Fix: keep signature when inserting a template #621

This commit is contained in:
Linus Rath
2026-07-16 20:13:07 +02:00
parent 739b72d251
commit 4a4950c3e5
3 changed files with 69 additions and 3 deletions
+20
View File
@@ -80,6 +80,26 @@ export function filterTemplates(templates: EmailTemplate[], query: string): Emai
);
}
// Compose bodies carry the embedded signature bracketed by
// data-signature-block markers (see email-composer's
// buildEmbeddedSignatureHtml). Applying a template must replace only the
// message content, so splice the template above the signature range instead
// of overwriting the whole body.
export function spliceTemplateAboveSignature(prevHtml: string, templateHtml: string): string {
const doc = new DOMParser().parseFromString(prevHtml, 'text/html');
const startEl = doc.querySelector('[data-signature-block="separator"], [data-signature-block="start"]');
if (!startEl) return templateHtml;
const endEl = doc.querySelector('[data-signature-block="end"]');
const host = doc.createElement('div');
let cursor: Node | null = startEl;
while (cursor) {
host.appendChild(cursor.cloneNode(true));
if (cursor === endEl) break;
cursor = cursor.nextSibling;
}
return templateHtml + host.innerHTML;
}
function sanitizeText(value: unknown): string {
return DOMPurify.sanitize(String(value || ''), STRIP_HTML_CONFIG);
}