Skip to content

Commit 2317686

Browse files
fix(imap): Sync mailboxes without a status
Signed-off-by: Christoph Wurst <[email protected]>
1 parent e6bafb3 commit 2317686

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

lib/IMAP/MailboxSync.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -285,9 +285,11 @@ private function syncMailboxStatus(mixed $mailboxes, ?string $personalNamespace,
285285
return $mailbox->getName();
286286
}, $syncStatus));
287287
foreach ($syncStatus as $mailbox) {
288-
$status = $statuses[$mailbox->getName()];
289-
$mailbox->setMessages($status->getTotal());
290-
$mailbox->setUnseen($status->getUnread());
288+
$status = $statuses[$mailbox->getName()] ?? null;
289+
if ($status !== null) {
290+
$mailbox->setMessages($status->getTotal());
291+
$mailbox->setUnseen($status->getUnread());
292+
}
291293
}
292294
$this->atomic(function () use ($syncStatus) {
293295
foreach ($syncStatus as $mailbox) {

tests/Unit/IMAP/MailboxSyncTest.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ public function testSync(): void {
108108
$folders = [
109109
$this->createMock(Folder::class),
110110
$this->createMock(Folder::class),
111+
$this->createMock(Folder::class),
111112
];
112113
$status = [
113114
'unseen' => 10,
@@ -117,24 +118,27 @@ public function testSync(): void {
117118
$folders[0]->method('getMailbox')->willReturn('mb1');
118119
$folders[1]->method('getStatus')->willReturn($status);
119120
$folders[1]->method('getMailbox')->willReturn('mb2');
121+
$folders[2]->method('getStatus')->willReturn($status);
122+
$folders[2]->method('getMailbox')->willReturn('mb3');
120123
$this->folderMapper->expects($this->once())
121124
->method('getFolders')
122125
->with($account, $client)
123126
->willReturn($folders);
124127
$this->folderMapper->expects($this->once())
125128
->method('getFoldersStatusAsObject')
126-
->with($client, self::equalToCanonicalizing(['mb1', 'mb2',]))
129+
->with($client, self::equalToCanonicalizing(['mb1', 'mb2', 'mb3',]))
127130
->willReturn([
128131
'mb1' => new MailboxStats(1, 2),
129132
'mb2' => new MailboxStats(1, 2),
133+
/* no status for mb3 */
130134
]);
131135
$this->folderMapper->expects($this->once())
132136
->method('detectFolderSpecialUse')
133137
->with($folders);
134-
$this->mailboxMapper->expects(self::exactly(2))
138+
$this->mailboxMapper->expects(self::exactly(3))
135139
->method('insert')
136140
->willReturnArgument(0);
137-
$this->mailboxMapper->expects(self::exactly(2))
141+
$this->mailboxMapper->expects(self::exactly(3))
138142
->method('update')
139143
->willReturnArgument(0);
140144
$this->dispatcher

0 commit comments

Comments
 (0)