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 d52c7fa

Browse filesBrowse files
Merge branch '4.4' into 5.4
* 4.4: [Mailer] Restore X-Transport after failure
2 parents 3776e75 + 7f4c304 commit d52c7fa
Copy full SHA for d52c7fa

File tree

2 files changed

+31
-1
lines changed
Filter options

2 files changed

+31
-1
lines changed

‎src/Symfony/Component/Mailer/Tests/Transport/TransportsTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Mailer/Tests/Transport/TransportsTest.php
+24Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,4 +64,28 @@ public function testTransportDoesNotExist()
6464
$this->expectExceptionMessage('The "foobar" transport does not exist (available transports: "foo", "bar").');
6565
$transport->send($email);
6666
}
67+
68+
public function testTransportRestoredAfterFailure()
69+
{
70+
$exception = new \Exception();
71+
72+
$fooTransport = $this->createMock(TransportInterface::class);
73+
$fooTransport->method('send')
74+
->willThrowException($exception);
75+
76+
$transport = new Transports([
77+
'foo' => $fooTransport,
78+
]);
79+
80+
$headers = (new Headers())->addTextHeader('X-Transport', 'foo');
81+
$email = new Message($headers, new TextPart('...'));
82+
83+
$this->expectExceptionObject($exception);
84+
85+
try {
86+
$transport->send($email);
87+
} finally {
88+
$this->assertSame('foo', $email->getHeaders()->getHeaderBody('X-Transport'));
89+
}
90+
}
6791
}

‎src/Symfony/Component/Mailer/Transport/Transports.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Mailer/Transport/Transports.php
+7-1Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,13 @@ public function send(RawMessage $message, Envelope $envelope = null): ?SentMessa
5959
throw new InvalidArgumentException(sprintf('The "%s" transport does not exist (available transports: "%s").', $transport, implode('", "', array_keys($this->transports))));
6060
}
6161

62-
return $this->transports[$transport]->send($message, $envelope);
62+
try {
63+
return $this->transports[$transport]->send($message, $envelope);
64+
} catch (\Throwable $e) {
65+
$headers->addTextHeader('X-Transport', $transport);
66+
67+
throw $e;
68+
}
6369
}
6470

6571
public function __toString(): string

0 commit comments

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