Replace true/punycode by `\idn_to_ascii()` in Mailbox
authorTim Düsterhus <duesterhus@woltlab.com>
Wed, 8 Jun 2022 14:21:41 +0000 (16:21 +0200)
committerTim Düsterhus <duesterhus@woltlab.com>
Wed, 8 Jun 2022 14:39:19 +0000 (16:39 +0200)
Flags taken from symfony/symfony's IdnAddressEncoder.

The `IDNA_NONTRANSITIONAL_TO_ASCII` is necessary to correctly encode the German
`ß` into the Punycode representation, instead of `ss`.

The other flags enable various recommended validations as described in
https://unicode.org/reports/tr46/.

see 73ce002da6f3dee4eda9cf418b58e5f614fdf79f

wcfsetup/install/files/lib/system/email/Mailbox.class.php

index d350a3f6807f592bf7cee0193fdcd3c142fb09c1..df37a0698d10b094b32b50eebd1e081ea8b3f283 100644 (file)
@@ -2,7 +2,8 @@
 
 namespace wcf\system\email;
 
-use TrueBV\Exception\OutOfBoundsException;
+use GuzzleHttp\Psr7\Uri;
+use GuzzleHttp\Utils;
 use TrueBV\Punycode;
 use wcf\data\language\Language;
 use wcf\system\language\LanguageFactory;
@@ -84,10 +85,14 @@ class Mailbox
             }
         }
 
+        // punycode the domain ...
         try {
-            // punycode the domain ...
-            $domain = @(new Punycode())->encode($domain);
-        } catch (OutOfBoundsException $e) {
+            $uri = (new Uri())->withHost($domain);
+            $domain = Utils::idnUriConvert(
+                $uri,
+                \IDNA_DEFAULT | \IDNA_USE_STD3_RULES | \IDNA_CHECK_BIDI | \IDNA_CHECK_CONTEXTJ | \IDNA_NONTRANSITIONAL_TO_ASCII
+            )->getHost();
+        } catch (\InvalidArgumentException $e) {
             throw new \DomainException($e->getMessage(), 0, $e);
         }