Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ed9f973

Browse files
committed
bug #45691 [Mailer] fix: stringify from address for ses+api transport (everyx)
This PR was submitted for the 6.0 branch but it was merged into the 5.4 branch instead. Discussion ---------- [Mailer] fix: stringify from address for ses+api transport close: #45660 | Q | A | ------------- | --- | Branch? | 6.0 for bug fixes <!-- see below --> | Bug fix? | yes | New feature? | no <!-- please update src/**/CHANGELOG.md files --> | Deprecations? | no <!-- please update UPGRADE-*.md and src/**/CHANGELOG.md files --> | Tickets | Fix #45660 <!-- prefix each issue number with "Fix #", no need to create an issue if none exist, explain below instead --> | License | MIT | Doc PR | <!-- required for new features --> > There are non-ASCII characters in the email address—The email address string must be 7-bit ASCII. If you want to send to or from email addresses that contain Unicode characters in the domain part of an address, you must encode the domain using Punycode. Punycode is not permitted in the local part of the email address (the part before the @ sign) nor in the "friendly from" name. If you want to use Unicode characters in the "friendly from" name, you must encode the "friendly from" name using MIME encoded-word syntax, as described in [Sending raw email using the Amazon SES API](https://docs.aws.amazon.com/ses/latest/dg/send-email-raw.html). For more information about Punycode, see [RFC 3492](http://tools.ietf.org/html/rfc3492). \- from [Amazon SES email sending errors](https://docs.aws.amazon.com/ses/latest/dg/troubleshoot-error-messages.html) We have already stringify to addresses, and we should also stringify the from address. Commits ------- 69c1bdb fix: stringify from address for ses+api transport
2 parents d63e0fe + 69c1bdb commit ed9f973

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)