From 226351407f312b23b6b54636b2afb0d1f8e805be Mon Sep 17 00:00:00 2001 From: Judah MW Date: Thu, 16 Jun 2022 11:42:59 +0200 Subject: [PATCH 1/2] functions: Added support for leading dots to _idn_encode_decode() Amavisd supports wildcards by performing decreasingly specific SQL lookups: 9 - lookup for user+foo@sub.example.com 8 - lookup for user@sub.example.com 7 - lookup for user+foo 6 - lookup for user 5 - lookup for @sub.example.com 3 - lookup for @.sub.example.com 2 - lookup for @.example.com 1 - lookup for @.com 0 - lookup for @. (catchall) (https://www.ijs.si/software/amavisd/README.lookups.txt) However idn_to_* returns an empty string if the domain has a leading dot which means lookups 0-3 cannot be used. This is fixed by removing the leading dot before encoding or decoding and adding it back just before returning the domain. --- interface/lib/classes/functions.inc.php | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/interface/lib/classes/functions.inc.php b/interface/lib/classes/functions.inc.php index 1b39668674..c38c8e22d6 100644 --- a/interface/lib/classes/functions.inc.php +++ b/interface/lib/classes/functions.inc.php @@ -334,6 +334,14 @@ class functions { $domain = substr($domain, strrpos($domain, '@') + 1); } + // idn_to_* chokes on leading dots, but we need them for amavis, so remove it for later + if(strpos($domain, '.') == 0) { + $leading_dot = true; + $domain = substr($domain, 1); + } else { + $leading_dot = false; + } + if($encode == true) { if(function_exists('idn_to_ascii')) { if(defined('IDNA_NONTRANSITIONAL_TO_ASCII') && defined('INTL_IDNA_VARIANT_UTS46') && constant('IDNA_NONTRANSITIONAL_TO_ASCII')) { @@ -378,6 +386,10 @@ class functions { } } + if($leading_dot == true) { + $domain = '.' . $domain; + } + if($user_part !== false) return $user_part . '@' . $domain; else return $domain; } -- GitLab From 6b17bf5fd645bd26914683279c76b5659fb86fe3 Mon Sep 17 00:00:00 2001 From: Marius Burkard Date: Wed, 17 Aug 2022 14:11:28 +0000 Subject: [PATCH 2/2] Fix leading dot check @pixcept --- interface/lib/classes/functions.inc.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/interface/lib/classes/functions.inc.php b/interface/lib/classes/functions.inc.php index c38c8e22d6..629da2fb0e 100644 --- a/interface/lib/classes/functions.inc.php +++ b/interface/lib/classes/functions.inc.php @@ -335,7 +335,7 @@ class functions { } // idn_to_* chokes on leading dots, but we need them for amavis, so remove it for later - if(strpos($domain, '.') == 0) { + if(substr($domain, 0, 1) === '.') { $leading_dot = true; $domain = substr($domain, 1); } else { -- GitLab