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",
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" +