diff --git a/components/email/email-viewer.tsx b/components/email/email-viewer.tsx index 162f2443..626552fc 100644 --- a/components/email/email-viewer.tsx +++ b/components/email/email-viewer.tsx @@ -803,6 +803,45 @@ export function EmailViewer({ }; }, [email, allowExternalContent, hasBlockedContent, externalContentPolicy, isSenderTrusted, resolvedTheme]); + // Print only the email content in a new window + const handlePrint = () => { + if (!email) return; + const printSender = email.from?.[0]; + const date = email.sentAt ? new Date(email.sentAt).toLocaleString() : ''; + const toList = email.to?.map(r => r.name ? `${r.name} <${r.email}>` : r.email).join(', ') || ''; + const ccList = email.cc?.map(r => r.name ? `${r.name} <${r.email}>` : r.email).join(', ') || ''; + + const printWindow = window.open('', '_blank'); + if (!printWindow) return; + + printWindow.document.write(` +${DOMPurify.sanitize(email.subject || t('no_subject'))} + +
+
${DOMPurify.sanitize(email.subject || t('no_subject'))}
+
+
${t('from')}: ${DOMPurify.sanitize(printSender?.name ? `${printSender.name} <${printSender.email}>` : printSender?.email || t('unknown_sender'))}
+ ${toList ? `
${t('to')}: ${toList}
` : ''} + ${ccList ? `
CC: ${ccList}
` : ''} + ${date ? `
${t('date')}: ${DOMPurify.sanitize(date)}
` : ''} +
+
+
${emailContent.html}
+`); + printWindow.document.close(); + printWindow.focus(); + printWindow.print(); + }; + // Detect List-Unsubscribe header for newsletter banners const listHeaders = useMemo(() => { if (!email?.headers) return null; @@ -1070,7 +1109,7 @@ export function EmailViewer({