Skip to content

Commit bafe768

Browse files
committed
bug symfony#57499 [Mailer] Add additional headers in Scaleway bridge (MrMicky-FR)
This PR was merged into the 6.4 branch. Discussion ---------- [Mailer] Add additional headers in Scaleway bridge | Q | A | ------------- | --- | Branch? | 6.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | License | MIT This adds the missing additional headers in the Scaleway bridge (I forgot to add them in the original implementation). This can be used, for example, to add a `Reply-To` header that doesn't have its own field, but is supported in the `additional_headers` field (see the [Scaleway documentation](https://www.scaleway.com/en/docs/managed-services/transactional-email/api-cli/send-emails-with-api/)). Tested with the Scaleway API and is working fine 🚀 Commits ------- 79265d6 Add additional headers in Scaleway bridge
2 parents 33cfd50 + 79265d6 commit bafe768

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

src/Symfony/Component/Mailer/Bridge/Scaleway/Tests/Transport/ScalewayApiTransportTest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@ public function testSend()
6969
$this->assertSame('attachment.txt', $body['attachments'][0]['name']);
7070
$this->assertSame('text/plain', $body['attachments'][0]['type']);
7171
$this->assertSame(base64_encode('some attachment'), $body['attachments'][0]['content']);
72+
$this->assertSame('Reply-To', $body['additional_headers'][0]['key']);
73+
$this->assertStringContainsString('[email protected]', $body['additional_headers'][0]['value']);
7274

7375
return new JsonMockResponse(['emails' => [['message_id' => 'foobar']]], [
7476
'http_code' => 200,
@@ -81,6 +83,7 @@ public function testSend()
8183
$mail->subject('Hello!')
8284
->to(new Address('[email protected]', 'Saif Eddin'))
8385
->from(new Address('[email protected]', 'Fabien'))
86+
->replyTo(new Address('[email protected]', 'Foo'))
8487
->text('Hello There!')
8588
->addPart(new DataPart('some attachment', 'attachment.txt', 'text/plain'));
8689

src/Symfony/Component/Mailer/Bridge/Scaleway/Transport/ScalewayApiTransport.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,9 @@ private function getPayload(Email $email, Envelope $envelope): array
101101
if ($attachements = $this->prepareAttachments($email)) {
102102
$payload['attachments'] = $attachements;
103103
}
104+
if ($headers = $this->getCustomHeaders($email)) {
105+
$payload['additional_headers'] = $headers;
106+
}
104107

105108
return $payload;
106109
}
@@ -122,6 +125,24 @@ private function prepareAttachments(Email $email): array
122125
return $attachments;
123126
}
124127

128+
private function getCustomHeaders(Email $email): array
129+
{
130+
$headers = [];
131+
$headersToBypass = ['from', 'to', 'cc', 'bcc', 'subject', 'content-type', 'sender'];
132+
foreach ($email->getHeaders()->all() as $name => $header) {
133+
if (\in_array($name, $headersToBypass, true)) {
134+
continue;
135+
}
136+
137+
$headers[] = [
138+
'key' => $header->getName(),
139+
'value' => $header->getBodyAsString(),
140+
];
141+
}
142+
143+
return $headers;
144+
}
145+
125146
private function formatAddress(Address $address): array
126147
{
127148
$array = ['email' => $address->getAddress()];

0 commit comments

Comments
 (0)