From 8d9741467c53750dc8ccda23a1cdb91cda732571 Mon Sep 17 00:00:00 2001 From: Romanavr Date: Thu, 12 Oct 2023 15:48:09 +0300 Subject: [PATCH] [Mailer] Capitalize sender header for Mailgun --- Tests/Transport/MailgunApiTransportTest.php | 6 +++--- Tests/Transport/MailgunHttpTransportTest.php | 12 ++---------- Transport/MailgunApiTransport.php | 2 +- Transport/MailgunHttpTransport.php | 1 - 4 files changed, 6 insertions(+), 15 deletions(-) diff --git a/Tests/Transport/MailgunApiTransportTest.php b/Tests/Transport/MailgunApiTransportTest.php index 808798e..e60a153 100644 --- a/Tests/Transport/MailgunApiTransportTest.php +++ b/Tests/Transport/MailgunApiTransportTest.php @@ -62,7 +62,7 @@ public function testCustomHeader() $email = new Email(); $envelope = new Envelope(new Address('alice@system.com'), [new Address('bob@system.com')]); - $email->getHeaders()->addTextHeader('h:sender', $envelope->getSender()->toString()); + $email->getHeaders()->addTextHeader('h:Sender', $envelope->getSender()->toString()); $email->getHeaders()->addTextHeader('h:X-Mailgun-Variables', $json); $email->getHeaders()->addTextHeader('h:foo', 'foo-value'); $email->getHeaders()->addTextHeader('t:text', 'text-value'); @@ -79,8 +79,8 @@ public function testCustomHeader() $this->assertArrayHasKey('h:X-Mailgun-Variables', $payload); $this->assertEquals($json, $payload['h:X-Mailgun-Variables']); - $this->assertArrayHasKey('h:sender', $payload); - $this->assertEquals($envelope->getSender()->toString(), $payload['h:sender']); + $this->assertArrayHasKey('h:Sender', $payload); + $this->assertEquals($envelope->getSender()->toString(), $payload['h:Sender']); $this->assertArrayHasKey('h:foo', $payload); $this->assertEquals('foo-value', $payload['h:foo']); $this->assertArrayHasKey('t:text', $payload); diff --git a/Tests/Transport/MailgunHttpTransportTest.php b/Tests/Transport/MailgunHttpTransportTest.php index cc83f6f..85342c2 100644 --- a/Tests/Transport/MailgunHttpTransportTest.php +++ b/Tests/Transport/MailgunHttpTransportTest.php @@ -69,8 +69,6 @@ public function testSend() $this->assertStringContainsString('Subject: Hello!', $content); $this->assertStringContainsString('To: Saif Eddin ', $content); $this->assertStringContainsString('From: Fabien ', $content); - $this->assertStringContainsString('Sender: Senior Fabien Eddin ', $content); - $this->assertStringContainsString('h:sender: "Senior Fabien Eddin" ', $content); $this->assertStringContainsString('Hello There!', $content); return new MockResponse(json_encode(['id' => 'foobar']), [ @@ -81,17 +79,11 @@ public function testSend() $transport->setPort(8984); $mail = new Email(); - $toAddress = new Address('saif.gmati@symfony.com', 'Saif Eddin'); - $fromAddress = new Address('fabpot@symfony.com', 'Fabien'); - $senderAddress = new Address('fabpot@symfony.com', 'Senior Fabien Eddin'); $mail->subject('Hello!') - ->to($toAddress) - ->from($fromAddress) - ->sender($senderAddress) + ->to(new Address('saif.gmati@symfony.com', 'Saif Eddin')) + ->from(new Address('fabpot@symfony.com', 'Fabien')) ->text('Hello There!'); - $mail->getHeaders()->addHeader('h:sender', $mail->getSender()->toString()); - $message = $transport->send($mail); $this->assertSame('foobar', $message->getMessageId()); diff --git a/Transport/MailgunApiTransport.php b/Transport/MailgunApiTransport.php index 36fb59c..7c92754 100644 --- a/Transport/MailgunApiTransport.php +++ b/Transport/MailgunApiTransport.php @@ -87,7 +87,7 @@ protected function doSendApi(SentMessage $sentMessage, Email $email, Envelope $e private function getPayload(Email $email, Envelope $envelope): array { $headers = $email->getHeaders(); - $headers->addHeader('h:sender', $envelope->getSender()->toString()); + $headers->addHeader('h:Sender', $envelope->getSender()->toString()); $html = $email->getHtmlBody(); if (null !== $html && \is_resource($html)) { if (stream_get_meta_data($html)['seekable'] ?? false) { diff --git a/Transport/MailgunHttpTransport.php b/Transport/MailgunHttpTransport.php index 1af78bf..7dbbb8d 100644 --- a/Transport/MailgunHttpTransport.php +++ b/Transport/MailgunHttpTransport.php @@ -53,7 +53,6 @@ public function __toString(): string protected function doSendHttp(SentMessage $message): ResponseInterface { $body = new FormDataPart([ - 'h:sender' => $message->getEnvelope()->getSender()->toString(), 'to' => implode(',', $this->stringifyAddresses($message->getEnvelope()->getRecipients())), 'message' => new DataPart($message->toString(), 'message.mime'), ]);