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 c7dff93 commit 33cc44d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 89 deletions.
50 changes: 0 additions & 50 deletions tests/Integration/Framework/Caching.php

This file was deleted.

47 changes: 8 additions & 39 deletions tests/Integration/MailboxSynchronizationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,15 @@

use Horde_Imap_Client;
use Horde_Imap_Client_Socket;
use OC\Memcache\Redis;
use OCA\Mail\Account;
use OCA\Mail\Contracts\IMailManager;
use OCA\Mail\Controller\MailboxesController;
use OCA\Mail\Db\MailboxMapper;
use OCA\Mail\Db\MessageMapper as DbMessageMapper;
use OCA\Mail\IMAP\MessageMapper as ImapMessageMapper;
use OCA\Mail\IMAP\Sync\Synchronizer;
use OCA\Mail\Service\AccountService;
use OCA\Mail\Service\Sync\ImapToDbSynchronizer;
use OCA\Mail\Service\Sync\SyncService;
use OCA\Mail\Support\PerformanceLogger;
use OCA\Mail\Tests\Integration\Framework\Caching;
use OCA\Mail\Tests\Integration\Framework\ImapTest;
use OCA\Mail\Tests\Integration\Framework\ImapTestAccount;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\IConfig;
use OCP\IRequest;
use OCP\Server;
use Psr\Log\LoggerInterface;
Expand Down Expand Up @@ -233,20 +225,6 @@ public function testSyncVanishedMessage() {
}

public function testUnsolicitedVanishedMessage() {
$config = Server::get(IConfig::class);
$cacheClass = $config->getSystemValueString('memcache.distributed');
if (ltrim($cacheClass, '\\') !== Redis::class) {
$this->markTestSkipped('Redis not available. Found ' . $cacheClass);
}

[$imapClientFactory, $cacheFactory] = Caching::getImapClientFactoryAndConfiguredCacheFactory();

// Just to be sure ...
$cache = $cacheFactory->createDistributed();
$this->assertInstanceOf(Redis::class, $cache);

$cache->clear();

$mailbox = 'INBOX';
$message = $this->getMessageBuilder()
->from('ralph@[email protected]')
Expand Down Expand Up @@ -282,36 +260,27 @@ public function testUnsolicitedVanishedMessage() {
);

// Trigger partial sync to warm the cache.
// Construct a new ImapToDbSynchronizer from scratch to prevent getting a cached instance
// without the proper ICacheFactory that still builds instances of ArrayCache despite Redis
// being configured.
$dbMessageMapper = Server::get(DbMessageMapper::class);
$logger = Server::get(LoggerInterface::class);
$synchronizer = new ImapToDbSynchronizer(
$dbMessageMapper,
$imapClientFactory,
Server::get(ImapMessageMapper::class),
Server::get(MailboxMapper::class),
Server::get(Synchronizer::class),
Server::get(IEventDispatcher::class),
Server::get(PerformanceLogger::class),
$logger,
Server::get(IMailManager::class),
$synchronizer = Server::get(ImapToDbSynchronizer::class);
$synchronizer->syncAccount(
new Account($this->account),
Server::get(LoggerInterface::class),
);
$synchronizer->syncAccount(new Account($this->account), $logger);

// Assert that there are 2 messages and nothing changes when deleting a message externally
$dbMessageMapper = Server::get(DbMessageMapper::class);
self::assertCount(2, $dbMessageMapper->findAllUids($inbox));
$this->deleteMessagesExternally($mailbox, [$uid1]);
self::assertCount(2, $dbMessageMapper->findAllUids($inbox));

// Receive unsolicited vanished uid
$client = $this->getClient($this->account);
$mailManager->getSource(
$imapClientFactory->getClient(new Account($this->account)),
$client,
new Account($this->account),
$mailbox,
$uid2,
);
$client->logout();

// Assert that the unsolicited change was synced to the db
self::assertCount(1, $dbMessageMapper->findAllUids($inbox));
Expand Down

0 comments on commit 33cc44d

Please sign in to comment.