diff --git a/app/courrier/page.tsx b/app/courrier/page.tsx index 9652ec0c..230a8a7c 100644 --- a/app/courrier/page.tsx +++ b/app/courrier/page.tsx @@ -49,9 +49,7 @@ import { CommandShortcut, } from '@/components/ui/command'; import { useSession } from 'next-auth/react'; -import DOMPurify from 'isomorphic-dompurify'; import ComposeEmail from '@/components/email/ComposeEmail'; -import { decodeEmail, cleanHtml } from '@/lib/mail-parser-wrapper'; import { Attachment as MailParserAttachment } from 'mailparser'; import { LoadingFix } from './loading-fix'; @@ -169,15 +167,15 @@ function EmailContent({ email }: { email: Email }) { // Update the email content with the fetched full content email.content = fullContent.content; - // Render the content - const sanitizedHtml = DOMPurify.sanitize(fullContent.content); + // Render the content using the centralized cleaner + const sanitizedHtml = cleanHtmlContent(fullContent.content); setContent(
); - setDebugInfo('Rendered fetched HTML content'); + setDebugInfo('Rendered fetched HTML content with centralized formatter'); setError(null); setIsLoading(false); } @@ -200,39 +198,36 @@ function EmailContent({ email }: { email: Email }) { // Check if content is already HTML if (formattedEmail.startsWith('<') && formattedEmail.endsWith('>')) { - // Content is likely HTML, sanitize and display directly - const sanitizedHtml = DOMPurify.sanitize(formattedEmail); + // Content is likely HTML, sanitize using the centralized cleaner + const sanitizedHtml = cleanHtmlContent(formattedEmail); setContent( ); - setDebugInfo('Rendered existing HTML content'); + setDebugInfo('Rendered existing HTML content with centralized formatter'); } else { - // Use mailparser for more complex formats - console.log('Parsing email content'); - const parsedEmail = await decodeEmail(formattedEmail); + // For plain text or complex formats, use the centralized formatter + const cleanedContent = cleanHtmlContent(formattedEmail); - if (parsedEmail.html) { - const sanitizedHtml = DOMPurify.sanitize(parsedEmail.html); + // If it looks like HTML, render it as HTML + if (cleanedContent.includes('<') && cleanedContent.includes('>')) { setContent( ); - setDebugInfo('Rendered HTML content from parser'); - } else if (parsedEmail.text) { + setDebugInfo('Rendered content as HTML using centralized formatter'); + } else { + // Otherwise, render as plain text setContent(