remove wildcard in relayrecipients only if no wildcard emailaddr exists

This commit is contained in:
Peter Hormanns 2017-11-09 12:56:18 +01:00
parent a9f0fb6985
commit f4139407a8

View File

@ -135,14 +135,19 @@ public class DomainProcessorFactory implements EntityProcessorFactory {
new ShellProcessor("postmap -r -i /etc/postfix-mailin/relaydomains || true", new ShellProcessor("postmap -r -i /etc/postfix-mailin/relaydomains || true",
dom.getName() + " anything\n" + dom.getName() + " anything\n" +
"." + dom.getName() + " anything\n")); "." + dom.getName() + " anything\n"));
final Query query = em.createQuery("SELECT d FROM Domains d WHERE d.domainoptions.name = :option AND d.name = :domname"); final Query domainBackupMXQuery = em.createQuery("SELECT d FROM Domains d WHERE d.domainoptions.name = :option AND d.name = :domname");
query.setParameter("domname", dom.getName()); domainBackupMXQuery.setParameter("domname", dom.getName());
query.setParameter("option", "backupmxforexternalmx"); domainBackupMXQuery.setParameter("option", "backupmxforexternalmx");
if (query.getResultList().isEmpty()) { if (domainBackupMXQuery.getResultList().isEmpty()) {
cp.appendProcessor( final Query wildcardAddressQuery = em.createQuery("SELECT addr FROM EMailAddresses addr "
new ShellProcessor("postmap -d - /etc/postfix-mailin/relayrecipients || true", + "WHERE addr.localpart = '' AND addr.domain.name = :domname AND (addr.subdomain IS NULL OR addr.subdomain = '')");
"@" + dom.getName() + "\n") wildcardAddressQuery.setParameter("domname", dom.getName());
); if (wildcardAddressQuery.getResultList().isEmpty()) {
cp.appendProcessor(
new ShellProcessor("postmap -d - /etc/postfix-mailin/relayrecipients || true",
"@" + dom.getName() + "\n")
);
}
cp.appendProcessor( cp.appendProcessor(
new ShellProcessor("postmap -r -i /etc/postfix-mailin/transport || true", new ShellProcessor("postmap -r -i /etc/postfix-mailin/transport || true",
dom.getName() + " smtp:" + inetAddr + ":225\n" + dom.getName() + " smtp:" + inetAddr + ":225\n" +