From 82f4f1fd156a42b89ef14461d18ea6c458520bfb Mon Sep 17 00:00:00 2001 From: andryyy Date: Tue, 17 Aug 2021 16:51:06 +0200 Subject: [PATCH] [Postfix] Lookup credentials for user-specific sender transports --- data/Dockerfiles/postfix/postfix.sh | 28 ++++++++++++++++++++++++---- docker-compose.yml | 2 +- 2 files changed, 25 insertions(+), 5 deletions(-) diff --git a/data/Dockerfiles/postfix/postfix.sh b/data/Dockerfiles/postfix/postfix.sh index 35cd79012..e734a9ab3 100755 --- a/data/Dockerfiles/postfix/postfix.sh +++ b/data/Dockerfiles/postfix/postfix.sh @@ -181,11 +181,31 @@ hosts = unix:/var/run/mysqld/mysqld.sock dbname = ${DBNAME} query = SELECT CONCAT_WS(':', username, password) AS auth_data FROM relayhosts WHERE id IN ( - SELECT relayhost FROM domain - WHERE CONCAT('@', domain) = '%s' - OR domain IN ( - SELECT target_domain FROM alias_domain WHERE CONCAT('@', alias_domain) = '%s' + SELECT COALESCE( + (SELECT id FROM relayhosts + LEFT OUTER JOIN domain ON domain.relayhost = relayhosts.id + WHERE relayhosts.active = '1' + AND (domain.domain = '%d' + OR domain.domain IN ( + SELECT target_domain FROM alias_domain + WHERE alias_domain = '%d' + ) + ) + ), + (SELECT id FROM relayhosts + LEFT OUTER JOIN mailbox ON JSON_UNQUOTE(JSON_VALUE(mailbox.attributes, '$.relayhost')) = relayhosts.id + WHERE relayhosts.active = '1' + AND ( + mailbox.username IN ( + SELECT alias.goto from alias + JOIN mailbox ON mailbox.username = alias.goto + WHERE alias.active = '1' + AND alias.address = '%s' + AND alias.address NOT LIKE '@%%' + ) + ) ) + ) ) AND active = '1' AND username != ''; diff --git a/docker-compose.yml b/docker-compose.yml index 60e8ce661..c0e7fecd3 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -290,7 +290,7 @@ services: - dovecot postfix-mailcow: - image: mailcow/postfix:1.65 + image: mailcow/postfix:1.66 depends_on: - mysql-mailcow volumes: