Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(imap): Sync mailboxes without a status #10822

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
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
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