Movatterモバイル変換


[0]ホーム

URL:


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

Sign up
Appearance settings

Commitd1a3b74

Browse files
committed
[Mailer] Fix error message in case of an STMP error
1 parent42938ef commitd1a3b74

File tree

3 files changed

+25
-25
lines changed

3 files changed

+25
-25
lines changed

‎src/Symfony/Component/Mailer/Tests/Transport/Smtp/EsmtpTransportTest.php‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,9 @@ public function testToString()
4040
$t =newEsmtpTransport('example.com',466,true);
4141
$this->assertEquals('smtps://example.com:466', (string)$t);
4242
}
43+
44+
publicfunctiontestErrorMessage()
45+
{
46+
47+
}
4348
}

‎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
protectedfunctiondoHeloCommand():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
thrownewTransportException('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-
privatefunctiongetCapabilities(string$ehloResponse):array
119+
privatefunctioncallHeloCommand():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 ($linesas$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
thrownewLogicException('You must set the expected response code.');
296296
}
297297

298-
if (!$response) {
299-
thrownewTransportException(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-
thrownewTransportException(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+
thrownewTransportException(sprintf('Expected response code "%s" but got %s%s.',implode('/',$codes),$codeStr,$responseStr),$code);
307305
}
308306
}
309307

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp