diff --git a/lib/BackgroundJob/MigrateImportantJob.php b/lib/BackgroundJob/MigrateImportantJob.php index e9b0724d80..7b2d1f0a46 100644 --- a/lib/BackgroundJob/MigrateImportantJob.php +++ b/lib/BackgroundJob/MigrateImportantJob.php @@ -33,6 +33,7 @@ use OCA\Mail\Db\MailboxMapper; use OCA\Mail\Exception\ServiceException; +use OCA\Mail\IMAP\IMAPClientFactory; use OCA\Mail\Migration\MigrateImportantFromImapAndDb; use OCA\Mail\Service\MailManager; use OCP\AppFramework\Db\DoesNotExistException; @@ -57,12 +58,16 @@ class MigrateImportantJob extends QueuedJob { /** @var LoggerInterface */ private $logger; + /** @var IMAPClientFactory */ + private $imapClientFactory; + public function __construct(MailboxMapper $mailboxMapper, MailAccountMapper $mailAccountMapper, MailManager $mailManager, MigrateImportantFromImapAndDb $migration, LoggerInterface $logger, - ITimeFactory $timeFactory + ITimeFactory $timeFactory, + IMAPClientFactory $imapClientFactory ) { parent::__construct($timeFactory); $this->mailboxMapper = $mailboxMapper; @@ -70,6 +75,7 @@ public function __construct(MailboxMapper $mailboxMapper, $this->mailManager = $mailManager; $this->migration = $migration; $this->logger = $logger; + $this->imapClientFactory = $imapClientFactory; } /** @@ -96,21 +102,27 @@ public function run($argument) { } $account = new Account($mailAccount); - if ($this->mailManager->isPermflagsEnabled($account, $mailbox->getName()) === false) { - $this->logger->debug('Permflags not enabled for <' . $accountId . '>'); - return; - } - - try { - $this->migration->migrateImportantOnImap($account, $mailbox); - } catch (ServiceException $e) { - $this->logger->debug('Could not flag messages on IMAP for mailbox <' . $mailboxId . '>.'); - } + $client = $this->imapClientFactory->getClient($account); try { - $this->migration->migrateImportantFromDb($account, $mailbox); - } catch (ServiceException $e) { - $this->logger->debug('Could not flag messages from DB on IMAP for mailbox <' . $mailboxId . '>.'); + if ($this->mailManager->isPermflagsEnabled($client, $account, $mailbox->getName()) === false) { + $this->logger->debug('Permflags not enabled for <' . $accountId . '>'); + return; + } + + try { + $this->migration->migrateImportantOnImap($client, $account, $mailbox); + } catch (ServiceException $e) { + $this->logger->debug('Could not flag messages on IMAP for mailbox <' . $mailboxId . '>.'); + } + + try { + $this->migration->migrateImportantFromDb($client, $account, $mailbox); + } catch (ServiceException $e) { + $this->logger->debug('Could not flag messages from DB on IMAP for mailbox <' . $mailboxId . '>.'); + } + } finally { + $client->logout(); } } } diff --git a/lib/Contracts/IMailManager.php b/lib/Contracts/IMailManager.php index 72246d6667..e41ec110ed 100644 --- a/lib/Contracts/IMailManager.php +++ b/lib/Contracts/IMailManager.php @@ -23,6 +23,7 @@ namespace OCA\Mail\Contracts; +use Horde_Imap_Client_Socket; use OCA\Mail\Account; use OCA\Mail\Db\Mailbox; use OCA\Mail\Db\Message; @@ -248,7 +249,7 @@ public function getTagByImapLabel(string $imapLabel, string $userId): Tag; * @param string $mailbox * @return boolean */ - public function isPermflagsEnabled(Account $account, string $mailbox): bool; + public function isPermflagsEnabled(Horde_Imap_Client_Socket $client, Account $account, string $mailbox): bool; /** * Create a mail tag diff --git a/lib/Migration/MigrateImportantFromImapAndDb.php b/lib/Migration/MigrateImportantFromImapAndDb.php index f6e693d5fc..6cf9df4f91 100644 --- a/lib/Migration/MigrateImportantFromImapAndDb.php +++ b/lib/Migration/MigrateImportantFromImapAndDb.php @@ -29,6 +29,7 @@ namespace OCA\Mail\Migration; use Horde_Imap_Client_Exception; +use Horde_Imap_Client_Socket; use OCA\Mail\Account; use OCA\Mail\Db\Mailbox; use OCA\Mail\Db\MailboxMapper; @@ -52,55 +53,42 @@ class MigrateImportantFromImapAndDb { /** @var LoggerInterface */ private $logger; - public function __construct(IMAPClientFactory $clientFactory, - MessageMapper $messageMapper, + public function __construct(MessageMapper $messageMapper, MailboxMapper $mailboxMapper, LoggerInterface $logger ) { - $this->clientFactory = $clientFactory; $this->messageMapper = $messageMapper; $this->mailboxMapper = $mailboxMapper; $this->logger = $logger; } - public function migrateImportantOnImap(Account $account, Mailbox $mailbox): void { - $client = $this->clientFactory->getClient($account); + public function migrateImportantOnImap(Horde_Imap_Client_Socket $client, Account $account, Mailbox $mailbox): void { try { - //get all messages that have an $important label from IMAP + $uids = $this->messageMapper->getFlagged($client, $mailbox, '$important'); + } catch (Horde_Imap_Client_Exception $e) { + throw new ServiceException("Could not fetch UIDs of important messages: " . $e->getMessage(), 0, $e); + } + // add $label1 for all that are tagged on IMAP + if (!empty($uids)) { try { - $uids = $this->messageMapper->getFlagged($client, $mailbox, '$important'); + $this->messageMapper->addFlag($client, $mailbox, $uids, Tag::LABEL_IMPORTANT); } catch (Horde_Imap_Client_Exception $e) { - throw new ServiceException("Could not fetch UIDs of important messages: " . $e->getMessage(), 0, $e); - } - // add $label1 for all that are tagged on IMAP - if (!empty($uids)) { - try { - $this->messageMapper->addFlag($client, $mailbox, $uids, Tag::LABEL_IMPORTANT); - } catch (Horde_Imap_Client_Exception $e) { - $this->logger->debug('Could not flag messages in mailbox <' . $mailbox->getId() . '>'); - throw new ServiceException($e->getMessage(), 0, $e); - } + $this->logger->debug('Could not flag messages in mailbox <' . $mailbox->getId() . '>'); + throw new ServiceException($e->getMessage(), 0, $e); } - } finally { - $client->logout(); } } - public function migrateImportantFromDb(Account $account, Mailbox $mailbox): void { - $client = $this->clientFactory->getClient($account); - try { - $uids = $this->mailboxMapper->findFlaggedImportantUids($mailbox->getId()); - // store our data on imap - if (!empty($uids)) { - try { - $this->messageMapper->addFlag($client, $mailbox, $uids, Tag::LABEL_IMPORTANT); - } catch (Horde_Imap_Client_Exception $e) { - $this->logger->debug('Could not flag messages in mailbox <' . $mailbox->getId() . '>'); - throw new ServiceException($e->getMessage(), 0, $e); - } + public function migrateImportantFromDb(Horde_Imap_Client_Socket $client, Account $account, Mailbox $mailbox): void { + $uids = $this->mailboxMapper->findFlaggedImportantUids($mailbox->getId()); + // store our data on imap + if (!empty($uids)) { + try { + $this->messageMapper->addFlag($client, $mailbox, $uids, Tag::LABEL_IMPORTANT); + } catch (Horde_Imap_Client_Exception $e) { + $this->logger->debug('Could not flag messages in mailbox <' . $mailbox->getId() . '>'); + throw new ServiceException($e->getMessage(), 0, $e); } - } finally { - $client->logout(); } } } diff --git a/lib/Service/MailManager.php b/lib/Service/MailManager.php index c23ad5b4bd..a769013688 100644 --- a/lib/Service/MailManager.php +++ b/lib/Service/MailManager.php @@ -26,6 +26,7 @@ use Horde_Imap_Client; use Horde_Imap_Client_Exception; use Horde_Imap_Client_Exception_NoSupportExtension; +use Horde_Imap_Client_Socket; use OCA\Mail\Account; use OCA\Mail\Contracts\IMailManager; use OCA\Mail\Db\Mailbox; @@ -401,7 +402,7 @@ public function flagMessage(Account $account, string $mailbox, int $uid, string $client = $this->imapClientFactory->getClient($account); try { // Only send system flags to the IMAP server as other flags might not be supported - $imapFlags = $this->filterFlags($account, $flag, $mailbox); + $imapFlags = $this->filterFlags($client, $account, $flag, $mailbox); foreach ($imapFlags as $imapFlag) { if (empty($imapFlag) === true) { continue; @@ -456,8 +457,8 @@ public function tagMessage(Account $account, string $mailbox, Message $message, } catch (DoesNotExistException $e) { throw new ClientException("Mailbox $mailbox does not exist", 0, $e); } - if ($this->isPermflagsEnabled($account, $mailbox) === true) { - $client = $this->imapClientFactory->getClient($account); + $client = $this->imapClientFactory->getClient($account); + if ($this->isPermflagsEnabled($client, $account, $mailbox) === true) { try { if ($value) { // imap keywords and flags work the same way @@ -474,7 +475,10 @@ public function tagMessage(Account $account, string $mailbox, Message $message, } finally { $client->logout(); } + } else { + $client->logout(); } + if ($value) { $this->tagMapper->tagMessage($tag, $message->getMessageId(), $account->getUserId()); } else { @@ -617,7 +621,7 @@ public function getTagByImapLabel(string $imapLabel, string $userId): Tag { * @param string $mailbox * @return array */ - public function filterFlags(Account $account, string $flag, string $mailbox): array { + public function filterFlags(Horde_Imap_Client_Socket $client, Account $account, string $flag, string $mailbox): array { // check for RFC server flags if (array_key_exists($flag, self::ALLOWED_FLAGS) === true) { return self::ALLOWED_FLAGS[$flag]; @@ -625,7 +629,7 @@ public function filterFlags(Account $account, string $flag, string $mailbox): ar // Only allow flag setting if IMAP supports Permaflags // @TODO check if there are length & char limits on permflags - if ($this->isPermflagsEnabled($account, $mailbox) === true) { + if ($this->isPermflagsEnabled($client, $account, $mailbox) === true) { return [$flag]; } return []; @@ -638,8 +642,7 @@ public function filterFlags(Account $account, string $flag, string $mailbox): ar * @param string $mailbox * @return boolean */ - public function isPermflagsEnabled(Account $account, string $mailbox): bool { - $client = $this->imapClientFactory->getClient($account); + public function isPermflagsEnabled(Horde_Imap_Client_Socket $client, Account $account, string $mailbox): bool { try { $capabilities = $client->status($mailbox, Horde_Imap_Client::STATUS_PERMFLAGS); } catch (Horde_Imap_Client_Exception $e) { @@ -648,8 +651,6 @@ public function isPermflagsEnabled(Account $account, string $mailbox): bool { (int)$e->getCode(), $e ); - } finally { - $client->logout(); } return (is_array($capabilities) === true && array_key_exists('permflags', $capabilities) === true && in_array("\*", $capabilities['permflags'], true) === true); } diff --git a/lib/Service/Sync/ImapToDbSynchronizer.php b/lib/Service/Sync/ImapToDbSynchronizer.php index 15d0648ac4..c5e91a6d83 100644 --- a/lib/Service/Sync/ImapToDbSynchronizer.php +++ b/lib/Service/Sync/ImapToDbSynchronizer.php @@ -413,7 +413,7 @@ private function runPartialSync(Account $account, ); $perf->step('get changed messages via Horde'); - $permflagsEnabled = $this->mailManager->isPermflagsEnabled($account, $mailbox->getName()); + $permflagsEnabled = $this->mailManager->isPermflagsEnabled($client, $account, $mailbox->getName()); foreach (array_chunk($response->getChangedMessages(), 500) as $chunk) { $this->dbMapper->updateBulk($account, $permflagsEnabled, ...array_map(static function (IMAPMessage $imapMessage) use ($mailbox, $account) { diff --git a/tests/Integration/Migration/MigrateImportantFromImapAndDbTest.php b/tests/Integration/Migration/MigrateImportantFromImapAndDbTest.php index 548d63cefc..79a4937eda 100644 --- a/tests/Integration/Migration/MigrateImportantFromImapAndDbTest.php +++ b/tests/Integration/Migration/MigrateImportantFromImapAndDbTest.php @@ -38,10 +38,6 @@ use Psr\Log\LoggerInterface; class MigrateImportantFromImapAndDbTest extends TestCase { - - /** @var MockObject */ - private $clientFactory; - /** @var MockObject */ private $client; @@ -64,7 +60,6 @@ protected function setUp(): void { $this->mailboxMapper = $this->createMock(MailboxMapper::class); $this->logger = $this->createMock(LoggerInterface::class); $this->migration = new MigrateImportantFromImapAndDb( - $this->clientFactory, $this->messageMapper, $this->mailboxMapper, $this->logger @@ -77,10 +72,6 @@ public function testMigrateImportantOnImap() { $mailbox = $this->createMock(Mailbox::class); $uids = [1,2,3]; - $this->clientFactory->expects($this->once()) - ->method('getClient') - ->with($account) - ->willReturn($this->client); $this->messageMapper->expects($this->once()) ->method('getFlagged') ->with($this->client, $mailbox, '$important') @@ -91,7 +82,7 @@ public function testMigrateImportantOnImap() { $this->logger->expects($this->never()) ->method('debug'); - $this->migration->migrateImportantOnImap($account, $mailbox); + $this->migration->migrateImportantOnImap($this->client, $account, $mailbox); } public function testMigrateImportantOnImapNoUids() { @@ -99,10 +90,6 @@ public function testMigrateImportantOnImapNoUids() { $mailbox = $this->createMock(Mailbox::class); $uids = []; - $this->clientFactory->expects($this->once()) - ->method('getClient') - ->with($account) - ->willReturn($this->client); $this->messageMapper->expects($this->once()) ->method('getFlagged') ->with($this->client, $mailbox, '$important') @@ -112,7 +99,7 @@ public function testMigrateImportantOnImapNoUids() { $this->logger->expects($this->never()) ->method('debug'); - $this->migration->migrateImportantOnImap($account, $mailbox); + $this->migration->migrateImportantOnImap($this->client, $account, $mailbox); } public function testMigrateImportantOnImapExceptionGetFlagged() { @@ -120,10 +107,6 @@ public function testMigrateImportantOnImapExceptionGetFlagged() { $mailbox = $this->createMock(Mailbox::class); $e = new Horde_Imap_Client_Exception(''); - $this->clientFactory->expects($this->once()) - ->method('getClient') - ->with($account) - ->willReturn($this->client); $this->messageMapper->expects($this->once()) ->method('getFlagged') ->with($this->client, $mailbox, '$important') @@ -134,7 +117,7 @@ public function testMigrateImportantOnImapExceptionGetFlagged() { ->method('debug'); $this->expectException(ServiceException::class); - $this->migration->migrateImportantOnImap($account, $mailbox); + $this->migration->migrateImportantOnImap($this->client, $account, $mailbox); } public function testMigrateImportantOnImapExceptionOnFlag() { @@ -144,10 +127,6 @@ public function testMigrateImportantOnImapExceptionOnFlag() { $e = new Horde_Imap_Client_Exception(''); $uids = [1,2,3,4]; - $this->clientFactory->expects($this->once()) - ->method('getClient') - ->with($account) - ->willReturn($this->client); $this->messageMapper->expects($this->once()) ->method('getFlagged') ->with($this->client, $mailbox, '$important') @@ -161,7 +140,7 @@ public function testMigrateImportantOnImapExceptionOnFlag() { ->with('Could not flag messages in mailbox <' . $mailbox->getId() . '>'); $this->expectException(ServiceException::class); - $this->migration->migrateImportantOnImap($account, $mailbox); + $this->migration->migrateImportantOnImap($this->client, $account, $mailbox); } public function migrateImportantFromDb() { @@ -170,10 +149,6 @@ public function migrateImportantFromDb() { $mailbox->setId(1); $uids = [1,2,3]; - $this->clientFactory->expects($this->once()) - ->method('getClient') - ->with($account) - ->willReturn($this->client); $this->mailboxMapper->expects($this->once()) ->method('findFlaggedImportantUids') ->with($mailbox->getId()) @@ -184,7 +159,7 @@ public function migrateImportantFromDb() { $this->logger->expects($this->never()) ->method('debug'); - $this->migration->migrateImportantFromDb($account, $mailbox); + $this->migration->migrateImportantFromDb($this->client, $account, $mailbox); } public function testMigrateImportantFromDbNoUids() { @@ -193,10 +168,6 @@ public function testMigrateImportantFromDbNoUids() { $mailbox->setId(1); $uids = []; - $this->clientFactory->expects($this->once()) - ->method('getClient') - ->with($account) - ->willReturn($this->client); $this->mailboxMapper->expects($this->once()) ->method('findFlaggedImportantUids') ->with($mailbox->getId()) @@ -206,7 +177,7 @@ public function testMigrateImportantFromDbNoUids() { $this->logger->expects($this->never()) ->method('debug'); - $this->migration->migrateImportantFromDb($account, $mailbox); + $this->migration->migrateImportantFromDb($this->client, $account, $mailbox); } public function testMigrateImportantFromDbExceptionOnFlag() { @@ -217,10 +188,6 @@ public function testMigrateImportantFromDbExceptionOnFlag() { $e = new Horde_Imap_Client_Exception(''); $uids = [1,2,3]; - $this->clientFactory->expects($this->once()) - ->method('getClient') - ->with($account) - ->willReturn($this->client); $this->mailboxMapper->expects($this->once()) ->method('findFlaggedImportantUids') ->with($mailbox->getId()) @@ -234,6 +201,6 @@ public function testMigrateImportantFromDbExceptionOnFlag() { ->with('Could not flag messages in mailbox <' . $mailbox->getId() . '>'); $this->expectException(ServiceException::class); - $this->migration->migrateImportantFromDb($account, $mailbox); + $this->migration->migrateImportantFromDb($this->client, $account, $mailbox); } } diff --git a/tests/Unit/Migration/MigrateImportantFromImapAndDbTest.php b/tests/Unit/Migration/MigrateImportantFromImapAndDbTest.php index 58b799000a..7627c0bcbf 100644 --- a/tests/Unit/Migration/MigrateImportantFromImapAndDbTest.php +++ b/tests/Unit/Migration/MigrateImportantFromImapAndDbTest.php @@ -33,7 +33,6 @@ use OCA\Mail\IMAP\MessageMapper; use OCA\Mail\Db\Tag; use OCA\Mail\Exception\ServiceException; -use OCA\Mail\IMAP\IMAPClientFactory; use OCA\Mail\Migration\MigrateImportantFromImapAndDb; use Psr\Log\LoggerInterface; @@ -58,13 +57,11 @@ class MigrateImportantFromImapAndDbTest extends TestCase { private $migration; protected function setUp(): void { - $this->clientFactory = $this->createMock(IMAPClientFactory::class); $this->client = $this->createMock(Horde_Imap_Client_Socket::class); $this->messageMapper = $this->createMock(MessageMapper::class); $this->mailboxMapper = $this->createMock(MailboxMapper::class); $this->logger = $this->createMock(LoggerInterface::class); $this->migration = new MigrateImportantFromImapAndDb( - $this->clientFactory, $this->messageMapper, $this->mailboxMapper, $this->logger @@ -77,10 +74,6 @@ public function testMigrateImportantOnImap() { $mailbox = $this->createMock(Mailbox::class); $uids = [1,2,3]; - $this->clientFactory->expects($this->once()) - ->method('getClient') - ->with($account) - ->willReturn($this->client); $this->messageMapper->expects($this->once()) ->method('getFlagged') ->with($this->client, $mailbox, '$important') @@ -91,7 +84,7 @@ public function testMigrateImportantOnImap() { $this->logger->expects($this->never()) ->method('debug'); - $this->migration->migrateImportantOnImap($account, $mailbox); + $this->migration->migrateImportantOnImap($this->client, $account, $mailbox); } public function testMigrateImportantOnImapNoUids() { @@ -99,10 +92,6 @@ public function testMigrateImportantOnImapNoUids() { $mailbox = $this->createMock(Mailbox::class); $uids = []; - $this->clientFactory->expects($this->once()) - ->method('getClient') - ->with($account) - ->willReturn($this->client); $this->messageMapper->expects($this->once()) ->method('getFlagged') ->with($this->client, $mailbox, '$important') @@ -112,7 +101,7 @@ public function testMigrateImportantOnImapNoUids() { $this->logger->expects($this->never()) ->method('debug'); - $this->migration->migrateImportantOnImap($account, $mailbox); + $this->migration->migrateImportantOnImap($this->client, $account, $mailbox); } public function testMigrateImportantOnImapExceptionGetFlagged() { @@ -120,10 +109,6 @@ public function testMigrateImportantOnImapExceptionGetFlagged() { $mailbox = $this->createMock(Mailbox::class); $e = new Horde_Imap_Client_Exception(''); - $this->clientFactory->expects($this->once()) - ->method('getClient') - ->with($account) - ->willReturn($this->client); $this->messageMapper->expects($this->once()) ->method('getFlagged') ->with($this->client, $mailbox, '$important') @@ -134,7 +119,7 @@ public function testMigrateImportantOnImapExceptionGetFlagged() { ->method('debug'); $this->expectException(ServiceException::class); - $this->migration->migrateImportantOnImap($account, $mailbox); + $this->migration->migrateImportantOnImap($this->client, $account, $mailbox); } public function testMigrateImportantOnImapExceptionOnFlag() { @@ -144,10 +129,6 @@ public function testMigrateImportantOnImapExceptionOnFlag() { $e = new Horde_Imap_Client_Exception(''); $uids = [1,2,3]; - $this->clientFactory->expects($this->once()) - ->method('getClient') - ->with($account) - ->willReturn($this->client); $this->messageMapper->expects($this->once()) ->method('getFlagged') ->with($this->client, $mailbox, '$important') @@ -161,7 +142,7 @@ public function testMigrateImportantOnImapExceptionOnFlag() { ->with('Could not flag messages in mailbox <' . $mailbox->getId() . '>'); $this->expectException(ServiceException::class); - $this->migration->migrateImportantOnImap($account, $mailbox); + $this->migration->migrateImportantOnImap($this->client, $account, $mailbox); } public function migrateImportantFromDb() { @@ -170,10 +151,6 @@ public function migrateImportantFromDb() { $mailbox->setId(1); $uids = [1,2,3]; - $this->clientFactory->expects($this->once()) - ->method('getClient') - ->with($account) - ->willReturn($this->client); $this->mailboxMapper->expects($this->once()) ->method('findFlaggedImportantUids') ->with($mailbox->getId()) @@ -184,7 +161,7 @@ public function migrateImportantFromDb() { $this->logger->expects($this->never()) ->method('debug'); - $this->migration->migrateImportantFromDb($account, $mailbox); + $this->migration->migrateImportantFromDb($this->client, $account, $mailbox); } public function testMigrateImportantFromDbNoUids() { @@ -193,10 +170,6 @@ public function testMigrateImportantFromDbNoUids() { $mailbox->setId(1); $uids = []; - $this->clientFactory->expects($this->once()) - ->method('getClient') - ->with($account) - ->willReturn($this->client); $this->mailboxMapper->expects($this->once()) ->method('findFlaggedImportantUids') ->with($mailbox->getId()) @@ -206,7 +179,7 @@ public function testMigrateImportantFromDbNoUids() { $this->logger->expects($this->never()) ->method('debug'); - $this->migration->migrateImportantFromDb($account, $mailbox); + $this->migration->migrateImportantFromDb($this->client, $account, $mailbox); } public function testMigrateImportantFromDbExceptionOnFlag() { @@ -217,10 +190,6 @@ public function testMigrateImportantFromDbExceptionOnFlag() { $e = new Horde_Imap_Client_Exception(''); $uids = [1,2,3]; - $this->clientFactory->expects($this->once()) - ->method('getClient') - ->with($account) - ->willReturn($this->client); $this->mailboxMapper->expects($this->once()) ->method('findFlaggedImportantUids') ->with($mailbox->getId()) @@ -234,6 +203,6 @@ public function testMigrateImportantFromDbExceptionOnFlag() { ->with('Could not flag messages in mailbox <' . $mailbox->getId() . '>'); $this->expectException(ServiceException::class); - $this->migration->migrateImportantFromDb($account, $mailbox); + $this->migration->migrateImportantFromDb($this->client, $account, $mailbox); } } diff --git a/tests/Unit/Service/MailManagerTest.php b/tests/Unit/Service/MailManagerTest.php index b9b7f60d25..21cd84c64b 100644 --- a/tests/Unit/Service/MailManagerTest.php +++ b/tests/Unit/Service/MailManagerTest.php @@ -351,13 +351,9 @@ public function testFilterFlagStandard(): void { 'mdnsent' => [\Horde_Imap_Client::FLAG_MDNSENT], ]; - $this->imapClientFactory->expects($this->any()) - ->method('getClient') - ->willReturn($client); - //standard flags foreach ($flags as $k => $flag) { - $this->assertEquals($this->manager->filterFlags($account, $k, 'INBOX'), $flags[$k]); + $this->assertEquals($this->manager->filterFlags($client, $account, $k, 'INBOX'), $flags[$k]); } } @@ -365,53 +361,40 @@ public function testSetFilterFlagsNoCapabilities() { $account = $this->createMock(Account::class); $client = $this->createMock(Horde_Imap_Client_Socket::class); - $this->imapClientFactory->expects($this->any()) - ->method('getClient') - ->willReturn($client); - - $this->assertEquals([], $this->manager->filterFlags($account, Tag::LABEL_IMPORTANT, 'INBOX')); + $this->assertEquals([], $this->manager->filterFlags($client, $account, Tag::LABEL_IMPORTANT, 'INBOX')); } public function testSetFilterFlagsImportant() { $account = $this->createMock(Account::class); $client = $this->createMock(Horde_Imap_Client_Socket::class); - $this->imapClientFactory->expects($this->once()) - ->method('getClient') - ->willReturn($client); $client->expects($this->once()) ->method('status') ->willReturn(['permflags' => [ "11" => "\*" ]]); - $this->assertEquals([Tag::LABEL_IMPORTANT], $this->manager->filterFlags($account, Tag::LABEL_IMPORTANT, 'INBOX')); + $this->assertEquals([Tag::LABEL_IMPORTANT], $this->manager->filterFlags($client, $account, Tag::LABEL_IMPORTANT, 'INBOX')); } public function testIsPermflagsEnabledTrue(): void { $account = $this->createMock(Account::class); $client = $this->createMock(Horde_Imap_Client_Socket::class); - $this->imapClientFactory->expects($this->once()) - ->method('getClient') - ->willReturn($client); $client->expects($this->once()) ->method('status') ->willReturn(['permflags' => [ "11" => "\*"] ]); - $this->assertTrue($this->manager->isPermflagsEnabled($account, 'INBOX')); + $this->assertTrue($this->manager->isPermflagsEnabled($client, $account, 'INBOX')); } public function testIsPermflagsEnabledFalse(): void { $account = $this->createMock(Account::class); $client = $this->createMock(Horde_Imap_Client_Socket::class); - $this->imapClientFactory->expects($this->once()) - ->method('getClient') - ->willReturn($client); $client->expects($this->once()) ->method('status') ->willReturn([]); - $this->assertFalse($this->manager->isPermflagsEnabled($account, 'INBOX')); + $this->assertFalse($this->manager->isPermflagsEnabled($client, $account, 'INBOX')); } public function testRemoveFlag(): void {