Index: includes/common.inc =================================================================== RCS file: /cvs/drupal/drupal/includes/common.inc,v retrieving revision 1.686 diff -u -r1.686 common.inc --- includes/common.inc 14 Sep 2007 20:08:59 -0000 1.686 +++ includes/common.inc 16 Oct 2007 22:34:05 -0000 @@ -772,6 +772,8 @@ * Verify the syntax of the given e-mail address. * * Empty e-mail addresses are allowed. See RFC 2822 for details. + * This version is based on Cal Henderson's. + * See http://www.iamcal.com/publish/articles/php/parsing_email/ * * @param $mail * A string containing an e-mail address. @@ -779,12 +781,34 @@ * TRUE if the address is in a valid format. */ function valid_email_address($mail) { - $user = '[a-zA-Z0-9_\-\.\+\^!#\$%&*+\/\=\?\`\|\{\}~\']+'; - $domain = '(?:(?:[a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]*[a-zA-Z0-9])\.?)+'; - $ipv4 = '[0-9]{1,3}(\.[0-9]{1,3}){3}'; - $ipv6 = '[0-9a-fA-F]{1,4}(\:[0-9a-fA-F]{1,4}){7}'; - - return preg_match("/^$user@($domain|(\[($ipv4|$ipv6)\]))$/", $mail); + + // Get the strict variable + $strict = variable_get('valid_email_address_strict', FALSE); + + // Build our regex + $qtext = '[^\\x0d\\x22\\x5c\\x80-\\xff]'; + $dtext = '[^\\x0d\\x5b-\\x5d\\x80-\\xff]'; + $atom = '[^\\x00-\\x20\\x22\\x28\\x29\\x2c\\x2e\\x3a-\\x3c\\x3e\\x40\\x5b-\\x5d\\x7f-\\xff]+'; + $quoted_pair = '\\x5c[\\x00-\\x7f]'; + $domain_literal = "\\x5b($dtext|$quoted_pair)*\\x5d"; + $quoted_string = "\\x22($qtext|$quoted_pair)*\\x22"; + $domain_ref = $atom; + $sub_domain = "($domain_ref|$domain_literal)"; + $word = "($atom|$quoted_string)"; + $domain = "$sub_domain(\\x2e$sub_domain)*"; + $local_part = "$word(\\x2e$word)*"; + + // Validate in strict accordance with RFC 2822 + if ($strict) { + $strict_addr_spec = "$local_part\\x40$domain"; + return preg_match("!^$strict_addr_spec$!", $mail); + } + + // Validate so that we require a ".*" at the end of the email + else { + $rl_addr_spec = "($local_part\\x40(?:[-a-z0-9]+\.)+[a-z]{2,})"; + return preg_match("!^$rl_addr_spec$!", $mail); + } } /**