Skip to content

Commit

Permalink
fix(imap): Sync mailboxes without a status
Browse files Browse the repository at this point in the history
Signed-off-by: Christoph Wurst <[email protected]>
  • Loading branch information
ChristophWurst committed Mar 7, 2025
1 parent e6bafb3 commit 2317686
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
8 changes: 5 additions & 3 deletions lib/IMAP/MailboxSync.php
Original file line number Diff line number Diff line change
Expand Up @@ -285,9 +285,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) {
Expand Down
10 changes: 7 additions & 3 deletions tests/Unit/IMAP/MailboxSyncTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ public function testSync(): void {
$folders = [
$this->createMock(Folder::class),
$this->createMock(Folder::class),
$this->createMock(Folder::class),
];
$status = [
'unseen' => 10,
Expand All @@ -117,24 +118,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
Expand Down

0 comments on commit 2317686

Please sign in to comment.