Maybe fixed: update relay_recipients when email address is created or deleted.

This commit is contained in:
Michael Hierweck 2017-09-08 12:43:24 +02:00
parent 7daa01ae23
commit c7fbfcc85c

View File

@ -23,10 +23,10 @@ public class EMailAddressProcessorFactory implements EntityProcessorFactory {
CompoundProcessor cp = new CompoundProcessor(); CompoundProcessor cp = new CompoundProcessor();
cp.appendProcessor(new ShellProcessor( "postmap -r -i /etc/postfix-mailin/virtual", cp.appendProcessor(new ShellProcessor( "postmap -r -i /etc/postfix-mailin/virtual",
email.getFullDomain() + " -" ) ); email.getFullDomain() + " -" ) );
WaitingTasksProcessor waitingTasksProcessor = new WaitingTasksProcessor(cp);
Config config = Config.getInstance(); Config config = Config.getInstance();
cp.appendProcessor(new ShellProcessor( "postmap -r -i /etc/postfix-mailin/virtual", cp.appendProcessor(new ShellProcessor( "postmap -r -i /etc/postfix-mailin/virtual",
email.getEMailAddress() + " " + email.getTarget() ) ); email.getEMailAddress() + " " + email.getTarget() ) );
WaitingTasksProcessor waitingTasksProcessor = new WaitingTasksProcessor(cp);
for (String queueName : config.getProperty("queues.mail").split(",")) { for (String queueName : config.getProperty("queues.mail").split(",")) {
waitingTasksProcessor.appendProcessor(queueName, new ShellProcessor( "postmap -r -i /etc/postfix-mailin/relayrecipients", waitingTasksProcessor.appendProcessor(queueName, new ShellProcessor( "postmap -r -i /etc/postfix-mailin/relayrecipients",
email.getEMailAddress() + " anything" ), "Add to relayrecipients" ); email.getEMailAddress() + " anything" ), "Add to relayrecipients" );
@ -36,10 +36,8 @@ public class EMailAddressProcessorFactory implements EntityProcessorFactory {
for (String queueName : config.getProperty("queues.mail").split(",")) { for (String queueName : config.getProperty("queues.mail").split(",")) {
waitingTasksProcessor.appendProcessor(queueName, createMailinSetupProcessor(domName, pac), queueName + ".hostsharing.net"); waitingTasksProcessor.appendProcessor(queueName, createMailinSetupProcessor(domName, pac), queueName + ".hostsharing.net");
} }
return waitingTasksProcessor;
} else {
return cp;
} }
return waitingTasksProcessor;
} }
public <T extends AbstractEntity> Processor createUpdateProcessor(EntityManager em, T entity) { public <T extends AbstractEntity> Processor createUpdateProcessor(EntityManager em, T entity) {
@ -60,8 +58,7 @@ public class EMailAddressProcessorFactory implements EntityProcessorFactory {
new ShellProcessor( "postmap -d '" + email.getEMailAddress() + "' /etc/postfix-mailin/relayrecipients" ), new ShellProcessor( "postmap -d '" + email.getEMailAddress() + "' /etc/postfix-mailin/relayrecipients" ),
"Remove from relayrecipients" ); "Remove from relayrecipients" );
} }
int emailAddressCount = emailAddressCount(em, email); if (emailAddressCount(em, email) == 0) {
if (emailAddressCount == 0) {
// remove the domain from virtual.db // remove the domain from virtual.db
String fullDomain = email.getFullDomain(); String fullDomain = email.getFullDomain();
cp.appendProcessor( cp.appendProcessor(
@ -69,10 +66,8 @@ public class EMailAddressProcessorFactory implements EntityProcessorFactory {
for (String queueName : config.getProperty("queues.mail").split(",")) { for (String queueName : config.getProperty("queues.mail").split(",")) {
waitingTasksProcessor.appendProcessor(queueName, createMailinDeleteProcessor(fullDomain), queueName + ".hostsharing.net"); waitingTasksProcessor.appendProcessor(queueName, createMailinDeleteProcessor(fullDomain), queueName + ".hostsharing.net");
} }
return waitingTasksProcessor;
} else {
return cp;
} }
return waitingTasksProcessor;
} }
private int emailAddressCount(EntityManager em, EMailAddress email) { private int emailAddressCount(EntityManager em, EMailAddress email) {