Skip to content

Commit e0d4423

Browse files
committed
Fix to allow empty address groups #241
1 parent 48cf726 commit e0d4423

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

src/Header/Consumer/AddressGroupConsumerService.php

+17
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
namespace ZBateson\MailMimeParser\Header\Consumer;
99

1010
use Psr\Log\LoggerInterface;
11+
use Iterator;
1112
use ZBateson\MailMimeParser\Header\Part\AddressGroupPart;
1213
use ZBateson\MailMimeParser\Header\Part\HeaderPartFactory;
1314

@@ -72,6 +73,22 @@ protected function isStartToken(string $token) : bool
7273
return ($token === ':');
7374
}
7475

76+
/**
77+
* Overridden to always call processParts even for an empty set of
78+
* addresses, since a group could be empty.
79+
*
80+
* @param Iterator $tokens
81+
* @return IHeaderPart[]
82+
*/
83+
protected function parseTokensIntoParts(Iterator $tokens) : array
84+
{
85+
$ret = parent::parseTokensIntoParts($tokens);
86+
if ($ret === []) {
87+
return $this->processParts([]);
88+
}
89+
return $ret;
90+
}
91+
7592
/**
7693
* Performs post-processing on parsed parts.
7794
*

tests/MailMimeParser/Header/AddressHeaderTest.php

+14
Original file line numberDiff line numberDiff line change
@@ -230,4 +230,18 @@ public function testGetGroups() : void
230230
$this->assertSame($parts[0], $groups[0]);
231231
$this->assertSame($parts[1], $groups[1]);
232232
}
233+
234+
public function testEmptyAddressGroup() : void
235+
{
236+
$header = $this->newAddressHeader(
237+
'Cc',
238+
'House Stark:;'
239+
);
240+
$parts = $header->getParts();
241+
$this->assertCount(1, $parts);
242+
243+
$starks = $parts[0];
244+
$this->assertEquals('House Stark', $starks->getName());
245+
$this->assertCount(0, $starks->getAddresses());
246+
}
233247
}

0 commit comments

Comments
 (0)