From 3230a653d3480f5fbb5b40c4f6e8f6e95ade2f30 Mon Sep 17 00:00:00 2001 From: djmaze Date: Wed, 27 Oct 2021 21:14:52 +0200 Subject: [PATCH] Bugfix: there's a long standing IMAP CLIENTBUG where STATUS command is executed after SELECT/EXAMINE on same folder --- .../app/libraries/MailSo/Imap/ImapClient.php | 18 +++++++++++++----- .../app/libraries/MailSo/Mail/MailClient.php | 7 +------ 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/snappymail/v/0.0.0/app/libraries/MailSo/Imap/ImapClient.php b/snappymail/v/0.0.0/app/libraries/MailSo/Imap/ImapClient.php index c5e31dcc4..20c9a0f0d 100644 --- a/snappymail/v/0.0.0/app/libraries/MailSo/Imap/ImapClient.php +++ b/snappymail/v/0.0.0/app/libraries/MailSo/Imap/ImapClient.php @@ -429,6 +429,10 @@ class ImapClient extends \MailSo\Net\NetClient */ public function FolderStatus(string $sFolderName, array $aStatusItems) : ?array { + $oFolderInfo = $this->oCurrentFolderInfo; + if ($sFolderName === $oFolderInfo->FolderName) { + return $oFolderInfo->getStatusItems(); + } return \count($aStatusItems) ? $this->SendRequestGetResponse('STATUS', array($this->EscapeString($sFolderName), $aStatusItems)) ->getStatusFolderInformationResult() @@ -735,6 +739,7 @@ class ImapClient extends \MailSo\Net\NetClient if (!$aSearchOrSortReturn) { + // ALL OR COUNT | MIN | MAX $aSearchOrSortReturn = array('ALL'); } @@ -1039,6 +1044,8 @@ class ImapClient extends \MailSo\Net\NetClient $sFakeCommand = $sTag.' '.$sCommand.$this->prepareParamLine($aFakeParams); } +// $this->lastCommand = $sFakeCommand ?: $sRealCommand; + $this->aTagTimeouts[$sTag] = \microtime(true); if ($bBreakOnLiteral && !\preg_match('/\d\+\}\r\n/', $sRealCommand)) @@ -1123,6 +1130,12 @@ class ImapClient extends \MailSo\Net\NetClient throw new Exceptions\ResponseNotFoundException; } + // RFC 5530 + if (\is_array($oResponse->OptionalResponse) && 'CLIENTBUG' === $oResponse->OptionalResponse[0]) { + // The server has detected a client bug. +// \error_log("IMAP {$oResponse->OptionalResponse[0]}: {$this->lastCommand}"); + } + $oResult->append($oResponse); if ($sEndTag === $oResponse->Tag || Enumerations\ResponseType::CONTINUATION === $oResponse->ResponseType) { if (isset($this->aTagTimeouts[$sEndTag])) { @@ -1134,11 +1147,6 @@ class ImapClient extends \MailSo\Net\NetClient break; } - - // RFC 5530 - if (\is_array($oResponse->OptionalResponse) && 'CLIENTBUG' === $oResponse->OptionalResponse[0]) { - // The server has detected a client bug. - } } } diff --git a/snappymail/v/0.0.0/app/libraries/MailSo/Mail/MailClient.php b/snappymail/v/0.0.0/app/libraries/MailSo/Mail/MailClient.php index d7889c766..1002f0e10 100644 --- a/snappymail/v/0.0.0/app/libraries/MailSo/Mail/MailClient.php +++ b/snappymail/v/0.0.0/app/libraries/MailSo/Mail/MailClient.php @@ -630,14 +630,9 @@ class MailClient { $aFlags = array(); - $bSelect = false; - if (\count($aUids)) { - if (!$bSelect) - { - $this->oImapClient->FolderSelect($sFolderName); - } + $this->oImapClient->FolderSelect($sFolderName); $aFetchResponse = $this->oImapClient->Fetch(array( \MailSo\Imap\Enumerations\FetchType::INDEX,