This was first reported on this issue:
http://drupal.org/node/209672

Quoting RFC2822 Internet message format:

Normally, a mailbox is comprised of two parts: (1) an optional display name that indicates the name of the recipient (which could be a person or a system) that could be displayed to the user of a mail application, and (2) an addr-spec address enclosed in angle brackets ("<" and ">"). There is also an alternate simple form of a mailbox where the addr-spec address appears alone, without the recipient's name or the angle brackets. The Internet addr-spec address is described in section 3.4.1.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

lilou’s picture

FileSize
1.13 KB

Reroll.

Anonymous’s picture

Status: Needs review » Needs work

The last submitted patch failed testing.

valthebald’s picture

Version: 7.x-dev » 8.x-dev
Status: Needs work » Active
Issue tags: +Needs backport to D7
FileSize
739 bytes
759 bytes

In 8.x-dev and 7.x-dev, valid_email_address() relies on filter_var() function with FILTER_VALIDATE_EMAIL parameter.
However, as of the latest stable PHP version, filter_var() does not conform to RFC 2822 (i.e. see PHP bugs (https://bugs.php.net/bug.php?id=43402, https://bugs.php.net/bug.php?id=54403)
I think that approach suggested by theborg is better than currently existing in core.

valthebald’s picture

Status: Active » Needs review

Rerolling the patch

valthebald’s picture

My bad, I thought that -d8.patch will be submitted for testing, resubmitting with correct name

Status: Needs review » Needs work

The last submitted patch, valid-email-address-rfc2822-214114.patch, failed testing.

valthebald’s picture

Status: Needs work » Needs review
FileSize
613 bytes

Combining 2 approaches: split $mail to (optional) name and address parts, then validate address part with filter_var()

thedavidmeister’s picture

Status: Needs review » Needs work

minor coding standards issue, need a space after (bool)

https://drupal.org/coding-standards

valthebald’s picture

Status: Needs work » Needs review
FileSize
624 bytes

Here we go

alansaviolobo’s picture

Issue summary: View changes
Status: Needs review » Needs work

tested this in codepad http://codepad.org/EQlk2KA4

The following code should have returned all true. doesnt seem to be the case

function valid_email_address($mail) {
  $name = '((?:"[^\"\f\n\r\t\v]+" <))?';
  $angle = '>?';
  $ret = preg_match("/^$name(.*?)$angle$/", $mail, $matches);
  if (!$ret) {
    return FALSE;
  }
  else {
    return (bool) filter_var($matches[2], FILTER_VALIDATE_EMAIL);
  }
}

echo "all values should be true";
var_dump(TRUE === valid_email_address('John Doe <johndoe@randommail.com>'));
var_dump(TRUE === valid_email_address('John Doe < johndoe@randommail.com >'));
var_dump(TRUE === valid_email_address('"John Doe" <johndoe@randommail.com>'));
var_dump(TRUE === valid_email_address('"John Doe" < johndoe@randommail.com >'));
all values should be true
Warning: preg_match(): Internal pcre_fullinfo() error -3 on line 6
bool(false)

Warning: preg_match(): Internal pcre_fullinfo() error -3 on line 6
bool(false)

Warning: preg_match(): Internal pcre_fullinfo() error -3 on line 6
bool(false)

Warning: preg_match(): Internal pcre_fullinfo() error -3 on line 6
bool(false)

Version: 8.0.x-dev » 8.1.x-dev

Drupal 8.0.6 was released on April 6 and is the final bugfix release for the Drupal 8.0.x series. Drupal 8.0.x will not receive any further development aside from security fixes. Drupal 8.1.0-rc1 is now available and sites should prepare to update to 8.1.0.

Bug reports should be targeted against the 8.1.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.1.x-dev » 8.2.x-dev

Drupal 8.1.9 was released on September 7 and is the final bugfix release for the Drupal 8.1.x series. Drupal 8.1.x will not receive any further development aside from security fixes. Drupal 8.2.0-rc1 is now available and sites should prepare to upgrade to 8.2.0.

Bug reports should be targeted against the 8.2.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.6 was released on February 1, 2017 and is the final full bugfix release for the Drupal 8.2.x series. Drupal 8.2.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.3.0 on April 5, 2017. (Drupal 8.3.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.3.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.6 was released on August 2, 2017 and is the final full bugfix release for the Drupal 8.3.x series. Drupal 8.3.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.4.0 on October 4, 2017. (Drupal 8.4.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.4.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.4 was released on January 3, 2018 and is the final full bugfix release for the Drupal 8.4.x series. Drupal 8.4.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.5.0 on March 7, 2018. (Drupal 8.5.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.5.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.6 was released on August 1, 2018 and is the final bugfix release for the Drupal 8.5.x series. Drupal 8.5.x will not receive any further development aside from security fixes. Sites should prepare to update to 8.6.0 on September 5, 2018. (Drupal 8.6.0-rc1 is available for testing.)

Bug reports should be targeted against the 8.6.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

andypost’s picture