diff --git a/lib/demo/demo-client.ts b/lib/demo/demo-client.ts index 8238018e..ea0b4765 100644 --- a/lib/demo/demo-client.ts +++ b/lib/demo/demo-client.ts @@ -329,7 +329,7 @@ export class DemoJMAPClient implements IJMAPClient { this.recalcMailboxCounts(); } - async emptyMailbox(mailboxId: string): Promise { + async emptyMailbox(mailboxId: string, _accountId?: string): Promise { const before = this.data.emails.length; this.data.emails = this.data.emails.filter(e => !e.mailboxIds[mailboxId]); const removed = before - this.data.emails.length; diff --git a/lib/jmap/client-interface.ts b/lib/jmap/client-interface.ts index f657cca9..abfad8eb 100644 --- a/lib/jmap/client-interface.ts +++ b/lib/jmap/client-interface.ts @@ -109,7 +109,7 @@ export interface IJMAPClient { accountId?: string, ): Promise; moveEmail(emailId: string, toMailboxId: string, accountId?: string): Promise; - emptyMailbox(mailboxId: string): Promise; + emptyMailbox(mailboxId: string, accountId?: string): Promise; markMailboxAsRead(mailboxId: string, accountId?: string): Promise; markAllAsRead(excludeMailboxIds?: string[], accountId?: string): Promise; markAsSpam(emailId: string, accountId?: string, markAsRead?: boolean): Promise; diff --git a/lib/jmap/client.ts b/lib/jmap/client.ts index 54b565ed..cd66cf6c 100644 --- a/lib/jmap/client.ts +++ b/lib/jmap/client.ts @@ -1445,19 +1445,20 @@ export class JMAPClient implements IJMAPClient { } } - async emptyMailbox(mailboxId: string): Promise { + async emptyMailbox(mailboxId: string, accountId?: string): Promise { + const targetAccountId = accountId || this.accountId; let totalDestroyed = 0; let hasMore = true; while (hasMore) { const response = await this.request([ ["Email/query", { - accountId: this.accountId, + accountId: targetAccountId, filter: { inMailbox: mailboxId }, limit: 500, }, "0"], ["Email/set", { - accountId: this.accountId, + accountId: targetAccountId, "#destroy": { resultOf: "0", name: "Email/query", path: "/ids" }, }, "1"], ]); diff --git a/stores/email-store.ts b/stores/email-store.ts index 8e8a3d0b..ab746e70 100644 --- a/stores/email-store.ts +++ b/stores/email-store.ts @@ -2438,7 +2438,10 @@ export const useEmailStore = create((set, get) => ({ emptyMailbox: async (client, mailboxId) => { try { set({ isLoading: true, error: null }); - await resolveActionClient(client).emptyMailbox(mailboxId); + const mailbox = resolveActionMailboxes().find(mb => mb.id === mailboxId); + const accountId = mailbox?.isShared ? mailbox.accountId : undefined; + const jmapMailboxId = mailbox?.originalId || mailboxId; + await resolveActionClient(client).emptyMailbox(jmapMailboxId, accountId); // Clear emails from local state if we're viewing this mailbox const currentMailbox = get().selectedMailbox;