From e041689fa6ed5ec8f659092526c86bad13261128 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Tim=20D=C3=BCsterhus?= Date: Wed, 27 Apr 2022 15:08:19 +0200 Subject: [PATCH] Delegate to Mailbox::filterAddress() in UserUtil::isValidEmail() see 1723b426d25ecaad5034a6f74e3b29db25dc1b29 --- .../install/files/lib/util/UserUtil.class.php | 24 +++++++------------ 1 file changed, 9 insertions(+), 15 deletions(-) diff --git a/wcfsetup/install/files/lib/util/UserUtil.class.php b/wcfsetup/install/files/lib/util/UserUtil.class.php index a26d2ca9bc..74b6704743 100644 --- a/wcfsetup/install/files/lib/util/UserUtil.class.php +++ b/wcfsetup/install/files/lib/util/UserUtil.class.php @@ -2,6 +2,7 @@ namespace wcf\util; +use wcf\system\email\Mailbox; use wcf\system\WCF; /** @@ -62,30 +63,23 @@ final class UserUtil /** * Returns true if the given e-mail is a valid address. - * @see http://www.faqs.org/rfcs/rfc821.html * + * @see Mailbox::filterAddress() * @param string $email - * @return bool */ - public static function isValidEmail($email) + public static function isValidEmail($email): bool { if (\mb_strlen($email) > 191) { return false; } - // local-part - $c = '!#\$%&\'\*\+\-\/0-9=\?a-z\^_`\{\}\|~'; - $string = '[' . $c . ']*(?:\\\\[\x00-\x7F][' . $c . ']*)*'; - $localPart = $string . '(?:\.' . $string . ')*'; - - // domain - $name = '[a-z0-9](?:[a-z0-9-]*[a-z0-9])?'; - $domain = $name . '(?:\.' . $name . ')*\.[a-z]{2,}'; - - // mailbox - $mailbox = $localPart . '@' . $domain; + try { + Mailbox::filterAddress($email); - return \preg_match('/^' . $mailbox . '$/i', $email); + return true; + } catch (\DomainException $e) { + return false; + } } /** -- 2.20.1