From 206c8abdf5ca7ca136c77ce600bddd469ba74566 Mon Sep 17 00:00:00 2001 From: the-djmaze <> Date: Mon, 6 Mar 2023 13:21:21 +0100 Subject: [PATCH] More changes for #1003 --- .../app/libraries/MailSo/Mail/Message.php | 34 +++++++++++++------ .../libraries/RainLoop/Actions/Messages.php | 12 +++---- 2 files changed, 29 insertions(+), 17 deletions(-) diff --git a/snappymail/v/0.0.0/app/libraries/MailSo/Mail/Message.php b/snappymail/v/0.0.0/app/libraries/MailSo/Mail/Message.php index 980431b0f..622a273e2 100644 --- a/snappymail/v/0.0.0/app/libraries/MailSo/Mail/Message.php +++ b/snappymail/v/0.0.0/app/libraries/MailSo/Mail/Message.php @@ -465,6 +465,29 @@ class Message implements \JsonSerializable return $oMessage; } + public function ETag(string $sClientHash) : string + { + return \md5('MessageHash/' . \implode('/', [ + $this->sFolder, + $this->Uid, + \implode(',', $this->getFlags()), +// \implode(',', $this->aThreads), + $sClientHash + ])); + } + + // https://datatracker.ietf.org/doc/html/rfc5788#section-3.4.1 + // Thunderbird $label1 is same as $Important? + // Thunderbird $label4 is same as $todo? + protected function getFlags() : array + { + return \array_unique(\str_replace( + ['$readreceipt', '$replied', /* 'junk', 'nonjunk', '$queued', '$sent', 'sent'*/], + ['$mdnsent', '\\answered',/* '$junk', '$notjunk', '$submitpending', '$submitted', '$submitted'*/], + $this->aFlagsLowerCase + )); + } + #[\ReturnTypeWillChange] public function jsonSerialize() { @@ -476,15 +499,6 @@ class Message implements \JsonSerializable $this->aFlagsLowerCase ), true); */ - // https://datatracker.ietf.org/doc/html/rfc5788#section-3.4.1 - // Thunderbird $label1 is same as $Important? - // Thunderbird $label4 is same as $todo? - $aFlags = \array_unique(\str_replace( - ['$readreceipt', '$replied', /* 'junk', 'nonjunk', '$queued', '$sent', 'sent'*/], - ['$mdnsent', '\\answered',/* '$junk', '$notjunk', '$submitpending', '$submitted', '$submitted'*/], - $this->aFlagsLowerCase - )); - $aAutocrypt = []; if ($this->sAutocrypt) { foreach (\explode(';', $this->sAutocrypt) as $entry) { @@ -527,7 +541,7 @@ class Message implements \JsonSerializable 'dkim' => $this->DKIM, 'dmarc' => $this->DMARC, - 'flags' => $aFlags, + 'flags' => $this->getFlags(), 'inReplyTo' => $this->InReplyTo, 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 ec837ebef..0c54b57a0 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 @@ -406,15 +406,12 @@ trait Messages { $sRawKey = (string) $this->GetActionParam('RawKey', ''); - $sFolder = ''; - $iUid = 0; - $aValues = \json_decode(\MailSo\Base\Utils::UrlSafeBase64Decode($sRawKey), true); if ($aValues && 2 <= \count($aValues)) { $sFolder = (string) $aValues[0]; $iUid = (int) $aValues[1]; - - $this->verifyCacheByKey($sRawKey); +// $useThreads = !empty($aValues[2]); +// $accountHash = $aValues[3]; } else { $sFolder = $this->GetActionParam('folder', ''); $iUid = (int) $this->GetActionParam('uid', 0); @@ -432,9 +429,10 @@ trait Messages } if ($oMessage) { + $ETag = $oMessage->ETag($this->ImapClient()->Hash()); + $this->verifyCacheByKey($ETag); $this->Plugins()->RunHook('filter.result-message', array($oMessage)); - - $this->cacheByKey($sRawKey); + $this->cacheByKey($ETag); } return $this->DefaultResponse($oMessage);