Skip to content

Commit 2263514

Browse files
author
Judah MW
committed
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.
1 parent 5bbec2b commit 2263514

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

interface/lib/classes/functions.inc.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,14 @@ private function _idn_encode_decode($domain, $encode = true) {
334334
$domain = substr($domain, strrpos($domain, '@') + 1);
335335
}
336336

337+
// idn_to_* chokes on leading dots, but we need them for amavis, so remove it for later
338+
if(strpos($domain, '.') == 0) {
339+
$leading_dot = true;
340+
$domain = substr($domain, 1);
341+
} else {
342+
$leading_dot = false;
343+
}
344+
337345
if($encode == true) {
338346
if(function_exists('idn_to_ascii')) {
339347
if(defined('IDNA_NONTRANSITIONAL_TO_ASCII') && defined('INTL_IDNA_VARIANT_UTS46') && constant('IDNA_NONTRANSITIONAL_TO_ASCII')) {
@@ -378,6 +386,10 @@ private function _idn_encode_decode($domain, $encode = true) {
378386
}
379387
}
380388

389+
if($leading_dot == true) {
390+
$domain = '.' . $domain;
391+
}
392+
381393
if($user_part !== false) return $user_part . '@' . $domain;
382394
else return $domain;
383395
}

0 commit comments

Comments
 (0)