diff --git a/src/main/providers/imap.provider.ts b/src/main/providers/imap.provider.ts index aa691b8..dbf42dc 100644 --- a/src/main/providers/imap.provider.ts +++ b/src/main/providers/imap.provider.ts @@ -69,9 +69,28 @@ export class ImapProvider implements IEmailProvider { // listTree() returns { root: true, folders: ImapMailbox[] } const tree = await this.client.listTree() as { folders?: ImapMailbox[] } const folders = this.convertMailboxArray(tree.folders ?? []) + await this.populateUnreadCounts(folders) return { folders } } + private async populateUnreadCounts(folders: Folder[]): Promise { + for (const folder of folders) { + try { + const status = await this.client.status(folder.id, { unseen: true, messages: true }) as + { unseen?: number; messages?: number } | null + if (status) { + folder.unreadCount = status.unseen ?? 0 + folder.totalCount = status.messages ?? 0 + } + } catch { + // Некоторые папки (виртуальные, [Gmail]) могут не поддерживать STATUS + } + if (folder.children.length > 0) { + await this.populateUnreadCounts(folder.children) + } + } + } + async listMessages(options: MessageListOptions): Promise { const lock = await this.client.getMailboxLock(options.folderId) try {