From f4139407a840d3b128bcd22b1840f3ba75abf8b2 Mon Sep 17 00:00:00 2001 From: Peter Hormanns Date: Thu, 9 Nov 2017 12:56:18 +0100 Subject: [PATCH] remove wildcard in relayrecipients only if no wildcard emailaddr exists --- .../mods/dom/DomainProcessorFactory.java | 21 ++++++++++++------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/hsarback/src/de/hsadmin/mods/dom/DomainProcessorFactory.java b/hsarback/src/de/hsadmin/mods/dom/DomainProcessorFactory.java index 5e11cbf..529fade 100644 --- a/hsarback/src/de/hsadmin/mods/dom/DomainProcessorFactory.java +++ b/hsarback/src/de/hsadmin/mods/dom/DomainProcessorFactory.java @@ -135,14 +135,19 @@ public class DomainProcessorFactory implements EntityProcessorFactory { new ShellProcessor("postmap -r -i /etc/postfix-mailin/relaydomains || true", 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"); - query.setParameter("domname", dom.getName()); - query.setParameter("option", "backupmxforexternalmx"); - if (query.getResultList().isEmpty()) { - cp.appendProcessor( - new ShellProcessor("postmap -d - /etc/postfix-mailin/relayrecipients || true", - "@" + dom.getName() + "\n") - ); + final Query domainBackupMXQuery = em.createQuery("SELECT d FROM Domains d WHERE d.domainoptions.name = :option AND d.name = :domname"); + domainBackupMXQuery.setParameter("domname", dom.getName()); + domainBackupMXQuery.setParameter("option", "backupmxforexternalmx"); + if (domainBackupMXQuery.getResultList().isEmpty()) { + final Query wildcardAddressQuery = em.createQuery("SELECT addr FROM EMailAddresses addr " + + "WHERE addr.localpart = '' AND addr.domain.name = :domname AND (addr.subdomain IS NULL OR addr.subdomain = '')"); + 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( new ShellProcessor("postmap -r -i /etc/postfix-mailin/transport || true", dom.getName() + " smtp:" + inetAddr + ":225\n" +