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 754f754

Browse filesBrowse files
bug #47142 [Mailer] Fix error message in case of an STMP error (fabpot)
This PR was merged into the 4.4 branch. Discussion ---------- [Mailer] Fix error message in case of an STMP error | Q | A | ------------- | --- | Branch? | 4.4 | Bug fix? | yes | New feature? | no <!-- please update src/**/CHANGELOG.md files --> | Deprecations? | no <!-- please update UPGRADE-*.md and src/**/CHANGELOG.md files --> | Tickets | Fix #40414 <!-- prefix each issue number with "Fix #", no need to create an issue if none exist, explain below instead --> | License | MIT | Doc PR | n/a Better exception messages are generally done in the "main" branch, but this one is quite nasty as it masks the actual error message from the SMTP server, so I think it deserves to be merged in 4.4. Commits ------- aee6d08 [Mailer] Fix error message in case of an STMP error
2 parents 7129a32 + aee6d08 commit 754f754
Copy full SHA for 754f754

File tree

2 files changed

+20
-25
lines changed
Filter options

2 files changed

+20
-25
lines changed

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Mailer/Transport/Smtp/EsmtpTransport.php
+16-19Lines 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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Mailer/Transport/Smtp/SmtpTransport.php
+4-6Lines 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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.