Skip to content
This repository has been archived by the owner on Jan 30, 2020. It is now read-only.

Commit

Permalink
fix and test ">" being part of email "comment". #127
Browse files Browse the repository at this point in the history
Example Email-header:
  "Foo <bar" <foo.bar@test.com>

Description:
   The example email-header should be valid
   according to https://tools.ietf.org/html/rfc2822#section-3.4
   but the function AdressList.php/addFromString matches it incorrect.
   The result has the following form:
    "bar <foo.bar@test.com"
   This is clearly not a valid adress and therefore causes
   exceptions in the following code

#127
  • Loading branch information
glensc authored and Ocramius committed Mar 1, 2018
1 parent a6f72a1 commit 0888aee
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/AddressList.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public function addMany(array $addresses)
*/
public function addFromString($address)
{
if (! preg_match('/^((?P<name>.*?)<(?P<namedEmail>[^>]+)>|(?P<email>.+))$/', $address, $matches)) {
if (! preg_match('/^((?P<name>.*)<(?P<namedEmail>[^>]+)>|(?P<email>.+))$/', $address, $matches)) {
throw new Exception\InvalidArgumentException('Invalid address format');
}

Expand Down
5 changes: 4 additions & 1 deletion test/AddressListTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,13 @@

/**
* @group Zend_Mail
* @covers Zend\Mail\AddressList<extended>
* @covers \Zend\Mail\AddressList<extended>
*/
class AddressListTest extends TestCase
{
/** @var AddressList $list */
private $list;

public function setUp()
{
$this->list = new AddressList();
Expand Down
34 changes: 33 additions & 1 deletion test/HeadersTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

/**
* @group Zend_Mail
* @covers Zend\Mail\Headers<extended>
* @covers \Zend\Mail\Headers<extended>
*/
class HeadersTest extends TestCase
{
Expand Down Expand Up @@ -483,4 +483,36 @@ public function testAddressListGetEncodedFieldValueWithUtf8Domain()
$encodedValue = $to->getFieldValue(Header\HeaderInterface::FORMAT_ENCODED);
$this->assertEquals('local-part@xn---umlaut-4wa.de', $encodedValue);
}

/**
* Test ">" being part of email "comment".
*
* Example Email-header:
* "Foo <bar" foo.bar@test.com
*
* Description:
* The example email-header should be valid
* according to https://tools.ietf.org/html/rfc2822#section-3.4
* but the function AdressList.php/addFromString matches it incorrect.
* The result has the following form:
* "bar <foo.bar@test.com"
* This is clearly not a valid adress and therefore causes
* exceptions in the following code
*
* @see https://github.com/zendframework/zend-mail/issues/127
*/
public function testEmailNameParser() {
$to = Header\To::fromString('To: "=?UTF-8?Q?=C3=B5lu?= <bar" <foo.bar@test.com>');

$address = $to->getAddressList()->get('foo.bar@test.com');
$this->assertEquals('õlu <bar', $address->getName());
$this->assertEquals('foo.bar@test.com', $address->getEmail());

$encodedValue = $to->getFieldValue(Header\HeaderInterface::FORMAT_ENCODED);
$this->assertEquals('=?UTF-8?Q?=C3=B5lu=20<bar?= <foo.bar@test.com>', $encodedValue);

$encodedValue = $to->getFieldValue(Header\HeaderInterface::FORMAT_RAW);
// FIXME: shouldn't the "name" part be in quotes?
$this->assertEquals('õlu <bar <foo.bar@test.com>', $encodedValue);
}
}

0 comments on commit 0888aee

Please sign in to comment.