fix: fall back to primary identity signature on reply

When auto-select picks an alias identity matching the original recipient,
the alias often has no signature configured. The composer was using the
alias's empty signature for both the visual preview and the appended
signature on send, so neither showed up. New mail worked because no
auto-select runs.

Add a signatureIdentity that falls back to the primary when the current
identity has no signature. From address, identity ID, S/MIME, and draft
saves still use currentIdentity so mail goes out from the right address.
This commit is contained in:
Chance
2026-05-09 14:21:05 +02:00
committed by Linus Rath
parent 7fa65796f0
commit c44a9ce6e0
+18 -12
View File
@@ -281,6 +281,12 @@ export function EmailComposer({
const currentIdentity = selectedIdentityId const currentIdentity = selectedIdentityId
? identities.find((identity) => identity.id === selectedIdentityId) || primaryIdentity ? identities.find((identity) => identity.id === selectedIdentityId) || primaryIdentity
: primaryIdentity; : primaryIdentity;
// Alias identities often lack a configured signature — fall back to the primary
// identity's signature so replies (which auto-select a matching alias) still
// populate the user's signature.
const signatureIdentity = (currentIdentity?.htmlSignature || currentIdentity?.textSignature)
? currentIdentity
: primaryIdentity;
useEffect(() => { useEffect(() => {
if (!autoSelectReplyIdentity) return; if (!autoSelectReplyIdentity) return;
if (selectedIdentityId || initialData?.selectedIdentityId) return; if (selectedIdentityId || initialData?.selectedIdentityId) return;
@@ -322,10 +328,10 @@ export function EmailComposer({
selectedIdentityId, selectedIdentityId,
]); ]);
const composerSignatureHtml = currentIdentity?.htmlSignature const composerSignatureHtml = signatureIdentity?.htmlSignature
? `<div>${sanitizeEmailHtml(currentIdentity.htmlSignature)}</div>` ? `<div>${sanitizeEmailHtml(signatureIdentity.htmlSignature)}</div>`
: currentIdentity?.textSignature : signatureIdentity?.textSignature
? `<div>${getPlainTextSignature(currentIdentity).replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/\n/g, '<br>')}</div>` ? `<div>${getPlainTextSignature(signatureIdentity).replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/\n/g, '<br>')}</div>`
: ''; : '';
const getAutocomplete = useContactStore((s) => s.getAutocomplete); const getAutocomplete = useContactStore((s) => s.getAutocomplete);
const addToTrustedSendersBook = useContactStore((s) => s.addToTrustedSendersBook); const addToTrustedSendersBook = useContactStore((s) => s.addToTrustedSendersBook);
@@ -954,11 +960,11 @@ export function EmailComposer({
// Body is already HTML from the rich text editor (or plain text in plain text mode). // Body is already HTML from the rich text editor (or plain text in plain text mode).
// Build HTML signature block (used only in rich text mode) // Build HTML signature block (used only in rich text mode)
const buildSignatureHtml = (): string => { const buildSignatureHtml = (): string => {
if (currentIdentity?.htmlSignature) { if (signatureIdentity?.htmlSignature) {
return `<br><br>-- <br>${sanitizeEmailHtml(currentIdentity.htmlSignature)}`; return `<br><br>-- <br>${sanitizeEmailHtml(signatureIdentity.htmlSignature)}`;
} }
if (currentIdentity?.textSignature) { if (signatureIdentity?.textSignature) {
return `<br><br>-- <br>${currentIdentity.textSignature.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/\n/g, '<br>')}`; return `<br><br>-- <br>${signatureIdentity.textSignature.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/\n/g, '<br>')}`;
} }
return ''; return '';
}; };
@@ -970,8 +976,8 @@ export function EmailComposer({
// In plain text mode, send text/plain only (no HTML body) // In plain text mode, send text/plain only (no HTML body)
const finalBody = plainTextMode const finalBody = plainTextMode
? appendPlainTextSignature(body, currentIdentity) ? appendPlainTextSignature(body, signatureIdentity)
: appendPlainTextSignature(htmlToPlainText(body), currentIdentity); : appendPlainTextSignature(htmlToPlainText(body), signatureIdentity);
const rewritten = plainTextMode ? null : rewriteInlineImages(body); const rewritten = plainTextMode ? null : rewriteInlineImages(body);
const finalHtmlBody = plainTextMode const finalHtmlBody = plainTextMode
@@ -1500,9 +1506,9 @@ export function EmailComposer({
)} )}
{plainTextMode ? ( {plainTextMode ? (
getPlainTextSignature(currentIdentity) ? ( getPlainTextSignature(signatureIdentity) ? (
<div className="px-4 pb-3 text-sm leading-6 text-muted-foreground break-words whitespace-pre-wrap font-mono"> <div className="px-4 pb-3 text-sm leading-6 text-muted-foreground break-words whitespace-pre-wrap font-mono">
{'-- \n'}{getPlainTextSignature(currentIdentity)} {'-- \n'}{getPlainTextSignature(signatureIdentity)}
</div> </div>
) : null ) : null
) : composerSignatureHtml ? ( ) : composerSignatureHtml ? (