Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[Mailer] Fix SES API call with UTF-8 Addresses #41206

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 16, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
[Mailer] Fix SES API call with UTF-8 Addresses
  • Loading branch information
jderusse committed May 15, 2021
commit 05a949723079c63a04e01ce21a85436871da6e1d
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ public function testSend()

$this->assertSame('Hello!', $content['Content']['Simple']['Subject']['Data']);
$this->assertSame('"Saif Eddin" <saif.gmati@symfony.com>', $content['Destination']['ToAddresses'][0]);
$this->assertSame('=?UTF-8?B?SsOpcsOpbXk=?= <jeremy@derusse.com>', $content['Destination']['CcAddresses'][0]);
$this->assertSame('"Fabien" <fabpot@symfony.com>', $content['FromEmailAddress']);
$this->assertSame('Hello There!', $content['Content']['Simple']['Body']['Text']['Data']);
$this->assertSame('<b>Hello There!</b>', $content['Content']['Simple']['Body']['Html']['Data']);
Expand All @@ -84,6 +85,7 @@ public function testSend()
$mail = new Email();
$mail->subject('Hello!')
->to(new Address('saif.gmati@symfony.com', 'Saif Eddin'))
->cc(new Address('jeremy@derusse.com', 'Jérémy'))
->from(new Address('fabpot@symfony.com', 'Fabien'))
->text('Hello There!')
->html('<b>Hello There!</b>')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ public function testSend()

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,4 +107,19 @@ private function getRecipients(Email $email, Envelope $envelope): array
return !\in_array($address, $emailRecipients, true);
});
}

protected function stringifyAddresses(array $addresses): array
{
return array_map(function (Address $a) {
// AWS does not support UTF-8 address
if (preg_match('~[\x00-\x08\x10-\x19\x7F-\xFF\r\n]~', $name = $a->getName())) {
fabpot marked this conversation as resolved.
Show resolved Hide resolved
return sprintf('=?UTF-8?B?%s?= <%s>',
base64_encode($name),
$a->getEncodedAddress()
);
}

return $a->toString();
}, $addresses);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use Symfony\Component\Mailer\Exception\HttpTransportException;
use Symfony\Component\Mailer\SentMessage;
use Symfony\Component\Mailer\Transport\AbstractApiTransport;
use Symfony\Component\Mime\Address;
use Symfony\Component\Mime\Email;
use Symfony\Contracts\EventDispatcher\EventDispatcherInterface;
use Symfony\Contracts\HttpClient\HttpClientInterface;
Expand Down Expand Up @@ -130,4 +131,19 @@ private function getPayload(Email $email, Envelope $envelope): array

return $payload;
}

protected function stringifyAddresses(array $addresses): array
fabpot marked this conversation as resolved.
Show resolved Hide resolved
{
return array_map(function (Address $a) {
// AWS does not support UTF-8 address
if (preg_match('~[\x00-\x08\x10-\x19\x7F-\xFF\r\n]~', $name = $a->getName())) {
return sprintf('=?UTF-8?B?%s?= <%s>',
base64_encode($name),
$a->getEncodedAddress()
);
}

return $a->toString();
}, $addresses);
}
}
Morty Proxy This is a proxified and sanitized view of the page, visit original site.