Исправить источник счётчика непрочитанных
Корневая проблема: convertMailboxArray хардкодил unreadCount: 0, поэтому initUnreadCounts всегда инициализировал счётчики нулями. Решение: читать реальный unseen из client.mailbox.unseen (IMAP SELECT автоматически возвращает количество непрочитанных при открытии ящика). - provider.ts: добавить unseen в MessageListResult - imap.provider.ts: читать client.mailbox.unseen в listMessages - messages.store.ts: для полных папок — точный счёт из флагов, для больших папок — result.unseen из IMAP SELECT Примечание: imapflow уже использует BODY.PEEK[] для source-запросов, поэтому prefetchBodies не ставит \Seen на сервере. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
580e5ba87f
commit
8c92c7e1fc
3 changed files with 9 additions and 4 deletions
|
|
@ -84,6 +84,8 @@ export class ImapProvider implements IEmailProvider {
|
|||
|
||||
if (start > total) return { messages: [], total }
|
||||
|
||||
const unseen = (this.client.mailbox as { unseen?: number })?.unseen ?? 0
|
||||
|
||||
const messages: MessageEnvelope[] = []
|
||||
|
||||
for await (const msg of this.client.fetch(`${start}:${end}`, {
|
||||
|
|
@ -98,7 +100,7 @@ export class ImapProvider implements IEmailProvider {
|
|||
// Newest first
|
||||
messages.reverse()
|
||||
|
||||
return { messages, total }
|
||||
return { messages, total, unseen }
|
||||
} finally {
|
||||
lock.release()
|
||||
}
|
||||
|
|
@ -107,7 +109,7 @@ export class ImapProvider implements IEmailProvider {
|
|||
async fetchMessageBody(folderId: string, messageId: string): Promise<MessageBody> {
|
||||
const lock = await this.client.getMailboxLock(folderId)
|
||||
try {
|
||||
// Download full RFC822 source and parse with mailparser
|
||||
// imapflow использует BODY.PEEK[] (не BODY[]) для source-запросов — \Seen не ставится
|
||||
const download = await this.client.download(messageId, undefined, { uid: true })
|
||||
if (!download) {
|
||||
return { id: messageId, html: null, text: null, inlineImages: [], attachments: [] }
|
||||
|
|
|
|||
|
|
@ -63,11 +63,13 @@ export const useMessagesStore = defineStore('messages', () => {
|
|||
|
||||
if (offset === 0) {
|
||||
messages.value = result.messages
|
||||
// Если все письма загружены в одну страницу — пересчитываем
|
||||
// unread точно из флагов, а не из (возможно устаревшего) серверного счётчика
|
||||
if (result.messages.length >= result.total) {
|
||||
// Все письма загружены — считаем точно из флагов
|
||||
const exactUnread = result.messages.filter((m) => !m.flags.seen).length
|
||||
foldersStore.setFolderUnread(accountId, folderId, exactUnread)
|
||||
} else {
|
||||
// Частичная загрузка — используем unseen из IMAP SELECT (client.mailbox.unseen)
|
||||
foldersStore.setFolderUnread(accountId, folderId, result.unseen)
|
||||
}
|
||||
// Предзагрузка тел первых 10 писем в фоне
|
||||
setTimeout(() => prefetchBodies(accountId, folderId, 10), 600)
|
||||
|
|
|
|||
|
|
@ -14,6 +14,7 @@ export interface MessageListOptions {
|
|||
export interface MessageListResult {
|
||||
messages: MessageEnvelope[]
|
||||
total: number
|
||||
unseen: number
|
||||
}
|
||||
|
||||
export interface IEmailProvider {
|
||||
|
|
|
|||
Loading…
Reference in a new issue