Skip to content

Commit

Permalink
fixup! fix(imap): persist vanished messages immediately on EXAMINE co…
Browse files Browse the repository at this point in the history
…mmands
  • Loading branch information
st3iny committed Sep 11, 2024
1 parent 93d8530 commit c7dff93
Showing 1 changed file with 17 additions and 46 deletions.
63 changes: 17 additions & 46 deletions lib/Cache/Cache.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -107,61 +109,30 @@ 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) {
unset($this->cachedMailboxes[$mailbox]);
}

public function clear($lifetime) {
// Clear all data cached in memory to trigger a refetch from the db on the next access
$this->cachedMailboxes = [];
}
}

0 comments on commit c7dff93

Please sign in to comment.