namespace wcf\util;
+use wcf\system\email\Mailbox;
use wcf\system\WCF;
/**
/**
* 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;
+ }
}
/**