Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit aee6d08

Browse files
committed
[Mailer] Fix error message in case of an STMP error
1 parent 42938ef commit aee6d08

File tree

2 files changed

+20
-25
lines changed

2 files changed

+20
-25
lines changed

src/Symfony/Component/Mailer/Transport/Smtp/EsmtpTransport.php

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -94,15 +94,7 @@ public function addAuthenticator(AuthenticatorInterface $authenticator): void
9494

9595
protected function doHeloCommand(): void
9696
{
97-
try {
98-
$response = $this->executeCommand(sprintf("EHLO %s\r\n", $this->getLocalDomain()), [250]);
99-
} catch (TransportExceptionInterface $e) {
100-
parent::doHeloCommand();
101-
102-
return;
103-
}
104-
105-
$capabilities = $this->getCapabilities($response);
97+
$capabilities = $this->callHeloCommand();
10698

10799
/** @var SocketStream $stream */
108100
$stream = $this->getStream();
@@ -116,25 +108,30 @@ protected function doHeloCommand(): void
116108
throw new TransportException('Unable to connect with STARTTLS.');
117109
}
118110

119-
try {
120-
$response = $this->executeCommand(sprintf("EHLO %s\r\n", $this->getLocalDomain()), [250]);
121-
$capabilities = $this->getCapabilities($response);
122-
} catch (TransportExceptionInterface $e) {
123-
parent::doHeloCommand();
124-
125-
return;
126-
}
111+
$capabilities = $this->callHeloCommand();
127112
}
128113

129114
if (\array_key_exists('AUTH', $capabilities)) {
130115
$this->handleAuth($capabilities['AUTH']);
131116
}
132117
}
133118

134-
private function getCapabilities(string $ehloResponse): array
119+
private function callHeloCommand(): array
135120
{
121+
try {
122+
$response = $this->executeCommand(sprintf("EHLO %s\r\n", $this->getLocalDomain()), [250]);
123+
} catch (TransportExceptionInterface $e) {
124+
try {
125+
parent::doHeloCommand();
126+
} catch (TransportExceptionInterface $ex) {
127+
if (!$ex->getCode()) {
128+
throw $e;
129+
}
130+
}
131+
}
132+
136133
$capabilities = [];
137-
$lines = explode("\r\n", trim($ehloResponse));
134+
$lines = explode("\r\n", trim($response));
138135
array_shift($lines);
139136
foreach ($lines as $line) {
140137
if (preg_match('/^[0-9]{3}[ -]([A-Z0-9-]+)((?:[ =].*)?)$/Di', $line, $matches)) {

src/Symfony/Component/Mailer/Transport/Smtp/SmtpTransport.php

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -295,15 +295,13 @@ private function assertResponseCode(string $response, array $codes): void
295295
throw new LogicException('You must set the expected response code.');
296296
}
297297

298-
if (!$response) {
299-
throw new TransportException(sprintf('Expected response code "%s" but got an empty response.', implode('/', $codes)));
300-
}
301-
302298
[$code] = sscanf($response, '%3d');
303299
$valid = \in_array($code, $codes);
304300

305-
if (!$valid) {
306-
throw new TransportException(sprintf('Expected response code "%s" but got code "%s", with message "%s".', implode('/', $codes), $code, trim($response)), $code);
301+
if (!$valid || !$response) {
302+
$codeStr = $code ? sprintf('code "%s"', $code) : 'empty code';
303+
$responseStr = $response ? sprintf(', with message "%s"', trim($response)) : '';
304+
throw new TransportException(sprintf('Expected response code "%s" but got ', implode('/', $codes), $codeStr).$codeStr.$responseStr.'.', $code);
307305
}
308306
}
309307

0 commit comments

Comments
 (0)