diff --git a/lib/Service/MailManager.php b/lib/Service/MailManager.php index 1fb1ce58fa..bb8ad80c4f 100644 --- a/lib/Service/MailManager.php +++ b/lib/Service/MailManager.php @@ -759,11 +759,12 @@ public function isPermflagsEnabled(Horde_Imap_Client_Socket $client, Account $ac try { $capabilities = $client->status($mailbox, Horde_Imap_Client::STATUS_PERMFLAGS); } catch (Horde_Imap_Client_Exception $e) { - throw new ServiceException( - 'Could not get message flag options from IMAP: ' . $e->getMessage(), - $e->getCode(), - $e - ); + $this->logger->debug('Could not get IMAP PERMANENTFLAGS support; treating custom flags as unsupported', [ + 'exception' => $e, + 'mailbox' => $mailbox, + ]); + + return false; } return (is_array($capabilities) === true && array_key_exists('permflags', $capabilities) === true && in_array("\*", $capabilities['permflags'], true) === true); } diff --git a/tests/Unit/Service/MailManagerTest.php b/tests/Unit/Service/MailManagerTest.php index 5bd24acc40..3c3df9e7bb 100644 --- a/tests/Unit/Service/MailManagerTest.php +++ b/tests/Unit/Service/MailManagerTest.php @@ -10,6 +10,7 @@ namespace OCA\Mail\Tests\Unit\Service; use ChristophWurst\Nextcloud\Testing\TestCase; +use Horde_Imap_Client_Exception; use Horde_Imap_Client_Socket; use OCA\Mail\Account; use OCA\Mail\Attachment; @@ -404,6 +405,24 @@ public function testIsPermflagsEnabledFalse(): void { $this->assertFalse($this->manager->isPermflagsEnabled($client, $account, 'INBOX')); } + public function testIsPermflagsEnabledReturnsFalseOnImapError(): void { + $account = $this->createStub(Account::class); + $client = $this->createMock(Horde_Imap_Client_Socket::class); + + $client->expects($this->once()) + ->method('status') + ->with('INBOX', \Horde_Imap_Client::STATUS_PERMFLAGS) + ->willThrowException(new Horde_Imap_Client_Exception('IMAP error reported by server.')); + $this->logger->expects($this->once()) + ->method('debug') + ->with( + 'Could not get IMAP PERMANENTFLAGS support; treating custom flags as unsupported', + $this->callback(static fn (array $context): bool => $context['mailbox'] === 'INBOX' && $context['exception'] instanceof Horde_Imap_Client_Exception), + ); + + $this->assertFalse($this->manager->isPermflagsEnabled($client, $account, 'INBOX')); + } + public function testRemoveFlag(): void { $client = $this->createStub(Horde_Imap_Client_Socket::class); $account = $this->createStub(Account::class);