-
Notifications
You must be signed in to change notification settings - Fork 259
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #10036 from nextcloud/fix/imap/persist-deleted-mes…
…sages fix(imap): persist vanished messages immediately on EXAMINE commands
- Loading branch information
Showing
10 changed files
with
326 additions
and
469 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/** | ||
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors | ||
* SPDX-License-Identifier: AGPL-3.0-or-later | ||
*/ | ||
|
||
namespace OCA\Mail\Cache; | ||
|
||
class CachedMailbox { | ||
/** @var int[]|null */ | ||
private ?array $uids = null; | ||
|
||
private ?int $uidValidity = null; | ||
private ?int $highestModSeq = null; | ||
|
||
/** | ||
* @return int[]|null | ||
*/ | ||
public function getUids(): ?array { | ||
return $this->uids; | ||
} | ||
|
||
/** | ||
* @param int[]|null $uids | ||
*/ | ||
public function setUids(?array $uids): void { | ||
$this->uids = $uids; | ||
} | ||
|
||
public function getUidValidity(): ?int { | ||
return $this->uidValidity; | ||
} | ||
|
||
public function setUidValidity(?int $uidvalid): void { | ||
$this->uidValidity = $uidvalid; | ||
} | ||
|
||
public function getHighestModSeq(): ?int { | ||
return $this->highestModSeq; | ||
} | ||
|
||
public function setHighestModSeq(?int $highestModSeq): void { | ||
$this->highestModSeq = $highestModSeq; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/** | ||
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors | ||
* SPDX-License-Identifier: AGPL-3.0-or-later | ||
*/ | ||
|
||
namespace OCA\Mail\Cache; | ||
|
||
use OCA\Mail\Account; | ||
use OCA\Mail\Db\MailboxMapper; | ||
use OCA\Mail\Db\MessageMapper; | ||
|
||
class HordeCacheFactory { | ||
public function __construct( | ||
private MailboxMapper $mailboxMapper, | ||
private MessageMapper $messageMapper, | ||
private HordeSyncTokenParser $syncTokenParser, | ||
) { | ||
} | ||
|
||
public function newCache(Account $account): Cache { | ||
return new Cache( | ||
$this->messageMapper, | ||
$this->mailboxMapper, | ||
$this->syncTokenParser, | ||
$account, | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/** | ||
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors | ||
* SPDX-License-Identifier: AGPL-3.0-or-later | ||
*/ | ||
|
||
namespace OCA\Mail\Cache; | ||
|
||
class HordeSyncToken { | ||
public function __construct( | ||
private ?int $nextUid, | ||
private ?int $uidValidity, | ||
private ?int $highestModSeq, | ||
) { | ||
} | ||
|
||
public function getNextUid(): ?int { | ||
return $this->nextUid; | ||
} | ||
|
||
public function getUidValidity(): ?int { | ||
return $this->uidValidity; | ||
} | ||
|
||
public function getHighestModSeq(): ?int { | ||
return $this->highestModSeq; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/** | ||
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors | ||
* SPDX-License-Identifier: AGPL-3.0-or-later | ||
*/ | ||
|
||
namespace OCA\Mail\Cache; | ||
|
||
class HordeSyncTokenParser { | ||
public function parseSyncToken(string $token): HordeSyncToken { | ||
$decodedToken = base64_decode($token, true); | ||
$parts = explode(',', $decodedToken); | ||
|
||
$nextUid = null; | ||
$uidValidity = null; | ||
$highestModSeq = null; | ||
foreach ($parts as $part) { | ||
if (str_starts_with($part, 'U')) { | ||
$nextUid = (int)substr($part, 1); | ||
} | ||
|
||
if (str_starts_with($part, 'V')) { | ||
$uidValidity = (int)substr($part, 1); | ||
} | ||
|
||
if (str_starts_with($part, 'H')) { | ||
$highestModSeq = (int)substr($part, 1); | ||
} | ||
} | ||
|
||
return new HordeSyncToken($nextUid, $uidValidity, $highestModSeq); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -211,6 +211,31 @@ public function deleteMessage($mailbox, $id, ?MailAccount $account = null) { | |
} | ||
} | ||
|
||
/** | ||
* Delete a message without informing Horde or the db cache. This simulates another client | ||
* deleting a message on IMAP. | ||
* | ||
* @param int[] $uids | ||
*/ | ||
public function deleteMessagesExternally(string $mailbox, array $uids): void { | ||
$client = new Horde_Imap_Client_Socket([ | ||
'username' => '[email protected]', | ||
'password' => 'mypassword', | ||
'hostspec' => '127.0.0.1', | ||
'port' => 993, | ||
'secure' => 'ssl', | ||
]); | ||
$ids = new Horde_Imap_Client_Ids($uids); | ||
try { | ||
$client->expunge($mailbox, [ | ||
'ids' => $ids, | ||
'delete' => true, | ||
]); | ||
} finally { | ||
$client->logout(); | ||
} | ||
} | ||
|
||
/** | ||
* @param Horde_Imap_Client_Socket $client | ||
* @param string $mailbox | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.