From 5064f95148c1d996b5b25bc556830da9a8458e6a Mon Sep 17 00:00:00 2001 From: Denis Sokolov Date: Thu, 11 Jun 2015 13:27:04 +0300 Subject: [PATCH] Handle groups in address lists --- src/Header/AbstractAddressList.php | 2 ++ test/Header/AddressListHeaderTest.php | 21 +++++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/src/Header/AbstractAddressList.php b/src/Header/AbstractAddressList.php index b13f9ebd..e0b4e78c 100644 --- a/src/Header/AbstractAddressList.php +++ b/src/Header/AbstractAddressList.php @@ -58,6 +58,7 @@ 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, @@ -66,6 +67,7 @@ function (&$value) { $value = self::stripComments($value); } ); + $values = array_filter($values); $addressList = $header->getAddressList(); foreach ($values as $address) { diff --git a/test/Header/AddressListHeaderTest.php b/test/Header/AddressListHeaderTest.php index 223a135b..df2c6457 100644 --- a/test/Header/AddressListHeaderTest.php +++ b/test/Header/AddressListHeaderTest.php @@ -189,4 +189,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'], + ]; + } }