mirror of
https://github.com/bulwarkmail/native.git
synced 2026-10-31 00:06:17 +00:00
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:
@@ -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',
|
||||
|
||||
@@ -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')) {
|
||||
|
||||
@@ -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 };
|
||||
|
||||
Reference in New Issue
Block a user