From 7b7b47657c9dbf1764980b207397715dee9192de Mon Sep 17 00:00:00 2001 From: Alexander Schlarb Date: Sun, 9 Dec 2018 20:30:43 +0000 Subject: [PATCH] Allow users to send emails from alias domains MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ### Problem Currently, if I have a domain `bla.com` that is an alias of `blub.com` and John has user account as `john@blub.com`, then will not be able to send e-mails as `john@bla.com` because the system will not recognize / communicate to Postfix that `john@bla.com` is the same as `john@blub.com` and hence Postfix will reject this attempt. ### Proposed Solution When calculating the allowed SASL usernames for an email address, also include aliases from aliased domains in the result of the query. (This will also work for the primary username, since that is added as “internal” alias to that table as well.) ### Caveats I only tested the proposed query with PostgreSQL. --- modoboa/admin/postfix_maps.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/modoboa/admin/postfix_maps.py b/modoboa/admin/postfix_maps.py index a1c58d410..328d734cd 100644 --- a/modoboa/admin/postfix_maps.py +++ b/modoboa/admin/postfix_maps.py @@ -118,8 +118,9 @@ class SenderLoginMap(object): "(SELECT concat(mb.address, '@', dom.name) FROM admin_mailbox mb " "INNER JOIN modoboa_admin_aliasrecipient alr ON alr.r_mailbox_id=mb.id" " INNER JOIN admin_domain dom ON dom.id=mb.domain_id" + " INNER JOIN admin_domainalias adom ON adom.target_id=dom.id" " INNER JOIN admin_alias al ON alr.alias_id=al.id " - "WHERE al.enabled=1 AND al.address='%s')" + "WHERE al.enabled=1 AND (al.address='%s' OR (adom.name='@d' AND al.address='%u'||'@'||dom.name)))" ) postgres = ( "(SELECT email FROM core_user WHERE email='%s' AND is_active) " @@ -132,8 +133,9 @@ class SenderLoginMap(object): "(SELECT mb.address || '@' || dom.name FROM admin_mailbox mb " "INNER JOIN modoboa_admin_aliasrecipient alr ON alr.r_mailbox_id=mb.id" " INNER JOIN admin_domain dom ON dom.id=mb.domain_id" + " INNER JOIN admin_domainalias adom ON adom.target_id=dom.id" " INNER JOIN admin_alias al ON alr.alias_id=al.id " - "WHERE al.enabled AND al.address='%s')" + "WHERE al.enabled AND (al.address='%s' OR (adom.name='@d' AND al.address='%u'||'@'||dom.name)))" ) sqlite = ( "SELECT email FROM core_user WHERE email='%s' AND is_active=1 " @@ -146,6 +148,7 @@ class SenderLoginMap(object): "SELECT mb.address || '@' || dom.name FROM admin_mailbox mb " "INNER JOIN modoboa_admin_aliasrecipient alr ON alr.r_mailbox_id=mb.id " "INNER JOIN admin_domain dom ON dom.id=mb.domain_id " + "INNER JOIN admin_domainalias adom ON adom.target_id=dom.id " "INNER JOIN admin_alias al ON alr.alias_id=al.id " - "WHERE al.enabled=1 AND al.address='%s'" + "WHERE al.enabled=1 AND (al.address='%s' OR (adom.name='@d' AND al.address='%u'||'@'||dom.name))" )