Skip to content

Commit f5b2050

Browse files
andrehoong-pixiesetfabpot
authored andcommitted
[Mailer][Mandrill] Add subaccount to the payload
1 parent 1684c09 commit f5b2050

File tree

3 files changed

+25
-1
lines changed

3 files changed

+25
-1
lines changed

src/Symfony/Component/Mailer/Bridge/Mailchimp/CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
CHANGELOG
22
=========
33

4+
7.4
5+
---
6+
7+
* Add support for specifying a subaccount using the `X-MC-Subaccount` header
8+
49
7.2
510
---
611

src/Symfony/Component/Mailer/Bridge/Mailchimp/Tests/Transport/MandrillApiTransportTest.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,21 @@ public function testCustomHeader()
6666
$this->assertEquals('bar', $payload['message']['headers']['foo']);
6767
}
6868

69+
public function testSubaccountHeaderIsAddedToPayload()
70+
{
71+
$email = new Email();
72+
$email->getHeaders()->addTextHeader('X-MC-Subaccount', 'foo-bar');
73+
$envelope = new Envelope(new Address('[email protected]'), [new Address('[email protected]')]);
74+
75+
$transport = new MandrillApiTransport('ACCESS_KEY');
76+
$method = new \ReflectionMethod(MandrillApiTransport::class, 'getPayload');
77+
$payload = $method->invoke($transport, $email, $envelope);
78+
79+
$this->assertArrayHasKey('subaccount', $payload['message']);
80+
$this->assertEquals('foo-bar', $payload['message']['subaccount']);
81+
$this->assertArrayNotHasKey('headers', $payload['message']);
82+
}
83+
6984
public function testSend()
7085
{
7186
$client = new MockHttpClient(function (string $method, string $url, array $options): ResponseInterface {

src/Symfony/Component/Mailer/Bridge/Mailchimp/Transport/MandrillApiTransport.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,10 @@ private function getPayload(Email $email, Envelope $envelope): array
9393
],
9494
];
9595

96+
if ($email->getHeaders()->get('X-MC-Subaccount')) {
97+
$payload['message']['subaccount'] = $email->getHeaders()->get('X-MC-Subaccount')->getBodyAsString();
98+
}
99+
96100
if ('' !== $envelope->getSender()->getName()) {
97101
$payload['message']['from_name'] = $envelope->getSender()->getName();
98102
}
@@ -118,7 +122,7 @@ private function getPayload(Email $email, Envelope $envelope): array
118122
}
119123

120124
foreach ($email->getHeaders()->all() as $name => $header) {
121-
if (\in_array($name, ['from', 'to', 'cc', 'bcc', 'subject', 'content-type'], true)) {
125+
if (\in_array($name, ['from', 'to', 'cc', 'bcc', 'subject', 'content-type', 'x-mc-subaccount'], true)) {
122126
continue;
123127
}
124128

0 commit comments

Comments
 (0)