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

Commit

Permalink
Handle groups in address lists
Browse files Browse the repository at this point in the history
  • Loading branch information
denis-sokolov committed Jun 11, 2015
1 parent 3d865e7 commit cdc9205
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/Header/AbstractAddressList.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,15 @@ public static function fromString($headerLine)
}
// split value on ","
$fieldValue = str_replace(Headers::FOLDING, ' ', $fieldValue);
$fieldValue = preg_replace('/[^:]+:([^;]*);/', '$1,', $fieldValue);
$values = str_getcsv($fieldValue, ',');
array_walk(
$values,
function (&$value) {
$value = trim($value);
}
);
$values = array_filter($values);

$addressList = $header->getAddressList();
foreach ($values as $address) {
Expand Down
21 changes: 21 additions & 0 deletions test/Header/AddressListHeaderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -169,4 +169,25 @@ public function testAllowsNoWhitespaceBetweenHeaderAndValue($headerLine, $class)
$address = $list->get('first@last.zend.com');
$this->assertEquals('Last, First', $address->getName());
}

/**
* @dataProvider getAddressListsWithGroup
*/
public function testAddressListWithGroup($input, $count, $sample)
{
$header = To::fromString($input);
$list = $header->getAddressList();
$this->assertEquals($count, count($list));
if ($count > 0) {
$this->assertTrue($list->has($sample));
}
}

public function getAddressListsWithGroup()
{
return [
['To: undisclosed-recipients:;', 0, null],
['To: friends: john@example.com; enemies: john@example.net, bart@example.net;', 3, 'john@example.net'],
];
}
}

0 comments on commit cdc9205

Please sign in to comment.