diff --git a/src/Header/AbstractAddressList.php b/src/Header/AbstractAddressList.php index 1537f7d1..b9ba3e89 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, @@ -65,6 +66,7 @@ function (&$value) { $value = trim($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 b95dadc9..ed0a026a 100644 --- a/test/Header/AddressListHeaderTest.php +++ b/test/Header/AddressListHeaderTest.php @@ -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'], + ]; + } }