From 1db5a32683f54fe0f51f992972fcfba4f644c352 Mon Sep 17 00:00:00 2001 From: Stevehans Date: Fri, 13 Dec 2024 15:20:56 +0000 Subject: [PATCH] Update SMTP.php Resolves issue 2994 --- src/SMTP.php | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/SMTP.php b/src/SMTP.php index b4eff404..84cb8d2e 100644 --- a/src/SMTP.php +++ b/src/SMTP.php @@ -264,6 +264,12 @@ class SMTP */ protected $last_reply = ''; + /** + * Whether we are in the DATA phase or not + * @var bool + */ + private $inData = false; + /** * Output debugging info via a user-selected method. * @@ -737,9 +743,12 @@ class SMTP { //This will use the standard timelimit if (!$this->sendCommand('DATA', 'DATA', 354)) { + $this->inData = false; return false; } + $this->inData = true; + /* The server is ready to accept data! * According to rfc821 we should not send more than 1000 characters on a single line (including the LE) * so we will break the data up into lines by \r and/or \n then if needed we will break each of those into @@ -811,6 +820,7 @@ class SMTP $this->recordLastTransactionID(); //Restore timelimit $this->Timelimit = $savetimelimit; + $this->inData = false; return $result; } @@ -941,7 +951,11 @@ class SMTP */ public function quit($close_on_error = true) { - $noerror = $this->sendCommand('QUIT', 'QUIT', 221); + if ($this->inData) { + $noerror = true; + } else { + $noerror = $this->sendCommand('QUIT', 'QUIT', 221); + } $err = $this->error; //Save any error if ($noerror || $close_on_error) { $this->close();