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

Fix and test ">" being part of email "comment". fixes #127 #143

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -14,10 +14,13 @@

/**
* @group Zend_Mail
* @covers Zend\Mail\AddressList<extended>
* @covers \Zend\Mail\AddressList<extended>
*/
class AddressListTest extends \PHPUnit_Framework_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 @@ -14,7 +14,7 @@

/**
* @group Zend_Mail
* @covers Zend\Mail\Headers<extended>
* @covers \Zend\Mail\Headers<extended>
*/
class HeadersTest extends \PHPUnit_Framework_TestCase
{
Expand Down Expand Up @@ -479,4 +479,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);
}
}