From: Tim Düsterhus Date: Wed, 27 Apr 2022 12:56:56 +0000 (+0200) Subject: Revert "Unify the email validation of UserUtil::isValidEmail() and Mailbox::__constru... X-Git-Tag: 5.5.0_Alpha_5~15 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=1723b426d25ecaad5034a6f74e3b29db25dc1b29;p=GitHub%2FWoltLab%2FWCF.git Revert "Unify the email validation of UserUtil::isValidEmail() and Mailbox::__construct()" This change broke WCFSetup, because Mailboxes implicitly carry a language which is not readily available in WCFSetup. The validation of the email address should likely be moved into a dedicated method in Mailbox and then UserUtil::isValidEmail() deprecated. This reverts commit 395f9a6affffdd5381134d3f9d39b70de453b668. --- diff --git a/wcfsetup/install/files/lib/util/UserUtil.class.php b/wcfsetup/install/files/lib/util/UserUtil.class.php index e34edbd274..a26d2ca9bc 100644 --- a/wcfsetup/install/files/lib/util/UserUtil.class.php +++ b/wcfsetup/install/files/lib/util/UserUtil.class.php @@ -2,7 +2,6 @@ namespace wcf\util; -use wcf\system\email\Mailbox; use wcf\system\WCF; /** @@ -62,23 +61,31 @@ final class UserUtil } /** - * Returns whether the given email is accepted by the Mailbox class. + * Returns true if the given e-mail is a valid address. + * @see http://www.faqs.org/rfcs/rfc821.html * - * @see wcf\system\email\Mailbox::__construct() + * @param string $email + * @return bool */ - public static function isValidEmail(string $email): bool + public static function isValidEmail($email) { if (\mb_strlen($email) > 191) { return false; } - try { - new Mailbox($email); + // local-part + $c = '!#\$%&\'\*\+\-\/0-9=\?a-z\^_`\{\}\|~'; + $string = '[' . $c . ']*(?:\\\\[\x00-\x7F][' . $c . ']*)*'; + $localPart = $string . '(?:\.' . $string . ')*'; - return true; - } catch (\DomainException $e) { - return false; - } + // domain + $name = '[a-z0-9](?:[a-z0-9-]*[a-z0-9])?'; + $domain = $name . '(?:\.' . $name . ')*\.[a-z]{2,}'; + + // mailbox + $mailbox = $localPart . '@' . $domain; + + return \preg_match('/^' . $mailbox . '$/i', $email); } /**