From 6414b0d6a996faecfd11abe2e426b45a8a7bcd5c Mon Sep 17 00:00:00 2001 From: Linus Rath <139418639+rathlinus@users.noreply.github.com> Date: Thu, 29 Oct 2026 04:16:08 +0100 Subject: [PATCH] fix: send from the own account when a group's identities can't be read, and clear a draft save stopped by an account switch --- src/api/__tests__/send-account.test.ts | 14 ++++++++++++++ src/lib/compose-send-account.ts | 7 ++++++- src/screens/ComposeScreen.tsx | 5 ++++- 3 files changed, 24 insertions(+), 2 deletions(-) diff --git a/src/api/__tests__/send-account.test.ts b/src/api/__tests__/send-account.test.ts index 9671e0fc..411cf424 100644 --- a/src/api/__tests__/send-account.test.ts +++ b/src/api/__tests__/send-account.test.ts @@ -99,6 +99,20 @@ describe('sendTargetFor', () => { }); }); + it("sends from the own account when the group's identities can't be read", async () => { + const accounts = client.currentSession.accounts as Record; + accounts.team.name = 'team@example.com'; + vi.spyOn(console, 'warn').mockImplementation(() => undefined); + client.request.mockRejectedValue(new Error('Network request failed')); + try { + await expect(sendTargetFor(MIRRORED, 'team@example.com', MAILBOXES)).resolves.toEqual({ + identityId: 'i-me-team', draftsMailboxId: 'own-drafts', sentMailboxId: 'own-sent', + }); + } finally { + accounts.team.name = 'Team'; + } + }); + it('keeps an own message in the own folders', async () => { await expect(sendTargetFor(ME, 'me@example.com', MAILBOXES)).resolves.toEqual({ identityId: 'i-me', draftsMailboxId: 'own-drafts', sentMailboxId: 'own-sent', diff --git a/src/lib/compose-send-account.ts b/src/lib/compose-send-account.ts index 9b1e4357..785f1654 100644 --- a/src/lib/compose-send-account.ts +++ b/src/lib/compose-send-account.ts @@ -39,7 +39,12 @@ export async function sendTargetFor(identity: Identity, fromEmail: string, mailb if (accountId === jmapClient.accountId) return ownTarget; // Submitting needs the account's own identity for the address; without // one, the message goes out of the login's account as before. - const accountIdentity = await sendIdentityIn(accountId, fromEmail); + let accountIdentity: Identity | undefined; + try { + accountIdentity = await sendIdentityIn(accountId, fromEmail); + } catch (err) { + console.warn('[compose] could not read the identities of the sending account', err); + } if (!accountIdentity) return ownTarget; let scope = mailboxesOfAccount(mailboxes, accountId); if (!scope.some((m) => m.role === 'sent')) { diff --git a/src/screens/ComposeScreen.tsx b/src/screens/ComposeScreen.tsx index 7c85eaf9..ea5f054e 100644 --- a/src/screens/ComposeScreen.tsx +++ b/src/screens/ComposeScreen.tsx @@ -1383,7 +1383,10 @@ export default function ComposeScreen({ route, navigation }: Props) { // A draft From a group identity is saved in the group's Drafts, like // its Sent copy (#1090); one without a Drafts folder there in the own. const target = await sendTargetFor(identity, outgoing.from[0]?.email ?? identity.email, mailboxes); - if (loginMoved()) return draftIdRef.current; + if (loginMoved()) { + setDraftStatus('idle'); + return draftIdRef.current; + } const saveIn = target.accountId && target.draftsMailboxId ? { accountId: target.accountId, draftsMailboxId: target.draftsMailboxId } : { accountId: undefined, draftsMailboxId: draftsMailbox.id };