Manage Postfix relayrecipients on mailin servers.

This commit is contained in:
Michael Hierweck 2012-10-31 14:23:20 +01:00
parent 2803fcf81a
commit 46b6502c2f

View File

@ -23,12 +23,16 @@ 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();
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() ) );
if (emailAddressCount(em, email) < 2) { for (String queueName : config.getProperty("queues.mail").split(",")) {
WaitingTasksProcessor waitingTasksProcessor = new WaitingTasksProcessor(cp); waitingTasksProcessor.appendProcessor(queueName, new ShellProcessor( "postmap -r -i /etc/postfix-mailin/relayrecipients",
String domName = email.getDomain().getName(); email.getEMailAddress() + " anything" ), "Add to relayrecipients" );
Config config = Config.getInstance(); }
if (emailAddressCount(em, email) <= 1) {
String domName = email.getDomain().getName();
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");
} }
@ -49,14 +53,18 @@ public class EMailAddressProcessorFactory implements EntityProcessorFactory {
EMailAddress email = (EMailAddress) entity; EMailAddress email = (EMailAddress) entity;
cp.appendProcessor( cp.appendProcessor(
new ShellProcessor( "postmap -d '" + email.getEMailAddress() + "' /etc/postfix-mailin/virtual" ) ); new ShellProcessor( "postmap -d '" + email.getEMailAddress() + "' /etc/postfix-mailin/virtual" ) );
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" ), "Remove from relayrecipients" );
}
int emailAddressCount = emailAddressCount(em, email); int emailAddressCount = emailAddressCount(em, email);
if (emailAddressCount == 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(
new ShellProcessor( "postmap -d '" + fullDomain + "' /etc/postfix-mailin/virtual" ) ); new ShellProcessor( "postmap -d '" + fullDomain + "' /etc/postfix-mailin/virtual" ) );
WaitingTasksProcessor waitingTasksProcessor = new WaitingTasksProcessor(cp);
Config config = Config.getInstance();
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");
} }