This commit is contained in:
Michael Hierweck 2017-09-17 10:37:47 +02:00
parent 0cb44ebcc9
commit 5ce044e645

View File

@ -1,6 +1,8 @@
package de.hsadmin.mods.email;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.persistence.EntityManager;
import javax.persistence.Query;
@ -16,6 +18,7 @@ import de.hsadmin.core.util.Config;
public class EMailAddressProcessorFactory implements EntityProcessorFactory {
public <T extends AbstractEntity> Processor createCreateProcessor(EntityManager em, T entity) {
Logger logger = Logger.getLogger(EMailAddressProcessorFactory.class.getName());
CompoundProcessor cp = new CompoundProcessor();
EMailAddress email = (EMailAddress) entity;
if (emailAddressCount(em, email) > 0) {
@ -23,9 +26,11 @@ public class EMailAddressProcessorFactory implements EntityProcessorFactory {
cp.appendProcessor(new ShellProcessor("postmap -r -i /etc/postfix-mailin/virtual || true",
email.getFullDomain() + " -\n" +
"." + email.getFullDomain() + " -\n"));
logger.log(Level.INFO, "Queue: virtual => create domain record");
}
cp.appendProcessor(new ShellProcessor("postmap -r -i /etc/postfix-mailin/virtual || true",
email.getEMailAddress() + " " + email.getTarget() + "\n"));
logger.log(Level.INFO, "Queue: virtual => create email address record");
WaitingTasksProcessor waitingTasksProcessor = new WaitingTasksProcessor(cp);
Config config = Config.getInstance();
for (String queueName : config.getProperty("queues.mail").split(",")) {
@ -33,6 +38,7 @@ public class EMailAddressProcessorFactory implements EntityProcessorFactory {
new ShellProcessor("postmap -r -i /etc/postfix-mailin/relayrecipients || true",
email.getEMailAddress() + " anything\n"),
"Add to relayrecipients");
logger.log(Level.INFO, "Queue: relayrecipients => create email address record for " + queueName);
}
return waitingTasksProcessor;
}
@ -44,6 +50,7 @@ public class EMailAddressProcessorFactory implements EntityProcessorFactory {
}
public <T extends AbstractEntity> Processor createDeleteProcessor(EntityManager em, T entity) {
Logger logger = Logger.getLogger(EMailAddressProcessorFactory.class.getName());
CompoundProcessor cp = new CompoundProcessor();
EMailAddress email = (EMailAddress) entity;
if (emailAddressCount(em, email) == 0) {
@ -51,9 +58,11 @@ public class EMailAddressProcessorFactory implements EntityProcessorFactory {
cp.appendProcessor(new ShellProcessor("postmap -d - /etc/postfix-mailin/virtual || true",
email.getFullDomain() + "\n" +
"." + email.getFullDomain() + "\n"));
logger.log(Level.INFO, "Queue: virtual => remove domain record");
}
cp.appendProcessor(new ShellProcessor("postmap -d - /etc/postfix-mailin/virtual || true",
email.getEMailAddress() + "\n"));
logger.log(Level.INFO, "Queue: virtual => remove email address record");
Config config = Config.getInstance();
WaitingTasksProcessor waitingTasksProcessor = new WaitingTasksProcessor(cp);
for (String queueName : config.getProperty("queues.mail").split(",")) {
@ -61,6 +70,7 @@ public class EMailAddressProcessorFactory implements EntityProcessorFactory {
new ShellProcessor("postmap -d - /etc/postfix-mailin/relayrecipients || true",
email.getEMailAddress() + "\n"),
"Remove from relayrecipients");
logger.log(Level.INFO, "Queue: relayrecipients => remove email address record for " + queueName);
}
return waitingTasksProcessor;
}