Skip to content

Commit 1125a1a

Browse files
Merge branch '4.4' into 5.4
* 4.4: cs fix [Messenger] Fix Doctrine transport on MySQL [Translator] Fix translator overlapse [Yaml] Improve test coverage in DumperTest and ParserTest [Mailer] Fix error message in case of an STMP error [HttpClient] Fix shared connections not being freed on PHP < 8 [HttpFoundation] Fix invalid ID not regenerated with native PHP file sessions [HttpClient] Fix memory leak when using StreamWrapper Bump Symfony version to 4.4.45 Update VERSION for 4.4.44 Update CONTRIBUTORS for 4.4.44 Update CHANGELOG for 4.4.44
2 parents 9f34f71 + 0fce8fa commit 1125a1a

File tree

2 files changed

+20
-25
lines changed

2 files changed

+20
-25
lines changed

Transport/Smtp/EsmtpTransport.php

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

101101
protected function doHeloCommand(): void
102102
{
103-
try {
104-
$response = $this->executeCommand(sprintf("EHLO %s\r\n", $this->getLocalDomain()), [250]);
105-
} catch (TransportExceptionInterface $e) {
106-
parent::doHeloCommand();
107-
108-
return;
109-
}
110-
111-
$capabilities = $this->getCapabilities($response);
103+
$capabilities = $this->callHeloCommand();
112104

113105
/** @var SocketStream $stream */
114106
$stream = $this->getStream();
@@ -122,25 +114,30 @@ protected function doHeloCommand(): void
122114
throw new TransportException('Unable to connect with STARTTLS.');
123115
}
124116

125-
try {
126-
$response = $this->executeCommand(sprintf("EHLO %s\r\n", $this->getLocalDomain()), [250]);
127-
$capabilities = $this->getCapabilities($response);
128-
} catch (TransportExceptionInterface $e) {
129-
parent::doHeloCommand();
130-
131-
return;
132-
}
117+
$capabilities = $this->callHeloCommand();
133118
}
134119

135120
if (\array_key_exists('AUTH', $capabilities)) {
136121
$this->handleAuth($capabilities['AUTH']);
137122
}
138123
}
139124

140-
private function getCapabilities(string $ehloResponse): array
125+
private function callHeloCommand(): array
141126
{
127+
try {
128+
$response = $this->executeCommand(sprintf("EHLO %s\r\n", $this->getLocalDomain()), [250]);
129+
} catch (TransportExceptionInterface $e) {
130+
try {
131+
parent::doHeloCommand();
132+
} catch (TransportExceptionInterface $ex) {
133+
if (!$ex->getCode()) {
134+
throw $e;
135+
}
136+
}
137+
}
138+
142139
$capabilities = [];
143-
$lines = explode("\r\n", trim($ehloResponse));
140+
$lines = explode("\r\n", trim($response));
144141
array_shift($lines);
145142
foreach ($lines as $line) {
146143
if (preg_match('/^[0-9]{3}[ -]([A-Z0-9-]+)((?:[ =].*)?)$/Di', $line, $matches)) {

Transport/Smtp/SmtpTransport.php

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

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

307-
if (!$valid) {
308-
throw new TransportException(sprintf('Expected response code "%s" but got code "%s", with message "%s".', implode('/', $codes), $code, trim($response)), $code);
303+
if (!$valid || !$response) {
304+
$codeStr = $code ? sprintf('code "%s"', $code) : 'empty code';
305+
$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);
309307
}
310308
}
311309

0 commit comments

Comments
 (0)