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

This commit is contained in:
Linus Rath
2026-10-29 04:16:08 +01:00
parent 1ffce863d9
commit 6414b0d6a9
3 changed files with 24 additions and 2 deletions
+14
View File
@@ -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<string, { name: string }>;
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',
+6 -1
View File
@@ -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')) {
+4 -1
View File
@@ -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 };