From bd2ffab3bcd1b26fc321b07da433aeb40d4da8bf Mon Sep 17 00:00:00 2001 From: Linus Rath <139418639+rathlinus@users.noreply.github.com> Date: Fri, 22 May 2026 11:20:50 +0200 Subject: [PATCH] fix: resolve destination account id to local namespace in mailbox drop --- hooks/use-mailbox-drop.ts | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/hooks/use-mailbox-drop.ts b/hooks/use-mailbox-drop.ts index e018bd04..32026c7f 100644 --- a/hooks/use-mailbox-drop.ts +++ b/hooks/use-mailbox-drop.ts @@ -21,6 +21,27 @@ function resolveSourceAccountId(email: Email | undefined): string | null { return useAuthStore.getState().activeAccountId; } +/** + * Returns the local accountId ("user@host") that owns the destination + * mailbox. `mailbox.accountId` is the JMAP server's opaque account id, but + * `clients`, `activeAccountId`, and `email.accountId` all live in the local + * namespace. We map back by matching the JMAP id against each connected + * client's `getAccountId()`. Falls back to the viewing/active account so + * single-account flows (no connected clients map entry yet, in-memory edits, + * etc.) still resolve correctly. + */ +function resolveDestAccountId(mailbox: Mailbox): string | null { + const jmapId = mailbox.accountId; + if (jmapId) { + const clients = useAuthStore.getState().getAllConnectedClients(); + for (const [localId, client] of clients) { + if (client.getAccountId() === jmapId) return localId; + } + } + return useEmailStore.getState().viewingAccountId + ?? useAuthStore.getState().activeAccountId; +} + interface UseMailboxDropOptions { mailbox: Mailbox; onDropComplete?: () => void; @@ -123,7 +144,7 @@ export function useMailboxDrop({ mailbox, onDropComplete, onSuccess, onError }: // Group dragged emails by source account. In single-account flows this // collapses to one bucket; in unified view or the Pro multi-account // sidebar a single drag can mix sources. - const destAccountId = mailbox.accountId; + const destAccountId = resolveDestAccountId(mailbox); const idToEmail = new Map(draggedEmails.map((em) => [em.id, em])); const bySource = new Map(); for (const id of emailIds) {