From f30279e631a06fcb94d6b30098fd42d0c0a492c3 Mon Sep 17 00:00:00 2001 From: Matthew Weier O'Phinney Date: Wed, 6 Jun 2018 11:43:03 -0500 Subject: [PATCH] Allow comma or semicolon separation in a list This patch adds a new class, `AddressListParser`, with a single static method `parse()`. It loops through each character of the value to identify non-escaped, non-quoted delimiters, allowing either `,` or `;` to be used. `AbstractAddressList::fromString()` now uses the above method instead of `str_getcsv()` to extract the list of addresses. The patch also updates the test provided in #147 to test for the existence of all addresses in the test string. --- src/Header/AbstractAddressList.php | 2 +- src/Header/AddressListParser.php | 86 ++++++++++++++++++++++++++++++ test/AddressListTest.php | 3 ++ 3 files changed, 90 insertions(+), 1 deletion(-) create mode 100644 src/Header/AddressListParser.php diff --git a/src/Header/AbstractAddressList.php b/src/Header/AbstractAddressList.php index 0954b6e4..1ac31595 100644 --- a/src/Header/AbstractAddressList.php +++ b/src/Header/AbstractAddressList.php @@ -50,7 +50,7 @@ public static function fromString($headerLine) // split value on "," $fieldValue = str_replace(Headers::FOLDING, ' ', $fieldValue); $fieldValue = preg_replace('/[^:]+:([^;]*);/', '$1,', $fieldValue); - $values = str_getcsv($fieldValue, ','); + $values = AddressListParser::parse($fieldValue); $wasEncoded = false; array_walk( diff --git a/src/Header/AddressListParser.php b/src/Header/AddressListParser.php new file mode 100644 index 00000000..3d20d1cf --- /dev/null +++ b/src/Header/AddressListParser.php @@ -0,0 +1,86 @@ +getAddressList(); $this->assertEquals('Some User', $addressList->get('some.user@example.com')->getName()); + $this->assertTrue($addressList->has('uzer2.surname@example.org')); + $this->assertTrue($addressList->has('asda.fasd@example.net')); + $this->assertTrue($addressList->has('root@example.org')); } }