diff --git a/install/lib/installer_base.lib.php b/install/lib/installer_base.lib.php index 004167022527de3c9f3a0ec91ff838f9e49fbba9..e6f290f9c5c7e5faf4cd9a7fec2d8578c3722380 100644 --- a/install/lib/installer_base.lib.php +++ b/install/lib/installer_base.lib.php @@ -883,8 +883,10 @@ class installer_base extends stdClass { $addr_cleanup = "SUBSTRING_INDEX({$addr_cleanup}, '{$recipient_delimiter}', 1)"; } $no_addr_extension = "CONCAT({$addr_cleanup}, '@%d')"; + $no_addr_extension_alt_domain = "CONCAT({$addr_cleanup}, 's2.destination')"; } else { $no_addr_extension = "''"; + $no_addr_extension_alt_domain = "''"; } unset($out); @@ -896,6 +898,7 @@ class installer_base extends stdClass { $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}', $no_addr_extension, $content); + $content = str_replace('{address_without_extension_alt_domain}', $no_addr_extension_alt_domain, $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 8607735c932b18f95a458ed3dcbd297d7120f8ea..d21721d1364ec0e0bab56878630ad7802b033a0f 100644 --- a/install/tpl/mysql-virtual_forwardings.cf.master +++ b/install/tpl/mysql-virtual_forwardings.cf.master @@ -2,10 +2,50 @@ user = {mysql_server_ispconfig_user} 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' OR s.source = {address_without_extension}) AND s.type IN ('alias', 'forward') AND s.active = 'y' AND s.server_id = {server_id} +query = /* The most basic forward */ + SELECT s.destination AS target FROM mail_forwarding AS s + 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 + /* Handle catchall */ 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' OR email = {address_without_extension}) AND EXISTS (SELECT domain_id FROM mail_domain WHERE domain = SUBSTRING_INDEX('%s', '@', -1) AND active = 'y' AND server_id = {server_id}) 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}) + AND NOT EXISTS ( + /* Exclude an address that exists as a mail_user */ + SELECT email FROM mail_user + WHERE (email = '%s' OR email = {address_without_extension}) + AND EXISTS ( + SELECT domain_id FROM mail_domain + WHERE domain = SUBSTRING_INDEX('%s', '@', -1) + AND active = 'y' AND server_id = {server_id} + ) + AND server_id = {server_id} + ) + AND NOT EXISTS ( + /* Exclude an address that has a specific forward */ + SELECT source FROM mail_forwarding + WHERE (source = '%s' OR source = {address_without_extension}) + AND active = 'y' AND server_id = {server_id} + ) + UNION + /* Get all forwards, lookup localpart on active alias domains on this server */ + SELECT s.destination AS target FROM mail_forwarding AS s + INNER JOIN mail_forwarding AS s2 + ON ( s2.source = '@%d' + AND s2.type = 'aliasdomain' + AND s2.active = 'y' + AND s2.server_id = {server_id}) + WHERE s.source = {address_without_extension_alt_domain} + AND s.type IN ('alias', 'forward') + AND s.active = 'y' + AND s.server_id = {server_id} + UNION + /* Get all users, lookup localpart on active alias domains on this server */ + SELECT u.email AS target FROM mail_user AS u + INNER JOIN mail_forwarding AS s2 + ON ( s2.source = '@%d' + AND s2.type = 'aliasdomain' + AND s2.active = 'y' + AND s2.server_id = {server_id}) + WHERE (u.email = {address_without_extension_alt_domain}) + AND u.server_id = 1