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

[Mailer] Fix error message in case of an STMP error #47142

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 16 additions & 19 deletions 35 src/Symfony/Component/Mailer/Transport/Smtp/EsmtpTransport.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,15 +94,7 @@ public function addAuthenticator(AuthenticatorInterface $authenticator): void

protected function doHeloCommand(): void
{
try {
$response = $this->executeCommand(sprintf("EHLO %s\r\n", $this->getLocalDomain()), [250]);
} catch (TransportExceptionInterface $e) {
parent::doHeloCommand();

return;
}

$capabilities = $this->getCapabilities($response);
$capabilities = $this->callHeloCommand();

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

try {
$response = $this->executeCommand(sprintf("EHLO %s\r\n", $this->getLocalDomain()), [250]);
$capabilities = $this->getCapabilities($response);
} catch (TransportExceptionInterface $e) {
parent::doHeloCommand();

return;
}
$capabilities = $this->callHeloCommand();
}

if (\array_key_exists('AUTH', $capabilities)) {
$this->handleAuth($capabilities['AUTH']);
}
}

private function getCapabilities(string $ehloResponse): array
private function callHeloCommand(): array
{
try {
$response = $this->executeCommand(sprintf("EHLO %s\r\n", $this->getLocalDomain()), [250]);
} catch (TransportExceptionInterface $e) {
try {
parent::doHeloCommand();
} catch (TransportExceptionInterface $ex) {
if (!$ex->getCode()) {
throw $e;
}
}
}

$capabilities = [];
$lines = explode("\r\n", trim($ehloResponse));
$lines = explode("\r\n", trim($response));
array_shift($lines);
foreach ($lines as $line) {
if (preg_match('/^[0-9]{3}[ -]([A-Z0-9-]+)((?:[ =].*)?)$/Di', $line, $matches)) {
Expand Down
10 changes: 4 additions & 6 deletions 10 src/Symfony/Component/Mailer/Transport/Smtp/SmtpTransport.php
Original file line number Diff line number Diff line change
Expand Up @@ -295,15 +295,13 @@ private function assertResponseCode(string $response, array $codes): void
throw new LogicException('You must set the expected response code.');
}

if (!$response) {
throw new TransportException(sprintf('Expected response code "%s" but got an empty response.', implode('/', $codes)));
}

[$code] = sscanf($response, '%3d');
$valid = \in_array($code, $codes);

if (!$valid) {
throw new TransportException(sprintf('Expected response code "%s" but got code "%s", with message "%s".', implode('/', $codes), $code, trim($response)), $code);
if (!$valid || !$response) {
$codeStr = $code ? sprintf('code "%s"', $code) : 'empty code';
$responseStr = $response ? sprintf(', with message "%s"', trim($response)) : '';
throw new TransportException(sprintf('Expected response code "%s" but got ', implode('/', $codes), $codeStr).$codeStr.$responseStr.'.', $code);
}
}

Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.