From c7dff9341d808bfcd8e5ef32944517865ed60388 Mon Sep 17 00:00:00 2001 From: Richard Steinmetz Date: Wed, 11 Sep 2024 21:10:52 +0200 Subject: [PATCH] fixup! fix(imap): persist vanished messages immediately on EXAMINE commands --- lib/Cache/Cache.php | 63 ++++++++++++--------------------------------- 1 file changed, 17 insertions(+), 46 deletions(-) diff --git a/lib/Cache/Cache.php b/lib/Cache/Cache.php index e4cc808b1d..08bad94848 100644 --- a/lib/Cache/Cache.php +++ b/lib/Cache/Cache.php @@ -59,13 +59,15 @@ public function getCachedUids($mailbox, $uidvalid) { } // Refresh cached uids lazily - if ($cachedMailbox->getUids() === null) { + $cachedUids = $cachedMailbox->getUids(); + if ($cachedUids === null) { $mailboxEntity = $this->mailboxMapper->find($this->account, $mailbox); - $cachedMailbox->setUids($this->dbMessageMapper->findAllUids($mailboxEntity)); + $cachedUids = $this->dbMessageMapper->findAllUids($mailboxEntity); + $cachedMailbox->setUids($cachedUids); } - // Copy the array as we don't know whether horde will mutate it - return array_merge([], $cachedMailbox->getUids()); + // Copy the array because we don't know whether horde will mutate it + return array_merge([], $cachedUids); } public function set($mailbox, $data, $uidvalid) { @@ -107,53 +109,23 @@ public function getMetaData($mailbox, $uidvalid, $entries) { public function setMetaData($mailbox, $data) { // Don't mutate any metadata. // The data will be refreshed once the new sync token is written to the db. - - /* - $knownUidvalid = null; - $knownHighestmodseq = null; - - if (isset($this->uidvalid[$mailbox])) { - $knownUidvalid = $this->uidvalid[$mailbox]; - } - if (isset($this->highestmodseq[$mailbox])) { - $knownHighestmodseq = $this->highestmodseq[$mailbox]; - } - - $uidvalid = null; - if (isset($data['uidvalid'])) { - $uidvalid = (int)$data['uidvalid']; - } - - if ($knownUidvalid === null && $uidvalid !== null) { - $this->uidvalid[$mailbox] = $uidvalid; - } elseif ($knownUidvalid !== null && $uidvalid !== null && $knownUidvalid !== $uidvalid) { - $this->deleteMailbox($mailbox); - $this->uidvalid[$mailbox] = $uidvalid; - //unset($this->cachedUids[$mailbox]); - } - - if (isset($data['_m'])) { - var_dump('New _m', $data['_m']); - $this->highestmodseq[$mailbox] = (int)$data['_m']; - } - - $data2 = array_merge([], $data); - unset($data2['uidvalid'], $data2['_m']); - if (!isset($this->cache[$mailbox])) { - $this->cache[$mailbox] = []; - } - foreach ($data2 as $key => $value) { - $this->cache[$mailbox][$key] = $value; - } - */ } public function deleteMsgs($mailbox, $uids) { $mailboxEntity = $this->mailboxMapper->find($this->account, $mailbox); $this->dbMessageMapper->deleteByUid($mailboxEntity, ...$uids); - if (isset($this->cachedUids[$mailbox])) { - $this->cachedUids[$mailbox] = array_diff($this->cachedUids[$mailbox], $uids); + + if (!isset($this->cachedMailboxes[$mailbox])) { + return; + } + + $cachedMailbox = $this->cachedMailboxes[$mailbox]; + $cachedUids = $cachedMailbox->getUids(); + if ($cachedUids === null) { + return; } + + $cachedMailbox->setUids(array_diff($cachedUids, $uids)); } public function deleteMailbox($mailbox) { @@ -161,7 +133,6 @@ public function deleteMailbox($mailbox) { } public function clear($lifetime) { - // Clear all data cached in memory to trigger a refetch from the db on the next access $this->cachedMailboxes = []; } }