Skip to content

Commit 63bf36a

Browse files
committed
Merge branch '4.4' into 5.4
* 4.4: [Mailer] Fix edge cases in STMP transports Bump Symfony version to 4.4.46 Update VERSION for 4.4.45 Update CONTRIBUTORS for 4.4.45 Update CHANGELOG for 4.4.45
2 parents 076043a + 877cfb3 commit 63bf36a

File tree

3 files changed

+37
-2
lines changed

3 files changed

+37
-2
lines changed

Tests/Transport/Smtp/SmtpTransportTest.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
use PHPUnit\Framework\TestCase;
1515
use Symfony\Component\Mailer\Envelope;
16+
use Symfony\Component\Mailer\Exception\LogicException;
1617
use Symfony\Component\Mailer\Exception\TransportException;
1718
use Symfony\Component\Mailer\Transport\Smtp\SmtpTransport;
1819
use Symfony\Component\Mailer\Transport\Smtp\Stream\AbstractStream;
@@ -133,6 +134,35 @@ public function testWriteEncodedRecipientAndSenderAddresses()
133134
$this->assertContains("RCPT TO:<[email protected]>\r\n", $stream->getCommands());
134135
$this->assertContains("RCPT TO:<[email protected]>\r\n", $stream->getCommands());
135136
}
137+
138+
public function testAssertResponseCodeNoCodes()
139+
{
140+
$this->expectException(LogicException::class);
141+
$this->invokeAssertResponseCode('response', []);
142+
}
143+
144+
public function testAssertResponseCodeWithEmptyResponse()
145+
{
146+
$this->expectException(TransportException::class);
147+
$this->expectExceptionMessage('Expected response code "220" but got empty code.');
148+
$this->invokeAssertResponseCode('', [220]);
149+
}
150+
151+
public function testAssertResponseCodeWithNotValidCode()
152+
{
153+
$this->expectException(TransportException::class);
154+
$this->expectExceptionMessage('Expected response code "220" but got code "550", with message "550 Access Denied".');
155+
$this->expectExceptionCode(550);
156+
$this->invokeAssertResponseCode('550 Access Denied', [220]);
157+
}
158+
159+
private function invokeAssertResponseCode(string $response, array $codes): void
160+
{
161+
$transport = new SmtpTransport($this->getMockForAbstractClass(AbstractStream::class));
162+
$m = new \ReflectionMethod($transport, 'assertResponseCode');
163+
$m->setAccessible(true);
164+
$m->invoke($transport, $response, $codes);
165+
}
136166
}
137167

138168
class DummyStream extends AbstractStream

Transport/Smtp/EsmtpTransport.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,9 @@ public function addAuthenticator(AuthenticatorInterface $authenticator): void
100100

101101
protected function doHeloCommand(): void
102102
{
103-
$capabilities = $this->callHeloCommand();
103+
if (!$capabilities = $this->callHeloCommand()) {
104+
return;
105+
}
104106

105107
/** @var SocketStream $stream */
106108
$stream = $this->getStream();
@@ -129,6 +131,8 @@ private function callHeloCommand(): array
129131
} catch (TransportExceptionInterface $e) {
130132
try {
131133
parent::doHeloCommand();
134+
135+
return [];
132136
} catch (TransportExceptionInterface $ex) {
133137
if (!$ex->getCode()) {
134138
throw $e;

Transport/Smtp/SmtpTransport.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,8 @@ private function assertResponseCode(string $response, array $codes): void
303303
if (!$valid || !$response) {
304304
$codeStr = $code ? sprintf('code "%s"', $code) : 'empty code';
305305
$responseStr = $response ? sprintf(', with message "%s"', trim($response)) : '';
306-
throw new TransportException(sprintf('Expected response code "%s" but got ', implode('/', $codes), $codeStr).$codeStr.$responseStr.'.', $code);
306+
307+
throw new TransportException(sprintf('Expected response code "%s" but got ', implode('/', $codes)).$codeStr.$responseStr.'.', $code ?: 0);
307308
}
308309
}
309310

0 commit comments

Comments
 (0)