-
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.
fix(imap): persist vanished messages immediately on EXAMINE commands
Signed-off-by: Richard Steinmetz <[email protected]>
- Loading branch information
Showing
6 changed files
with
270 additions
and
45 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -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; | ||
use OCP\ICache; | ||
|
||
class CacheFactory { | ||
public function __construct( | ||
private MailboxMapper $mailboxMapper, | ||
private MessageMapper $messageMapper, | ||
) { | ||
} | ||
|
||
public function newCache(Account $account, ICache $cache): Cache { | ||
return new Cache( | ||
$this->messageMapper, | ||
$this->mailboxMapper, | ||
$account, | ||
$cache, | ||
); | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,50 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/** | ||
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors | ||
* SPDX-License-Identifier: AGPL-3.0-or-later | ||
*/ | ||
|
||
namespace OCA\Mail\Tests\Integration\Framework; | ||
|
||
use OC\Memcache\Factory; | ||
use OCA\Mail\Cache\CacheFactory; | ||
use OCA\Mail\IMAP\IMAPClientFactory; | ||
use OCP\AppFramework\Utility\ITimeFactory; | ||
use OCP\EventDispatcher\IEventDispatcher; | ||
use OCP\IConfig; | ||
use OCP\Profiler\IProfiler; | ||
use OCP\Security\ICrypto; | ||
use OCP\Server; | ||
use Psr\Log\LoggerInterface; | ||
|
||
class Caching { | ||
/** | ||
* Force usage of a real cache as configured in system config. The original ICacheFactory | ||
* service closure is hard-coded to always return an instance of ArrayCache when the global | ||
* PHPUNIT_RUN is defined. | ||
*/ | ||
public static function getImapClientFactoryAndConfiguredCacheFactory(?ICrypto $crypto = null): array { | ||
$config = Server::get(IConfig::class); | ||
$cacheFactory = new Factory( | ||
'mail-integration-tests', | ||
Server::get(LoggerInterface::class), | ||
Server::get(IProfiler::class), | ||
$config->getSystemValue('memcache.local', null), | ||
$config->getSystemValue('memcache.distributed', null), | ||
$config->getSystemValue('memcache.locking', null), | ||
$config->getSystemValueString('redis_log_file') | ||
); | ||
$imapClient = new IMAPClientFactory( | ||
$crypto ?? Server::get(ICrypto::class), | ||
$config, | ||
$cacheFactory, | ||
Server::get(IEventDispatcher::class), | ||
Server::get(ITimeFactory::class), | ||
Server::get(CacheFactory::class), | ||
); | ||
return [$imapClient, $cacheFactory]; | ||
} | ||
} |
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 | ||
|
Oops, something went wrong.