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

Commit fb4f862

Browse filesBrowse files
bug #52017 [Mailer] Capitalize sender header for Mailgun (Romanavr)
This PR was squashed before being merged into the 6.3 branch. Discussion ---------- [Mailer] Capitalize sender header for Mailgun | Q | A | ------------- | --- | Branch? | 6.3 | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | Fix #51773 (comment) | License | MIT This fix resolves the duplicate header issue. Without a fix, using API & HTTP transport type, emails could leave with double headers, causing problems for some email providers, for example, the problem was reproduced with Gmail: `5.7.1 This message is not RFC 5322 compliant. There are multiple Sender 5.7.1 headers. To reduce the amount of spam sent to Gmail, this message has 5.7.1 been blocked.` Moreover, I found that changes to HTTP transport type were not necessary since this problem could be solved by simply adding a sender, so I reverted everything for HTTP transport type. Commits ------- eb394bb [Mailer] Capitalize sender header for Mailgun
2 parents ab04a7a + eb394bb commit fb4f862
Copy full SHA for fb4f862

File tree

4 files changed

+6
-15
lines changed
Filter options

4 files changed

+6
-15
lines changed

‎src/Symfony/Component/Mailer/Bridge/Mailgun/Tests/Transport/MailgunApiTransportTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Mailer/Bridge/Mailgun/Tests/Transport/MailgunApiTransportTest.php
+3-3Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public function testCustomHeader()
6262

6363
$email = new Email();
6464
$envelope = new Envelope(new Address('alice@system.com'), [new Address('bob@system.com')]);
65-
$email->getHeaders()->addTextHeader('h:sender', $envelope->getSender()->toString());
65+
$email->getHeaders()->addTextHeader('h:Sender', $envelope->getSender()->toString());
6666
$email->getHeaders()->addTextHeader('h:X-Mailgun-Variables', $json);
6767
$email->getHeaders()->addTextHeader('h:foo', 'foo-value');
6868
$email->getHeaders()->addTextHeader('t:text', 'text-value');
@@ -79,8 +79,8 @@ public function testCustomHeader()
7979
$this->assertArrayHasKey('h:X-Mailgun-Variables', $payload);
8080
$this->assertEquals($json, $payload['h:X-Mailgun-Variables']);
8181

82-
$this->assertArrayHasKey('h:sender', $payload);
83-
$this->assertEquals($envelope->getSender()->toString(), $payload['h:sender']);
82+
$this->assertArrayHasKey('h:Sender', $payload);
83+
$this->assertEquals($envelope->getSender()->toString(), $payload['h:Sender']);
8484
$this->assertArrayHasKey('h:foo', $payload);
8585
$this->assertEquals('foo-value', $payload['h:foo']);
8686
$this->assertArrayHasKey('t:text', $payload);

‎src/Symfony/Component/Mailer/Bridge/Mailgun/Tests/Transport/MailgunHttpTransportTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Mailer/Bridge/Mailgun/Tests/Transport/MailgunHttpTransportTest.php
+2-10Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,6 @@ public function testSend()
6969
$this->assertStringContainsString('Subject: Hello!', $content);
7070
$this->assertStringContainsString('To: Saif Eddin <saif.gmati@symfony.com>', $content);
7171
$this->assertStringContainsString('From: Fabien <fabpot@symfony.com>', $content);
72-
$this->assertStringContainsString('Sender: Senior Fabien Eddin <fabpot@symfony.com>', $content);
73-
$this->assertStringContainsString('h:sender: "Senior Fabien Eddin" <fabpot@symfony.com>', $content);
7472
$this->assertStringContainsString('Hello There!', $content);
7573

7674
return new MockResponse(json_encode(['id' => 'foobar']), [
@@ -81,17 +79,11 @@ public function testSend()
8179
$transport->setPort(8984);
8280

8381
$mail = new Email();
84-
$toAddress = new Address('saif.gmati@symfony.com', 'Saif Eddin');
85-
$fromAddress = new Address('fabpot@symfony.com', 'Fabien');
86-
$senderAddress = new Address('fabpot@symfony.com', 'Senior Fabien Eddin');
8782
$mail->subject('Hello!')
88-
->to($toAddress)
89-
->from($fromAddress)
90-
->sender($senderAddress)
83+
->to(new Address('saif.gmati@symfony.com', 'Saif Eddin'))
84+
->from(new Address('fabpot@symfony.com', 'Fabien'))
9185
->text('Hello There!');
9286

93-
$mail->getHeaders()->addHeader('h:sender', $mail->getSender()->toString());
94-
9587
$message = $transport->send($mail);
9688

9789
$this->assertSame('foobar', $message->getMessageId());

‎src/Symfony/Component/Mailer/Bridge/Mailgun/Transport/MailgunApiTransport.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Mailer/Bridge/Mailgun/Transport/MailgunApiTransport.php
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ protected function doSendApi(SentMessage $sentMessage, Email $email, Envelope $e
8787
private function getPayload(Email $email, Envelope $envelope): array
8888
{
8989
$headers = $email->getHeaders();
90-
$headers->addHeader('h:sender', $envelope->getSender()->toString());
90+
$headers->addHeader('h:Sender', $envelope->getSender()->toString());
9191
$html = $email->getHtmlBody();
9292
if (null !== $html && \is_resource($html)) {
9393
if (stream_get_meta_data($html)['seekable'] ?? false) {

‎src/Symfony/Component/Mailer/Bridge/Mailgun/Transport/MailgunHttpTransport.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Mailer/Bridge/Mailgun/Transport/MailgunHttpTransport.php
-1Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ public function __toString(): string
5353
protected function doSendHttp(SentMessage $message): ResponseInterface
5454
{
5555
$body = new FormDataPart([
56-
'h:sender' => $message->getEnvelope()->getSender()->toString(),
5756
'to' => implode(',', $this->stringifyAddresses($message->getEnvelope()->getRecipients())),
5857
'message' => new DataPart($message->toString(), 'message.mime'),
5958
]);

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.