Skip to content

Commit 0970332

Browse files
author
Till Brehm
committed
Merge branch '5814-postfix_recipient_delimiter' into 'develop'
Resolve "Postfix recipient_delimiter not working with catchall defined" Closes #5814 See merge request ispconfig/ispconfig3!1260
2 parents 9220c71 + 5dcb3af commit 0970332

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

install/lib/installer_base.lib.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -774,13 +774,28 @@ public function process_postfix_config($configfile) {
774774
chmod($config_dir.$configfile.'~',0600);
775775
}
776776

777+
exec('postconf -h recipient_delimiter 2>/dev/null', $out);
778+
if (strlen($out[0]) > 0) {
779+
// build string like: CONCAT(SUBSTRING_INDEX(SUBSTRING_INDEX('%u', '%%', 1), '+', 1), '@%d')
780+
$addr_cleanup = "'%u'";
781+
foreach (str_split($out[0]) as $delim) {
782+
$recipient_delimiter = $this->db->escape( str_replace('%', '%%', $delim) );
783+
$addr_cleanup = "SUBSTRING_INDEX(${addr_cleanup}, '${recipient_delimiter}', 1)";
784+
}
785+
$no_addr_extension = "CONCAT(${addr_cleanup}, '@%d')";
786+
} else {
787+
$no_addr_extension = "''";
788+
}
789+
unset($out);
790+
777791
//* Replace variables in config file template
778792
$content = rfsel($conf['ispconfig_install_dir'].'/server/conf-custom/install/'.$configfile.'.master', 'tpl/'.$configfile.'.master');
779793
$content = str_replace('{mysql_server_ispconfig_user}', $conf['mysql']['ispconfig_user'], $content);
780794
$content = str_replace('{mysql_server_ispconfig_password}', $conf['mysql']['ispconfig_password'], $content);
781795
$content = str_replace('{mysql_server_database}', $conf['mysql']['database'], $content);
782796
$content = str_replace('{mysql_server_ip}', $conf['mysql']['ip'], $content);
783797
$content = str_replace('{server_id}', $conf['server_id'], $content);
798+
$content = str_replace('{address_without_extension}', $no_addr_extension, $content);
784799
wf($full_file_name, $content);
785800

786801
//* Changing mode and group of the new created config file

install/tpl/mysql-virtual_forwardings.cf.master

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ password = {mysql_server_ispconfig_password}
33
dbname = {mysql_server_database}
44
hosts = {mysql_server_ip}
55
query = SELECT s.destination AS target FROM mail_forwarding AS s
6-
WHERE s.source = '%s' AND s.type IN ('alias', 'forward') AND s.active = 'y' AND s.server_id = {server_id}
6+
WHERE (s.source = '%s' OR s.source = {address_without_extension}) AND s.type IN ('alias', 'forward') AND s.active = 'y' AND s.server_id = {server_id}
77
UNION
88
SELECT s.destination AS target FROM mail_forwarding AS s
99
WHERE s.source = '@%d' AND s.type = 'catchall' AND s.active = 'y' AND s.server_id = {server_id}
10-
AND NOT EXISTS (SELECT email FROM mail_user WHERE email = '%s' AND server_id = {server_id})
11-
AND NOT EXISTS (SELECT source FROM mail_forwarding WHERE source = '%s' AND active = 'y' AND server_id = {server_id})
10+
AND NOT EXISTS (SELECT email FROM mail_user WHERE (email = '%s' OR email = {address_without_extension}) AND server_id = {server_id})
11+
AND NOT EXISTS (SELECT source FROM mail_forwarding WHERE (source = '%s' OR source = {address_without_extension}) AND active = 'y' AND server_id = {server_id})

0 commit comments

Comments
 (0)