HSAdmin Backend Domains, E-Mail, Datenbanken
Michael Hierweck
2017-09-12 b29374939ce56e9ded77a450ba0de9630aa7d4ee
Cleanup.
2 files modified
53 ■■■■ changed files
hsarback/src/de/hsadmin/mods/dom/DomainProcessorFactory.java 31 ●●●● patch | view | raw | blame | history
hsarback/src/de/hsadmin/mods/email/EMailAddressProcessorFactory.java 22 ●●●● patch | view | raw | blame | history
hsarback/src/de/hsadmin/mods/dom/DomainProcessorFactory.java
@@ -4,6 +4,7 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import javax.persistence.EntityManager;
import javax.persistence.Query;
@@ -161,18 +162,18 @@
                            "." + dom.getName() + " smtp:" + inetAddr + ":225\n")
                    );
            cp.appendProcessor(
                    new ShellProcessor("postmap -r -i /etc/postfix-mailin/relayrecipients",
                            "@" + dom.getName() + " anything\n")
                    new ShellProcessor("postmap -d - /etc/postfix-mailin/relayrecipients",
                            "@" + dom.getName() + "\n")
                    );            
        } else {
            cp.appendProcessor(
                    new ShellProcessor(
                            "postmap -d '@" + dom.getName() + "' /etc/postfix-mailin/relayrecipients")
                    new ShellProcessor("postmap -d - /etc/postfix-mailin/transport",
                            dom.getName() + "\n" +
                            "." + dom.getName() + "\n")
                    );            
            cp.appendProcessor(
                    new ShellProcessor(
                            "postmap -d '" + dom.getName() + "' /etc/postfix-mailin/transport && " +
                            "postmap -d '." + dom.getName() + "' /etc/postfix-mailin/transport")
                    new ShellProcessor("postmap -r -i /etc/postfix-mailin/relayrecipients",
                            "@" + dom.getName() + " anything\n")
                    );
        }
        return cp;
@@ -202,14 +203,14 @@
    }
    private Processor createMailinUnsetupProcessor(EntityManager em, Domain dom) throws ProcessorException {
        Processor mailQueueProcessor = new CompoundProcessor(
                createPostgreyConfiguration(em),
                new ShellProcessor(
                        "postmap -d '@" + dom.getName() + "' /etc/postfix-mailin/relayrecpients && " +
                        "postmap -d '" + dom.getName() + "' /etc/postfix-mailin/relaydomains && " +
                        "postmap -d '" + dom.getName() + "' /etc/postfix-mailin/transport && " +
                        "postmap -d '." + dom.getName() + "' /etc/postfix-mailin/relaydomains && " +
                        "postmap -d '." + dom.getName() + "' /etc/postfix-mailin/transport"));
        final CompoundProcessor mailQueueProcessor = new CompoundProcessor(createPostgreyConfiguration(em));
        mailQueueProcessor.appendProcessor(new ShellProcessor("postmap -d - /etc/postfix-mailin/relayrecipients",
                                                    dom.getName() + "\n" +
                                                    "." + dom.getName() + "\n" +
                                                    "@" + dom.getName() + "\n"));
        mailQueueProcessor.appendProcessor(new ShellProcessor("postmap -d - /etc/postfix-mailin/transports",
                                                    dom.getName() + "\n" +
                                                    "." + dom.getName() + "\n"));
        return mailQueueProcessor;
    }
hsarback/src/de/hsadmin/mods/email/EMailAddressProcessorFactory.java
@@ -12,16 +12,18 @@
import de.hsadmin.core.qserv.ShellProcessor;
import de.hsadmin.core.qserv.WaitingTasksProcessor;
import de.hsadmin.core.util.Config;
import de.hsadmin.mods.pac.Pac;
public class EMailAddressProcessorFactory implements EntityProcessorFactory {
    public <T extends AbstractEntity> Processor createCreateProcessor(EntityManager em, T entity) {
        // TODO: combine both keys in a single call (optimization)
        EMailAddress email = (EMailAddress) entity;
        CompoundProcessor cp = new CompoundProcessor();
        cp.appendProcessor(
                new ShellProcessor("postmap -r -i /etc/postfix-mailin/virtual", email.getFullDomain() + " -"));
        EMailAddress email = (EMailAddress) entity;
        if (emailAddressCount(em, email) == 1) {
            // first email address added
            cp.appendProcessor(new ShellProcessor("postmap -r -i /etc/postfix-mailin/virtual",
                    email.getFullDomain() + " -"));
        }
        cp.appendProcessor(new ShellProcessor("postmap -r -i /etc/postfix-mailin/virtual",
                email.getEMailAddress() + " " + email.getTarget()));
        WaitingTasksProcessor waitingTasksProcessor = new WaitingTasksProcessor(cp);
@@ -46,17 +48,17 @@
        EMailAddress email = (EMailAddress) entity;
        if (emailAddressCount(em, email) == 0) {
            // last email address removed
            String fullDomain = email.getFullDomain();
            cp.appendProcessor(new ShellProcessor("postmap -d '" + fullDomain + "' /etc/postfix-mailin/virtual"));
            cp.appendProcessor(new ShellProcessor("postmap -d - /etc/postfix-mailin/virtual",
                    email.getFullDomain() + "\n"));
        }
        cp.appendProcessor(
                new ShellProcessor("postmap -d '" + email.getEMailAddress() + "' /etc/postfix-mailin/virtual"));
        cp.appendProcessor(new ShellProcessor("postmap -d - /etc/postfix-mailin/virtual",
                email.getEMailAddress() + "\n"));
        Config config = Config.getInstance();
        WaitingTasksProcessor waitingTasksProcessor = new WaitingTasksProcessor(cp);
        for (String queueName : config.getProperty("queues.mail").split(",")) {
            waitingTasksProcessor.appendProcessor(queueName,
                    new ShellProcessor(
                            "postmap -d '" + email.getEMailAddress() + "' /etc/postfix-mailin/relayrecipients"),
                    new ShellProcessor("postmap -d - /etc/postfix-mailin/relayrecipients",
                            email.getEMailAddress() + "\n"),
                    "Remove from relayrecipients");
        }
        return waitingTasksProcessor;