From 3c81f485df567f5aea363d4c84f333ace9faa808 Mon Sep 17 00:00:00 2001 From: Julien BERNARD Date: Fri, 19 Nov 2021 13:19:50 -0500 Subject: [PATCH] Fix #2563: Provide the right flags to IDN methods for email addresses conversion --- src/PHPMailer.php | 6 +++++- test/PHPMailer/PunyencodeAddressTest.php | 5 +++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/PHPMailer.php b/src/PHPMailer.php index dda4452a..e68585cc 100644 --- a/src/PHPMailer.php +++ b/src/PHPMailer.php @@ -1451,7 +1451,11 @@ class PHPMailer $errorcode = 0; if (defined('INTL_IDNA_VARIANT_UTS46')) { //Use the current punycode standard (appeared in PHP 7.2) - $punycode = idn_to_ascii($domain, $errorcode, \INTL_IDNA_VARIANT_UTS46); + $punycode = idn_to_ascii( + $domain, + \IDNA_DEFAULT | \IDNA_USE_STD3_RULES | \IDNA_CHECK_BIDI | \IDNA_CHECK_CONTEXTJ | \IDNA_NONTRANSITIONAL_TO_ASCII, + \INTL_IDNA_VARIANT_UTS46 + ); } elseif (defined('INTL_IDNA_VARIANT_2003')) { //Fall back to this old, deprecated/removed encoding $punycode = idn_to_ascii($domain, $errorcode, \INTL_IDNA_VARIANT_2003); diff --git a/test/PHPMailer/PunyencodeAddressTest.php b/test/PHPMailer/PunyencodeAddressTest.php index 3d38d757..a5fa6e3f 100644 --- a/test/PHPMailer/PunyencodeAddressTest.php +++ b/test/PHPMailer/PunyencodeAddressTest.php @@ -72,6 +72,11 @@ final class PunyencodeAddressTest extends TestCase 'charset' => PHPMailer::CHARSET_UTF8, 'expected' => 'françois@xn--franois-xxa.ch', ], + 'IDN conversion flags' => [ + 'input' => 'test@fußball.test', + 'charset' => PHPMailer::CHARSET_UTF8, + 'expected' => 'test@xn--fuball-cta.test', + ], ]; }