Skip to content

Commit 61622d3

Browse files
committed
[Mailer] Fix SES API call with UTF-8 Addresses
1 parent b802c6d commit 61622d3

File tree

4 files changed

+35
-0
lines changed

4 files changed

+35
-0
lines changed

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

+2
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ public function testSend()
6565

6666
$this->assertSame('Hello!', $content['Content']['Simple']['Subject']['Data']);
6767
$this->assertSame('"Saif Eddin" <saif.gmati@symfony.com>', $content['Destination']['ToAddresses'][0]);
68+
$this->assertSame('"=?UTF-8?B?SsOpcsOpbXk=?=" <jeremy@derusse.com>', $content['Destination']['CcAddresses'][0]);
6869
$this->assertSame('"Fabien" <fabpot@symfony.com>', $content['FromEmailAddress']);
6970
$this->assertSame('Hello There!', $content['Content']['Simple']['Body']['Text']['Data']);
7071
$this->assertSame('<b>Hello There!</b>', $content['Content']['Simple']['Body']['Html']['Data']);
@@ -84,6 +85,7 @@ public function testSend()
8485
$mail = new Email();
8586
$mail->subject('Hello!')
8687
->to(new Address('saif.gmati@symfony.com', 'Saif Eddin'))
88+
->cc(new Address('jeremy@derusse.com', 'Jérémy'))
8789
->from(new Address('fabpot@symfony.com', 'Fabien'))
8890
->text('Hello There!')
8991
->html('<b>Hello There!</b>')

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

+2
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ public function testSend()
6666

6767
$this->assertSame('Hello!', $content['Message_Subject_Data']);
6868
$this->assertSame('"Saif Eddin" <saif.gmati@symfony.com>', $content['Destination_ToAddresses_member'][0]);
69+
$this->assertSame('"=?UTF-8?B?SsOpcsOpbXk=?=" <jeremy@derusse.com>', $content['Destination_CcAddresses_member'][0]);
6970
$this->assertSame('"Fabien" <fabpot@symfony.com>', $content['Source']);
7071
$this->assertSame('Hello There!', $content['Message_Body_Text_Data']);
7172
$this->assertSame('aws-configuration-set-name', $content['ConfigurationSetName']);
@@ -86,6 +87,7 @@ public function testSend()
8687
$mail = new Email();
8788
$mail->subject('Hello!')
8889
->to(new Address('saif.gmati@symfony.com', 'Saif Eddin'))
90+
->cc(new Address('jeremy@derusse.com', 'Jérémy'))
8991
->from(new Address('fabpot@symfony.com', 'Fabien'))
9092
->text('Hello There!');
9193

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

+15
Original file line numberDiff line numberDiff line change
@@ -107,4 +107,19 @@ private function getRecipients(Email $email, Envelope $envelope): array
107107
return !\in_array($address, $emailRecipients, true);
108108
});
109109
}
110+
111+
protected function stringifyAddresses(array $addresses): array
112+
{
113+
return array_map(function (Address $a) {
114+
// AWS does not support UTF-8 address
115+
if (preg_match('~[\x00-\x08\x10-\x19\x7F-\xFF\r\n]~', $name = $a->getName())) {
116+
return sprintf('"=?UTF-8?B?%s?=" <%s>',
117+
base64_encode($name),
118+
$a->getEncodedAddress()
119+
);
120+
}
121+
122+
return $a->toString();
123+
}, $addresses);
124+
}
110125
}

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

+16
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use Symfony\Component\Mailer\Exception\HttpTransportException;
1717
use Symfony\Component\Mailer\SentMessage;
1818
use Symfony\Component\Mailer\Transport\AbstractApiTransport;
19+
use Symfony\Component\Mime\Address;
1920
use Symfony\Component\Mime\Email;
2021
use Symfony\Contracts\EventDispatcher\EventDispatcherInterface;
2122
use Symfony\Contracts\HttpClient\HttpClientInterface;
@@ -130,4 +131,19 @@ private function getPayload(Email $email, Envelope $envelope): array
130131

131132
return $payload;
132133
}
134+
135+
protected function stringifyAddresses(array $addresses): array
136+
{
137+
return array_map(function (Address $a) {
138+
// AWS does not support UTF-8 address
139+
if (preg_match('~[\x00-\x08\x10-\x19\x7F-\xFF\r\n]~', $name = $a->getName())) {
140+
return sprintf('"=?UTF-8?B?%s?=" <%s>',
141+
base64_encode($name),
142+
$a->getEncodedAddress()
143+
);
144+
}
145+
146+
return $a->toString();
147+
}, $addresses);
148+
}
133149
}

0 commit comments

Comments
 (0)