diff --git a/app/courrier/page.tsx b/app/courrier/page.tsx index c10723be..c45bacb1 100644 --- a/app/courrier/page.tsx +++ b/app/courrier/page.tsx @@ -135,17 +135,24 @@ function EmailContent({ email }: { email: Email }) { if (mounted) { // Update the email content with the fetched full content email.content = fullContent.content; - email.contentFetched = true; - // Render the content - call ourselves again now that we have content - setDebugInfo('Content fetched from API, reprocessing'); - loadContent(); - return; + // Render the content + const sanitizedHtml = DOMPurify.sanitize(fullContent.content); + setContent( +
+ ); + setDebugInfo('Rendered fetched HTML content'); + setError(null); + setIsLoading(false); } + return; } // Use existing content if available - console.log('Processing content for email:', email.id); + console.log('Using existing content for email'); const formattedEmail = email.content.trim(); if (!formattedEmail) { @@ -158,13 +165,23 @@ function EmailContent({ email }: { email: Email }) { return; } - try { - // Always try to use the mail parser first for consistency - console.log('Parsing email content with mailparser'); + // Check if content is already HTML + if (formattedEmail.startsWith('<') && formattedEmail.endsWith('>')) { + // Content is likely HTML, sanitize and display directly + const sanitizedHtml = DOMPurify.sanitize(formattedEmail); + setContent( + + ); + setDebugInfo('Rendered existing HTML content'); + } else { + // Use mailparser for more complex formats + console.log('Parsing email content'); const parsedEmail = await decodeEmail(formattedEmail); if (parsedEmail.html) { - console.log('Using HTML content from parser'); const sanitizedHtml = DOMPurify.sanitize(parsedEmail.html); setContent(