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();
cp.appendProcessor(new ShellProcessor( "postmap -r -i /etc/postfix-mailin/virtual",
email.getFullDomain() + " -" ) );
WaitingTasksProcessor waitingTasksProcessor = new WaitingTasksProcessor(cp);
Config config = Config.getInstance();
cp.appendProcessor(new ShellProcessor( "postmap -r -i /etc/postfix-mailin/virtual",
email.getEMailAddress() + " " + email.getTarget() ) );
if (emailAddressCount(em, email) < 2) {
WaitingTasksProcessor waitingTasksProcessor = new WaitingTasksProcessor(cp);
for (String queueName : config.getProperty("queues.mail").split(",")) {
waitingTasksProcessor.appendProcessor(queueName, new ShellProcessor( "postmap -r -i /etc/postfix-mailin/relayrecipients",
email.getEMailAddress() + " anything" ), "Add to relayrecipients" );
}
if (emailAddressCount(em, email) <= 1) {
String domName = email.getDomain().getName();
Config config = Config.getInstance();
for (String queueName : config.getProperty("queues.mail").split(",")) {
waitingTasksProcessor.appendProcessor(queueName, createMailinSetupProcessor(domName, pac), queueName + ".hostsharing.net");
}
@ -49,14 +53,18 @@ public class EMailAddressProcessorFactory implements EntityProcessorFactory {
EMailAddress email = (EMailAddress) entity;
cp.appendProcessor(
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);
if (emailAddressCount == 0) {
// remove the domain from virtual.db
String fullDomain = email.getFullDomain();
cp.appendProcessor(
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(",")) {
waitingTasksProcessor.appendProcessor(queueName, createMailinDeleteProcessor(fullDomain), queueName + ".hostsharing.net");
}