Skip to content

Commit 69c1bdb

Browse files
everyxfabpot
authored andcommitted
fix: stringify from address for ses+api transport
close: symfony#45660
1 parent d63e0fe commit 69c1bdb

File tree

2 files changed

+17
-12
lines changed

2 files changed

+17
-12
lines changed

src/Symfony/Component/Mailer/Bridge/Amazon/Tests/Transport/SesApiAsyncAwsTransportTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ public function testSend()
8282
$this->assertSame('Hello!', $content['Content']['Simple']['Subject']['Data']);
8383
$this->assertSame('"Saif Eddin" <[email protected]>', $content['Destination']['ToAddresses'][0]);
8484
$this->assertSame('=?UTF-8?B?SsOpcsOpbXk=?= <[email protected]>', $content['Destination']['CcAddresses'][0]);
85-
$this->assertSame('"Fabien" <[email protected]>', $content['FromEmailAddress']);
85+
$this->assertSame('=?UTF-8?B?RmFiacOpbg==?= <[email protected]>', $content['FromEmailAddress']);
8686
$this->assertSame('Hello There!', $content['Content']['Simple']['Body']['Text']['Data']);
8787
$this->assertSame('<b>Hello There!</b>', $content['Content']['Simple']['Body']['Html']['Data']);
8888
$this->assertSame(['[email protected]', '[email protected]'], $content['ReplyToAddresses']);
@@ -103,7 +103,7 @@ public function testSend()
103103
$mail->subject('Hello!')
104104
->to(new Address('[email protected]', 'Saif Eddin'))
105105
->cc(new Address('[email protected]', 'Jérémy'))
106-
->from(new Address('[email protected]', 'Fabien'))
106+
->from(new Address('[email protected]', 'Fabién'))
107107
->text('Hello There!')
108108
->html('<b>Hello There!</b>')
109109
->replyTo(new Address('[email protected]'), new Address('[email protected]'))

src/Symfony/Component/Mailer/Bridge/Amazon/Transport/SesApiAsyncAwsTransport.php

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ protected function getRequest(SentMessage $message): SendEmailRequest
5353
$envelope = $message->getEnvelope();
5454

5555
$request = [
56-
'FromEmailAddress' => $envelope->getSender()->toString(),
56+
'FromEmailAddress' => $this->stringifyAddress($envelope->getSender()),
5757
'Destination' => [
5858
'ToAddresses' => $this->stringifyAddresses($this->getRecipients($email, $envelope)),
5959
],
@@ -114,15 +114,20 @@ private function getRecipients(Email $email, Envelope $envelope): array
114114
protected function stringifyAddresses(array $addresses): array
115115
{
116116
return array_map(function (Address $a) {
117-
// AWS does not support UTF-8 address
118-
if (preg_match('~[\x00-\x08\x10-\x19\x7F-\xFF\r\n]~', $name = $a->getName())) {
119-
return sprintf('=?UTF-8?B?%s?= <%s>',
120-
base64_encode($name),
121-
$a->getEncodedAddress()
122-
);
123-
}
124-
125-
return $a->toString();
117+
return $this->stringifyAddress($a);
126118
}, $addresses);
127119
}
120+
121+
protected function stringifyAddress(Address $a): string
122+
{
123+
// AWS does not support UTF-8 address
124+
if (preg_match('~[\x00-\x08\x10-\x19\x7F-\xFF\r\n]~', $name = $a->getName())) {
125+
return sprintf('=?UTF-8?B?%s?= <%s>',
126+
base64_encode($name),
127+
$a->getEncodedAddress()
128+
);
129+
}
130+
131+
return $a->toString();
132+
}
128133
}

0 commit comments

Comments
 (0)