bug #33994 [Mailer] Fix Mandrill Transport API payload for named addresses (Michaël Perrin)

This PR was merged into the 4.3 branch.

Discussion
----------

[Mailer] Fix Mandrill Transport API payload for named addresses

| Q             | A
| ------------- | ---
| Branch?       | 4.3
| 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 #33993 <!-- prefix each issue number with "Fix #", if any -->
| License       | MIT

Fix the Mandrill transport API payload when using named addressed. Fixes #33993 .

I will make an other PR for branch 4.4 that includes tests on the payload as well (tests on mailing transports were introduced in 4.4)? I can do this on Wednesday.

Commits
-------

6dbac13a07 [Mailer] Fix Mandrill Transport API payload with named addresses
This commit is contained in:
Fabien Potencier 2019-10-16 08:32:41 +02:00
commit 537d373e0d

View File

@ -17,6 +17,7 @@ use Symfony\Component\Mailer\Exception\TransportException;
use Symfony\Component\Mailer\SmtpEnvelope;
use Symfony\Component\Mailer\Transport\Http\Api\AbstractApiTransport;
use Symfony\Component\Mime\Email;
use Symfony\Component\Mime\NamedAddress;
use Symfony\Contracts\HttpClient\HttpClientInterface;
/**
@ -60,11 +61,15 @@ class MandrillTransport extends AbstractApiTransport
'html' => $email->getHtmlBody(),
'text' => $email->getTextBody(),
'subject' => $email->getSubject(),
'from_email' => $envelope->getSender()->toString(),
'from_email' => $envelope->getSender()->getAddress(),
'to' => $this->getRecipients($email, $envelope),
],
];
if ($envelope->getSender() instanceof NamedAddress) {
$payload['message']['from_name'] = $envelope->getSender()->getName();
}
foreach ($email->getAttachments() as $attachment) {
$headers = $attachment->getPreparedHeaders();
$disposition = $headers->getHeaderBody('Content-Disposition');
@ -104,10 +109,16 @@ class MandrillTransport extends AbstractApiTransport
$type = 'cc';
}
$recipients[] = [
'email' => $recipient->toString(),
$recipientPayload = [
'email' => $recipient->getAddress(),
'type' => $type,
];
if ($recipient instanceof NamedAddress) {
$recipientPayload['name'] = $recipient->getName();
}
$recipients[] = $recipientPayload;
}
return $recipients;