| | |
| | | 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; |
| | |
| | | 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) { |
| | |
| | | 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(",")) { |
| | |
| | | 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; |
| | | } |
| | |
| | | } |
| | | |
| | | 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) { |
| | |
| | | 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(",")) { |
| | |
| | | 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; |
| | | } |