Don't send QUIT while DATA is in progress
If the connection is closed in the middle of a DATA command, for example from a destructor after SIGTERM, the server takes QUIT as part of the message and the connection only ends when it times out. SMTP now keeps the last command it sent in a state property, and quit() just closes the connection when that command is DATA, as discussed in #3121. Fixes #2994
This commit is contained in:
1 parent
a1bc7fa8d1
commit
0825c8cc83
2 files changed
+47
-1
No files matched your search
@@ -1116,6 +1116,37 @@ EOT;
|
||||
self::assertFalse($smtp->mail("somewhere\nbad"), 'Bad SMTP command containing breaks accepted');
|
||||
}
|
||||
|
||||
/**
|
||||
* Closing a connection in the middle of DATA must not send QUIT, as the server would take it as message content.
|
||||
*/
|
||||
public function testQuitDuringData()
|
||||
{
|
||||
self::assertTrue($this->Mail->smtpConnect(), 'SMTP connect failed');
|
||||
$smtp = $this->Mail->getSMTPInstance();
|
||||
//Don't wait long for a reply that should never be requested
|
||||
$smtp->Timelimit = 5;
|
||||
self::assertTrue($smtp->mail('phpunit@example.com'));
|
||||
self::assertTrue($smtp->recipient('somebody@example.com'));
|
||||
|
||||
//Start DATA without sending the message, as if the send had been interrupted
|
||||
$reflMethod = new \ReflectionMethod($smtp, 'sendCommand');
|
||||
(\PHP_VERSION_ID < 80100) && $reflMethod->setAccessible(true);
|
||||
self::assertTrue($reflMethod->invoke($smtp, 'DATA', 'DATA', 354));
|
||||
(\PHP_VERSION_ID < 80100) && $reflMethod->setAccessible(false);
|
||||
|
||||
$sent = '';
|
||||
$smtp->setDebugLevel(SMTP::DEBUG_CLIENT);
|
||||
$smtp->setDebugOutput(
|
||||
static function ($str) use (&$sent) {
|
||||
$sent .= $str;
|
||||
}
|
||||
);
|
||||
$smtp->quit();
|
||||
|
||||
self::assertStringNotContainsString('QUIT', $sent, 'QUIT was sent during DATA');
|
||||
self::assertFalse($smtp->connected(), 'Connection was not closed');
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests setting and retrieving ConfirmReadingTo address, also known as "read receipt" address.
|
||||
*/
|
||||
|
||||
Reference in new issue
Block a user