From a7f93ef864d0e6bc64cb24e4d3681d4277b26414 Mon Sep 17 00:00:00 2001 From: the-djmaze <> Date: Mon, 5 Dec 2022 10:31:13 +0100 Subject: [PATCH] Remove `UNSEEN` on IMAP4rev2 deprecated SELECT/EXAMINE --- .../MailSo/Imap/Commands/Folders.php | 28 ++++++++++-- .../MailSo/Imap/FolderInformation.php | 6 --- .../MailSo/Mail/MessageCollection.php | 44 +++++-------------- 3 files changed, 34 insertions(+), 44 deletions(-) diff --git a/snappymail/v/0.0.0/app/libraries/MailSo/Imap/Commands/Folders.php b/snappymail/v/0.0.0/app/libraries/MailSo/Imap/Commands/Folders.php index 9694cf556..e38fdf231 100644 --- a/snappymail/v/0.0.0/app/libraries/MailSo/Imap/Commands/Folders.php +++ b/snappymail/v/0.0.0/app/libraries/MailSo/Imap/Commands/Folders.php @@ -112,7 +112,7 @@ trait Folders * * https://datatracker.ietf.org/doc/html/rfc9051#section-6.3.11 */ - public function FolderStatus(string $sFolderName) : FolderInformation + public function FolderStatus(string $sFolderName, bool $bSelect = false) : FolderInformation { $aStatusItems = array( FolderResponseStatus::MESSAGES, @@ -166,14 +166,31 @@ trait Folders $oInfo->setStatusFromResponse($oResponse); } - if ($bReselect) { - $this->selectOrExamineFolder($sFolderName, $bWritable, false); -// $this->oCurrentFolderInfo->UNSEEN = $oInfo->UNSEEN; + if ($bReselect || $bSelect) { + // Don't use FolderExamine, else PERMANENTFLAGS is empty in Dovecot + $oFolderInformation = $this->selectOrExamineFolder($sFolderName, $bSelect || $bWritable, false); + $oFolderInformation->MESSAGES = \max(0, $oFolderInformation->MESSAGES, $oInfo->MESSAGES); + // $oFolderInformation has the message sequence number of the first unseen message in the mailbox + // so we set it to the amount of unseen messages + $oFolderInformation->UNSEEN = \max(0, $oInfo->UNSEEN); + $oFolderInformation->UIDNEXT = \max(0, $oFolderInformation->UIDNEXT, $oInfo->UIDNEXT); + $oFolderInformation->UIDVALIDITY = \max(0, $oFolderInformation->UIDVALIDITY, $oInfo->UIDVALIDITY); + $oFolderInformation->HIGHESTMODSEQ = \max(0, $oInfo->HIGHESTMODSEQ); + $oFolderInformation->APPENDLIMIT = \max(0, $oFolderInformation->APPENDLIMIT, $oInfo->APPENDLIMIT); + $oFolderInformation->MAILBOXID = $oFolderInformation->MAILBOXID ?: $oInfo->MAILBOXID; +// $oFolderInformation->SIZE = \max($oFolderInformation->SIZE, $oInfo->SIZE); +// $oFolderInformation->RECENT = \max(0, $oFolderInformation->RECENT, $oInfo->RECENT); + return $oFolderInformation; } return $oInfo; } + public function FolderStatusAndSelect(string $sFolderName) : FolderInformation + { + return $this->FolderStatus($sFolderName, true); + } + /** * @throws \MailSo\RuntimeException * @throws \MailSo\Net\Exceptions\* @@ -382,6 +399,9 @@ trait Folders } } + // IMAP4rev2 deprecated + $oResult->UNSEEN = null; + $this->oCurrentFolderInfo = $oResult; return $oResult; diff --git a/snappymail/v/0.0.0/app/libraries/MailSo/Imap/FolderInformation.php b/snappymail/v/0.0.0/app/libraries/MailSo/Imap/FolderInformation.php index 256dba1d5..0954bdf7f 100644 --- a/snappymail/v/0.0.0/app/libraries/MailSo/Imap/FolderInformation.php +++ b/snappymail/v/0.0.0/app/libraries/MailSo/Imap/FolderInformation.php @@ -41,12 +41,6 @@ class FolderInformation implements \JsonSerializable */ public $PermanentFlags = array(); - /** - * https://datatracker.ietf.org/doc/html/rfc3501#section-7.3.1 - * @var int - */ - public $Exists = null; - function __construct(string $sFolderName, bool $bIsWritable) { $this->FolderName = $sFolderName; diff --git a/snappymail/v/0.0.0/app/libraries/MailSo/Mail/MessageCollection.php b/snappymail/v/0.0.0/app/libraries/MailSo/Mail/MessageCollection.php index 3cb2e990e..ac227fe04 100644 --- a/snappymail/v/0.0.0/app/libraries/MailSo/Mail/MessageCollection.php +++ b/snappymail/v/0.0.0/app/libraries/MailSo/Mail/MessageCollection.php @@ -17,53 +17,29 @@ namespace MailSo\Mail; */ class MessageCollection extends \MailSo\Base\Collection { - /** - * @var string - */ - public $FolderHash = ''; + public string $FolderHash = ''; /** - * @var int + * Amount of UIDs in this list (could be less then total messages when using threads) */ - public $MessageResultCount = 0; + public int $MessageResultCount = 0; - /** - * @var string - */ - public $FolderName = ''; + public string $FolderName = ''; - /** - * @var int - */ - public $Offset = 0; + public int $Offset = 0; - /** - * @var int - */ - public $Limit = 0; + public int $Limit = 0; - /** - * @var string - */ - public $Search = ''; + public string $Search = ''; - /** - * @var int - */ - public $ThreadUid = 0; + public int $ThreadUid = 0; // MailSo\Imap\FolderInformation public $FolderInfo = null; - /** - * @var array - */ - public $NewMessages = array(); + public array $NewMessages = array(); - /** - * @var bool - */ - public $Filtered = false; + public bool $Filtered = false; public function append($oMessage, bool $bToTop = false) : void {