Skip to content

Commit

Permalink
Merge branch '6.3' into 6.4
Browse files Browse the repository at this point in the history
* 6.3:
  Make FormPerformanceTestCase compatible with PHPUnit 10
  [Security] Fix resetting traceable listeners
  [HttpClient] Fix type error with http_version 1.1
  [FrameworkBundle] Fix call to invalid method in NotificationAssertionsTrait
  [Validator] Add missing italian translations
  Fix order array sum normalizedData and nestedData
  Fix duplicate component in UPGRADE-6.3.md
  [Notifier] Tweak an error message
  Change incorrect message, when the sender in the global envelope or the from header of asEmailMessage() is not defined.
  [Messenger] Check if PCNTL is installed
  Bump Symfony version to 6.3.6
  Update VERSION for 6.3.5
  Update CHANGELOG for 6.3.5
  Bump Symfony version to 5.4.30
  Update VERSION for 5.4.29
  Update CONTRIBUTORS for 5.4.29
  Update CHANGELOG for 5.4.29
  [Mailer] [Mailgun] Fix outlook sender
  • Loading branch information
derrabus committed Oct 7, 2023
2 parents 314ebef + b467aba commit e8d52e1
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 3 deletions.
5 changes: 4 additions & 1 deletion Tests/Transport/MailgunApiTransportTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ public function testCustomHeader()
$deliveryTime = (new \DateTimeImmutable('2020-03-20 13:01:00'))->format(\DateTimeInterface::RFC2822);

$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:X-Mailgun-Variables', $json);
$email->getHeaders()->addTextHeader('h:foo', 'foo-value');
$email->getHeaders()->addTextHeader('t:text', 'text-value');
Expand All @@ -69,7 +71,6 @@ public function testCustomHeader()
$email->getHeaders()->addTextHeader('template', 'template-value');
$email->getHeaders()->addTextHeader('recipient-variables', 'recipient-variables-value');
$email->getHeaders()->addTextHeader('amp-html', 'amp-html-value');
$envelope = new Envelope(new Address('alice@system.com'), [new Address('bob@system.com')]);

$transport = new MailgunApiTransport('ACCESS_KEY', 'DOMAIN');
$method = new \ReflectionMethod(MailgunApiTransport::class, 'getPayload');
Expand All @@ -78,6 +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:foo', $payload);
$this->assertEquals('foo-value', $payload['h:foo']);
$this->assertArrayHasKey('t:text', $payload);
Expand Down
12 changes: 10 additions & 2 deletions Tests/Transport/MailgunHttpTransportTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ public function testSend()
$this->assertStringContainsString('Subject: Hello!', $content);
$this->assertStringContainsString('To: Saif Eddin <saif.gmati@symfony.com>', $content);
$this->assertStringContainsString('From: Fabien <fabpot@symfony.com>', $content);
$this->assertStringContainsString('Sender: Senior Fabien Eddin <fabpot@symfony.com>', $content);
$this->assertStringContainsString('h:sender: "Senior Fabien Eddin" <fabpot@symfony.com>', $content);
$this->assertStringContainsString('Hello There!', $content);

return new MockResponse(json_encode(['id' => 'foobar']), [
Expand All @@ -79,11 +81,17 @@ 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(new Address('saif.gmati@symfony.com', 'Saif Eddin'))
->from(new Address('fabpot@symfony.com', 'Fabien'))
->to($toAddress)
->from($fromAddress)
->sender($senderAddress)
->text('Hello There!');

$mail->getHeaders()->addHeader('h:sender', $mail->getSender()->toString());

$message = $transport->send($mail);

$this->assertSame('foobar', $message->getMessageId());
Expand Down
1 change: 1 addition & 0 deletions Transport/MailgunApiTransport.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +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());
$html = $email->getHtmlBody();
if (null !== $html && \is_resource($html)) {
if (stream_get_meta_data($html)['seekable'] ?? false) {
Expand Down
1 change: 1 addition & 0 deletions Transport/MailgunHttpTransport.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ 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'),
]);
Expand Down

0 comments on commit e8d52e1

Please sign in to comment.