Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions lib/Service/MailManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Re-throw transient IMAP failures instead

If status() fails with a transient Horde exception such as SERVER_READERROR or DISCONNECT, this now downgrades the failure to “permflags unsupported”. In the tag/untag path (tagMessagesWithClient()), that makes the caller skip the IMAP addFlag/removeFlag block but still update tagMapper locally, so a user-visible tag change can be reported as successful even though the server was not updated. Please only suppress the specific PERMANENTFLAGS server response this fix targets and keep connection/authentication failures propagating.

Useful? React with 👍 / 👎.

}
return (is_array($capabilities) === true && array_key_exists('permflags', $capabilities) === true && in_array("\*", $capabilities['permflags'], true) === true);
}
Expand Down
19 changes: 19 additions & 0 deletions tests/Unit/Service/MailManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
Loading