feat(compose): preselect identity of the active mailbox for new messages
Starting a new message while viewing a specific mailbox/account now defaults the From identity to that mailbox instead of the global primary identity, so composing from info@ sends as info@. Mirrors the existing reply-time identity match and rides the same autoSelectReplyIdentity setting; reply/replyAll/forward keep resolving from the original recipients. Matches exact then +tag-stripped. Extracts findComposeIdentityId into lib/reply-identity.ts with unit tests.
This commit is contained in:
committed by
Linus Rath
parent
6c49427c7c
commit
b716f95a73
@@ -67,6 +67,34 @@ export function findReplyIdentityId(
|
||||
return baseIdentity?.id ?? null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Pick the identity to use for a NEW message started while viewing a specific
|
||||
* mailbox/account. Matches the active mailbox's address to a configured
|
||||
* identity (exact, then `+tag`-stripped) so composing from info@ defaults its
|
||||
* From to info@. Returns `null` when no address is given or none matches, so
|
||||
* the caller keeps the primary identity.
|
||||
*/
|
||||
export function findComposeIdentityId(
|
||||
identities: Identity[],
|
||||
accountEmail?: string | null,
|
||||
): string | null {
|
||||
const email = accountEmail?.trim();
|
||||
if (identities.length === 0 || !email) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const exact = normalizeEmailAddress(email);
|
||||
const exactIdentity = identities.find((identity) => normalizeEmailAddress(identity.email) === exact);
|
||||
if (exactIdentity) {
|
||||
return exactIdentity.id;
|
||||
}
|
||||
|
||||
const base = normalizeBaseEmailAddress(email);
|
||||
const baseIdentity = identities.find((identity) => normalizeBaseEmailAddress(identity.email) === base);
|
||||
|
||||
return baseIdentity?.id ?? null;
|
||||
}
|
||||
|
||||
export interface ReplyFromResolution {
|
||||
/** Identity to use for JMAP `identityId` and the SMTP envelope MAIL FROM. */
|
||||
identityId: string;
|
||||
|
||||
Reference in New Issue
Block a user