From 9ab1b1ef9768d5b32fa38b451f67dff530b72746 Mon Sep 17 00:00:00 2001 From: Jesse Norell Date: Fri, 9 Oct 2020 14:35:43 -0600 Subject: [PATCH 1/2] postfix: catchall addrs work with address extensions --- install/lib/installer_base.lib.php | 10 ++++++++++ install/tpl/mysql-virtual_forwardings.cf.master | 6 +++--- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/install/lib/installer_base.lib.php b/install/lib/installer_base.lib.php index c82fd16537..1d4a32d614 100644 --- a/install/lib/installer_base.lib.php +++ b/install/lib/installer_base.lib.php @@ -774,6 +774,15 @@ class installer_base { chmod($config_dir.$configfile.'~',0600); } + exec('postconf -h recipient_delimiter 2>/dev/null', $out); + if (strlen($out[0]) > 0) { + $recipient_delimiter = $this->db->escape( str_replace('%', '%%', $out[0]) ); + $addr_no_extension = "CONCAT(SUBSTRING_INDEX('%u', '${recipient_delimiter}', 1), '@%d')"; + } else { + $addr_no_extension = "'%s'"; + } + unset($out); + //* Replace variables in config file template $content = rfsel($conf['ispconfig_install_dir'].'/server/conf-custom/install/'.$configfile.'.master', 'tpl/'.$configfile.'.master'); $content = str_replace('{mysql_server_ispconfig_user}', $conf['mysql']['ispconfig_user'], $content); @@ -781,6 +790,7 @@ class installer_base { $content = str_replace('{mysql_server_database}', $conf['mysql']['database'], $content); $content = str_replace('{mysql_server_ip}', $conf['mysql']['ip'], $content); $content = str_replace('{server_id}', $conf['server_id'], $content); + $content = str_replace('{address_without_extension}', $addr_no_extension, $content); wf($full_file_name, $content); //* Changing mode and group of the new created config file diff --git a/install/tpl/mysql-virtual_forwardings.cf.master b/install/tpl/mysql-virtual_forwardings.cf.master index 9ab6f3e860..468691b16d 100644 --- a/install/tpl/mysql-virtual_forwardings.cf.master +++ b/install/tpl/mysql-virtual_forwardings.cf.master @@ -3,9 +3,9 @@ password = {mysql_server_ispconfig_password} dbname = {mysql_server_database} hosts = {mysql_server_ip} query = SELECT s.destination AS target FROM mail_forwarding AS s - WHERE s.source = '%s' AND s.type IN ('alias', 'forward') AND s.active = 'y' AND s.server_id = {server_id} + 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} UNION SELECT s.destination AS target FROM mail_forwarding AS s WHERE s.source = '@%d' AND s.type = 'catchall' AND s.active = 'y' AND s.server_id = {server_id} - AND NOT EXISTS (SELECT email FROM mail_user WHERE email = '%s' AND server_id = {server_id}) - AND NOT EXISTS (SELECT source FROM mail_forwarding WHERE source = '%s' AND active = 'y' AND server_id = {server_id}) + AND NOT EXISTS (SELECT email FROM mail_user WHERE (email = '%s' OR email = {address_without_extension}) AND server_id = {server_id}) + AND NOT EXISTS (SELECT source FROM mail_forwarding WHERE (source = '%s' OR source = {address_without_extension}) AND active = 'y' AND server_id = {server_id}) -- GitLab From 5dcb3afd23ea3aea1e66b5cd68d4c7c1b4ff6732 Mon Sep 17 00:00:00 2001 From: Jesse Norell Date: Fri, 9 Oct 2020 15:46:50 -0600 Subject: [PATCH 2/2] recipient_delimiter can be a list of characters --- install/lib/installer_base.lib.php | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/install/lib/installer_base.lib.php b/install/lib/installer_base.lib.php index 1d4a32d614..379bf5f749 100644 --- a/install/lib/installer_base.lib.php +++ b/install/lib/installer_base.lib.php @@ -776,10 +776,15 @@ class installer_base { exec('postconf -h recipient_delimiter 2>/dev/null', $out); if (strlen($out[0]) > 0) { - $recipient_delimiter = $this->db->escape( str_replace('%', '%%', $out[0]) ); - $addr_no_extension = "CONCAT(SUBSTRING_INDEX('%u', '${recipient_delimiter}', 1), '@%d')"; + // build string like: CONCAT(SUBSTRING_INDEX(SUBSTRING_INDEX('%u', '%%', 1), '+', 1), '@%d') + $addr_cleanup = "'%u'"; + foreach (str_split($out[0]) as $delim) { + $recipient_delimiter = $this->db->escape( str_replace('%', '%%', $delim) ); + $addr_cleanup = "SUBSTRING_INDEX(${addr_cleanup}, '${recipient_delimiter}', 1)"; + } + $no_addr_extension = "CONCAT(${addr_cleanup}, '@%d')"; } else { - $addr_no_extension = "'%s'"; + $no_addr_extension = "''"; } unset($out); @@ -790,7 +795,7 @@ class installer_base { $content = str_replace('{mysql_server_database}', $conf['mysql']['database'], $content); $content = str_replace('{mysql_server_ip}', $conf['mysql']['ip'], $content); $content = str_replace('{server_id}', $conf['server_id'], $content); - $content = str_replace('{address_without_extension}', $addr_no_extension, $content); + $content = str_replace('{address_without_extension}', $no_addr_extension, $content); wf($full_file_name, $content); //* Changing mode and group of the new created config file -- GitLab