From 96cc086d3abfe88b15400ec7d411d22ec937da2b Mon Sep 17 00:00:00 2001 From: Christoph Wurst Date: Fri, 7 Mar 2025 16:15:12 +0100 Subject: [PATCH] fix(imap): Sync mailboxes without a status Signed-off-by: Christoph Wurst --- lib/IMAP/MailboxSync.php | 8 +++++--- tests/Unit/IMAP/MailboxSyncTest.php | 10 +++++++--- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/lib/IMAP/MailboxSync.php b/lib/IMAP/MailboxSync.php index 5ac282c6b1..78e16ee6ab 100644 --- a/lib/IMAP/MailboxSync.php +++ b/lib/IMAP/MailboxSync.php @@ -299,9 +299,11 @@ private function syncMailboxStatus(mixed $mailboxes, ?string $personalNamespace, return $mailbox->getName(); }, $syncStatus)); foreach ($syncStatus as $mailbox) { - $status = $statuses[$mailbox->getName()]; - $mailbox->setMessages($status->getTotal()); - $mailbox->setUnseen($status->getUnread()); + $status = $statuses[$mailbox->getName()] ?? null; + if ($status !== null) { + $mailbox->setMessages($status->getTotal()); + $mailbox->setUnseen($status->getUnread()); + } } $this->atomic(function () use ($syncStatus) { foreach ($syncStatus as $mailbox) { diff --git a/tests/Unit/IMAP/MailboxSyncTest.php b/tests/Unit/IMAP/MailboxSyncTest.php index 09da950f6d..2a47a50533 100644 --- a/tests/Unit/IMAP/MailboxSyncTest.php +++ b/tests/Unit/IMAP/MailboxSyncTest.php @@ -124,6 +124,7 @@ public function testSync(): void { $folders = [ $this->createMock(Folder::class), $this->createMock(Folder::class), + $this->createMock(Folder::class), ]; $status = [ 'unseen' => 10, @@ -133,24 +134,27 @@ public function testSync(): void { $folders[0]->method('getMailbox')->willReturn('mb1'); $folders[1]->method('getStatus')->willReturn($status); $folders[1]->method('getMailbox')->willReturn('mb2'); + $folders[2]->method('getStatus')->willReturn($status); + $folders[2]->method('getMailbox')->willReturn('mb3'); $this->folderMapper->expects($this->once()) ->method('getFolders') ->with($account, $client) ->willReturn($folders); $this->folderMapper->expects($this->once()) ->method('getFoldersStatusAsObject') - ->with($client, self::equalToCanonicalizing(['mb1', 'mb2',])) + ->with($client, self::equalToCanonicalizing(['mb1', 'mb2', 'mb3',])) ->willReturn([ 'mb1' => new MailboxStats(1, 2), 'mb2' => new MailboxStats(1, 2), + /* no status for mb3 */ ]); $this->folderMapper->expects($this->once()) ->method('detectFolderSpecialUse') ->with($folders); - $this->mailboxMapper->expects(self::exactly(2)) + $this->mailboxMapper->expects(self::exactly(3)) ->method('insert') ->willReturnArgument(0); - $this->mailboxMapper->expects(self::exactly(2)) + $this->mailboxMapper->expects(self::exactly(3)) ->method('update') ->willReturnArgument(0); $this->dispatcher