Skip to content

Commit b6209da

Browse files
fix
1 parent 64f2862 commit b6209da

File tree

4 files changed

+38
-4
lines changed

4 files changed

+38
-4
lines changed

Makefile

+3
Original file line numberDiff line numberDiff line change
@@ -101,5 +101,8 @@ test-polyfill:
101101
test-parse-headers:
102102
@docker-compose run --rm phpunit tests --filter PolyfillTest::testRfc822ParseHeaders
103103

104+
test-parse-adrlist:
105+
@docker-compose run --rm phpunit tests --filter PolyfillTest::testRfc822ParseAdrList
106+
104107
test-special:
105108
@docker-compose run --rm phpunit tests --filter HeaderInfoTest::testSanitizeAddress

src/Functions.php

+7-2
Original file line numberDiff line numberDiff line change
@@ -155,17 +155,22 @@ public static function isValidImap2Connection($imap)
155155
return Connection::isValid($imap);
156156
}
157157

158-
public static function getAddressObjectList($addressList)
158+
public static function getAddressObjectList($addressList, $defaultHostname = 'UNKNOWN')
159159
{
160160
$addressObjectList = [];
161161
foreach ($addressList as $toAddress) {
162162
$email = explode('@', $toAddress->getEmail());
163163

164164
$addressObject = (object) [
165165
'mailbox' => $email[0],
166-
'host' => $email[1],
166+
'host' => $email[1] ?? $defaultHostname,
167167
];
168168

169+
$personal = $toAddress->getName();
170+
if ($personal) {
171+
$addressObject->personal = $personal;
172+
}
173+
169174
$addressObjectList[] = $addressObject;
170175
}
171176

src/Polyfill.php

+7-2
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,14 @@ public static function qPrint($string)
3636
return $string;
3737
}
3838

39-
public static function rfc822ParseAdrList($string)
39+
public static function rfc822ParseAdrList($string, $defaultHostname)
4040
{
41-
return $string;
41+
$message = Message::from('To: '.$string, false);
42+
43+
return Functions::getAddressObjectList(
44+
$message->getHeader(HeaderConsts::TO)->getAddresses(),
45+
$defaultHostname
46+
);
4247
}
4348

4449
/**

tests/PolyfillTest.php

+21
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,25 @@ public function testRfc822ParseHeaders()
4242
$this->assertEquals($headers1, $headers2);
4343
}
4444
}
45+
46+
public function testRfc822ParseAdrList()
47+
{
48+
$fixtures = [
49+
50+
];
51+
52+
$defaultHostname = 'default.host';
53+
foreach ($fixtures as $addresses) {
54+
$addressObjectList1 = imap_rfc822_parse_adrlist($addresses, $defaultHostname);
55+
$addressObjectList2 = Polyfill::rfc822ParseAdrList($addresses, $defaultHostname);
56+
57+
#file_put_contents('a1.json', json_encode($addressObjectList1, JSON_PRETTY_PRINT));
58+
#file_put_contents('a2.json', json_encode($addressObjectList2, JSON_PRETTY_PRINT));
59+
60+
#var_dump($addressObjectList1);
61+
#var_dump($addressObjectList2);
62+
63+
$this->assertEquals($addressObjectList1, $addressObjectList2);
64+
}
65+
}
4566
}

0 commit comments

Comments
 (0)