When attemping to use a sub-domain email address for a new account, it won't pass the syntax test. We know that its really the base - but I'm sure a lot of end uers don't know.

newaccount@research.drupal.org - this type of address will fail, though it is actually legal

CommentFileSizeAuthor
#3 valid_email.patch1.31 KBkilles@www.drop.org

Comments

CdnStrangequark’s picture

Title: sub-domain email addresses won't pass New Account test » other valid emails fail too

Not just sub-domain emails. If you have an email address of the form: "first.last@somewhere.com" it will also fail even though this is perfectly valid.

CdnStrangequark’s picture

Assigned: Unassigned » CdnStrangequark

After attempting to enter more emails on one of my new sites, I also discovered that the validation fails in yet more perfectly valid cases. For example: "myemail@somewhere.xx" where xx is the country domain code. (like .ca, or .us). Not all country codes are accepted.

Here is a replacement I made for the code in common.inc: valid_email_address($mail) that works just great:

$user = "[-a-z0-9!#$%&'*+/=?^_`{|}~]";
$domain = "([a-z]([-a-z0-9]*[a-z0-9]+)?)";
$regex = "^$user+(\.$user+)*@($domain{1,63}\.)+$domain{2,63}$";

//Return a 1 or 0 to mimic results of preg_match
if (eregi($regex, $mail)) {
  return 1;
} else {
  return 0;
}

The only thing this doesn't do is allow for "user@localhost" but does anyone really do that anyway? The code could be modified to do it through an alternate check on $domain though.

PS: I left this post's status as active and unassigned cause I'm kinda new here and don't know the process for submitting patches and bug fixes. Hope someone can put this code in the core though cause I'm sure we're not the only ones who have run into the problem.

killes@www.drop.org’s picture

StatusFileSize
new1.31 KB

Our intrepid Debian developer has cooked up a patch. It is based on RFC 2822 but it needs testing.

Cvbge’s picture

Please add a button 'I know my email is good, accept it!' that would be displayed when email is found invalid.

dries’s picture

Using Drupal HEAD, the following code returns 3 x TRUE:

print valid_email_address("first.last@somewhere.com");
print valid_email_address("first.last@sub.somewhere.com");
print valid_email_address("first.last@sub.sub.somewhere.com");

Looking at the code, valid_email_address() in HEAD is no different from the one in DRUPAL-4-6.

1.190        (dries    13-Apr-03): function valid_email_address($mail) {
1.185        (dries    28-Mar-03):   $user = '[a-zA-Z0-9_\-\.\+\^!#\$%&*+\/\=\?\`\|\{\}~\']+';
1.350        (dries    24-May-04):   $domain = '(?:(?:[a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]*[a-zA-Z0-9])\.?)+';
1.185        (dries    28-Mar-03):   $ipv4 = '[0-9]{1,3}(\.[0-9]{1,3}){3}';
1.185        (dries    28-Mar-03):   $ipv6 = '[0-9a-fA-F]{1,4}(\:[0-9a-fA-F]{1,4}){7}';
1.185        (dries    28-Mar-03): 
1.278        (dries    13-Dec-03):   return preg_match("/^$user@($domain|(\[($ipv4|$ipv6)\]))$/", $mail);
1.231        (dries    16-Jul-03): }

In short: I can't reproduce this problem.

dries’s picture

Status: Needs review » Closed (fixed)