From 59b3fe70b6674df3e6b7504bc01c766b2185b7dc Mon Sep 17 00:00:00 2001 From: the-djmaze <> Date: Mon, 13 Mar 2023 09:56:35 +0100 Subject: [PATCH] Improved mailbox ETag --- .../MailSo/Imap/Commands/Folders.php | 4 ++++ .../app/libraries/MailSo/Imap/Folder.php | 22 ++++-------------- .../MailSo/Imap/FolderInformation.php | 9 +------- .../libraries/MailSo/Imap/Traits/Status.php | 23 ++++++++++--------- .../app/libraries/MailSo/Mail/MailClient.php | 8 +++---- .../libraries/RainLoop/Actions/Messages.php | 2 +- .../libraries/RainLoop/Actions/Response.php | 5 ---- 7 files changed, 26 insertions(+), 47 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 1ac4e35e4..29490f17b 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 @@ -214,9 +214,11 @@ trait Folders // $oFolderInfo->SIZE = \max($oFolderInfo->SIZE, $oInfo->SIZE); // $oFolderInfo->RECENT = \max(0, $oFolderInfo->RECENT, $oInfo->RECENT); $oFolderInfo->hasStatus = $oInfo->hasStatus; + $oFolderInfo->generateETag($this); return $oFolderInfo; } + $oInfo->generateETag($this); return $oInfo; } @@ -436,6 +438,7 @@ trait Folders } */ $this->oCurrentFolderInfo = $oResult; + $oResult->generateETag($this); return $oResult; } @@ -516,6 +519,7 @@ trait Folders $oFolderCollection[$sFullName] = new Folder($sFullName); } $oFolderCollection[$sFullName]->setStatusFromResponse($oResponse); + $oFolderCollection[$sFullName]->generateETag($this); } else if ($sCmd === $oResponse->StatusOrIndex && 5 === \count($oResponse->ResponseList)) { try diff --git a/snappymail/v/0.0.0/app/libraries/MailSo/Imap/Folder.php b/snappymail/v/0.0.0/app/libraries/MailSo/Imap/Folder.php index 97a40e27c..c0b42ac8d 100644 --- a/snappymail/v/0.0.0/app/libraries/MailSo/Imap/Folder.php +++ b/snappymail/v/0.0.0/app/libraries/MailSo/Imap/Folder.php @@ -148,32 +148,16 @@ class Folder implements \JsonSerializable return $role ? \ltrim($role, '\\') : null; } - public function ETag(string $sClientHash) : ?string - { - return $this->Selectable() ? $this->getETag($sClientHash) : null; - } - #[\ReturnTypeWillChange] public function jsonSerialize() { -/* - $aExtended = null; - if (isset($this->MESSAGES, $this->UNSEEN, $this->UIDNEXT)) { - $aExtended = array( - 'totalEmails' => (int) $this->MESSAGES, - 'unreadEmails' => (int) $this->UNSEEN, - 'uidNext' => (int) $this->UIDNEXT, -// 'etag' => $this->ETag($this->getAccountFromToken()->IncLogin()) - ); - } -*/ /* if ($this->ImapClient->hasCapability('ACL') || $this->ImapClient->CapabilityValue('RIGHTS')) { // MailSo\Imap\Responses\ACL $rights = $this->ImapClient->FolderMyRights($this->FullName); } */ - return array( + $result = array( '@Object' => 'Object/Folder', 'name' => $this->Name(), 'fullName' => $this->FullName, @@ -202,5 +186,9 @@ class Folder implements \JsonSerializable ] */ ); + if ($this->etag) { + $result['etag'] = $this->etag; + } + return $result; } } 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 5104487df..a8073ea29 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 @@ -19,8 +19,6 @@ class FolderInformation implements \JsonSerializable { use Traits\Status; - public string $etag = ''; - public bool $IsWritable; /** @@ -39,11 +37,6 @@ class FolderInformation implements \JsonSerializable $this->IsWritable = $bIsWritable; } - public function generateETag(ImapClient $oImapClient) : void - { - $this->etag = $this->getETag($oImapClient->Hash()); - } - public function IsFlagSupported(string $sFlag) : bool { return \in_array('\\*', $this->PermanentFlags) || @@ -75,7 +68,7 @@ class FolderInformation implements \JsonSerializable if (isset($this->SIZE)) { $result['size'] = $this->SIZE; } - if (isset($this->etag)) { + if ($this->etag) { $result['etag'] = $this->etag; } return $result; diff --git a/snappymail/v/0.0.0/app/libraries/MailSo/Imap/Traits/Status.php b/snappymail/v/0.0.0/app/libraries/MailSo/Imap/Traits/Status.php index 1058e5589..f8aa2e550 100644 --- a/snappymail/v/0.0.0/app/libraries/MailSo/Imap/Traits/Status.php +++ b/snappymail/v/0.0.0/app/libraries/MailSo/Imap/Traits/Status.php @@ -87,24 +87,25 @@ trait Status */ public ?int $SIZE = null; - public function getETag(string $sClientHash) : ?string + public ?string $etag = null; + public function generateETag(\MailSo\Imap\ImapClient $oImapClient) : void { if (!$this->hasStatus) { // UNSEEN undefined when only SELECT/EXAMINE is used \error_log("STATUS missing " . \print_r($this,true)); - return null; + return; } if (!isset($this->MESSAGES, $this->UIDNEXT)) { - return null; + return; } - return \md5('FolderHash/'. \implode('-', [ - $this->FullName, - $this->MESSAGES, - $this->UIDNEXT, - $this->UIDVALIDITY, - $this->UNSEEN, - $this->HIGHESTMODSEQ, - $sClientHash + $this->etag = \md5('FolderHash/'. \implode('-', [ + $this->FullName, + $this->MESSAGES, + $this->UIDNEXT, + $this->UIDVALIDITY, + $this->UNSEEN, + $this->HIGHESTMODSEQ, + $oImapClient->Hash() ])); } 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 85f862959..1792b0c98 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 @@ -361,7 +361,7 @@ class MailClient 'mailboxId' => $oInfo->MAILBOXID ?: '', // 'flags' => $oInfo->Flags, // 'permanentFlags' => $oInfo->PermanentFlags, - 'etag' => $oInfo->getETag($this->oImapClient->Hash()), + 'etag' => $oInfo->etag, 'messagesFlags' => $aFlags, 'newMessages' => $this->getFolderNextMessageInformation( $sFolderName, @@ -379,8 +379,8 @@ class MailClient */ public function FolderHash(string $sFolderName) : string { - return $this->oImapClient->FolderStatus($sFolderName)->getETag($this->oImapClient->Hash()); -// return $this->oImapClient->FolderStatusAndSelect($sFolderName)->getETag($this->oImapClient->Hash()); + return $this->oImapClient->FolderStatus($sFolderName)->etag; +// return $this->oImapClient->FolderStatusAndSelect($sFolderName)->etag; } /** @@ -654,8 +654,6 @@ class MailClient throw new \InvalidArgumentException('THREAD not supported'); } - $oInfo->generateETag($this->oImapClient); - if (!$oParams->iThreadUid) { $oMessageCollection->NewMessages = $this->getFolderNextMessageInformation( $oParams->sFolderName, $oParams->iPrevUidNext, $oInfo->UIDNEXT diff --git a/snappymail/v/0.0.0/app/libraries/RainLoop/Actions/Messages.php b/snappymail/v/0.0.0/app/libraries/RainLoop/Actions/Messages.php index fe6a4eb63..324565321 100644 --- a/snappymail/v/0.0.0/app/libraries/RainLoop/Actions/Messages.php +++ b/snappymail/v/0.0.0/app/libraries/RainLoop/Actions/Messages.php @@ -65,7 +65,7 @@ trait Messages // $oInfo = $this->MailClient()->FolderHash($oParams->sFolderName); $oInfo = $this->ImapClient()->FolderStatusAndSelect($oParams->sFolderName); $aRequestHash = \explode('-', $sHash); - $sFolderHash = $oInfo->getETag($this->getAccountFromToken()->IncLogin()); + $sFolderHash = $oInfo->etag; $sHash = $oParams->hash() . '-' . $sFolderHash; if ($aRequestHash[1] == $sFolderHash) { $this->verifyCacheByKey($sHash); diff --git a/snappymail/v/0.0.0/app/libraries/RainLoop/Actions/Response.php b/snappymail/v/0.0.0/app/libraries/RainLoop/Actions/Response.php index 4522e235e..e0559c41f 100644 --- a/snappymail/v/0.0.0/app/libraries/RainLoop/Actions/Response.php +++ b/snappymail/v/0.0.0/app/libraries/RainLoop/Actions/Response.php @@ -142,11 +142,6 @@ trait Response if ($mResponse instanceof \MailSo\Imap\Folder) { $aResult = $mResponse->jsonSerialize(); - $sHash = $mResponse->ETag($this->getAccountFromToken()->IncLogin()); - if ($sHash) { - $aResult['etag'] = $sHash; - } - if (null === $this->aCheckableFolder) { $aCheckable = \json_decode( $this->SettingsProvider(true)