diff --git a/src/Header/Consumer/AddressGroupConsumerService.php b/src/Header/Consumer/AddressGroupConsumerService.php index 3e119f52..e613ff42 100644 --- a/src/Header/Consumer/AddressGroupConsumerService.php +++ b/src/Header/Consumer/AddressGroupConsumerService.php @@ -8,6 +8,7 @@ namespace ZBateson\MailMimeParser\Header\Consumer; use Psr\Log\LoggerInterface; +use Iterator; use ZBateson\MailMimeParser\Header\Part\AddressGroupPart; use ZBateson\MailMimeParser\Header\Part\HeaderPartFactory; @@ -72,6 +73,22 @@ protected function isStartToken(string $token) : bool return ($token === ':'); } + /** + * Overridden to always call processParts even for an empty set of + * addresses, since a group could be empty. + * + * @param Iterator $tokens + * @return IHeaderPart[] + */ + protected function parseTokensIntoParts(Iterator $tokens) : array + { + $ret = parent::parseTokensIntoParts($tokens); + if ($ret === []) { + return $this->processParts([]); + } + return $ret; + } + /** * Performs post-processing on parsed parts. * diff --git a/tests/MailMimeParser/Header/AddressHeaderTest.php b/tests/MailMimeParser/Header/AddressHeaderTest.php index 33117258..c284e383 100644 --- a/tests/MailMimeParser/Header/AddressHeaderTest.php +++ b/tests/MailMimeParser/Header/AddressHeaderTest.php @@ -230,4 +230,18 @@ public function testGetGroups() : void $this->assertSame($parts[0], $groups[0]); $this->assertSame($parts[1], $groups[1]); } + + public function testEmptyAddressGroup() : void + { + $header = $this->newAddressHeader( + 'Cc', + 'House Stark:;' + ); + $parts = $header->getParts(); + $this->assertCount(1, $parts); + + $starks = $parts[0]; + $this->assertEquals('House Stark', $starks->getName()); + $this->assertCount(0, $starks->getAddresses()); + } }