diff --git a/app/courrier/page.tsx b/app/courrier/page.tsx index ac228e5c..cda5d66f 100644 --- a/app/courrier/page.tsx +++ b/app/courrier/page.tsx @@ -475,6 +475,7 @@ function renderEmailContent(email: Email) { console.log('First 100 chars:', email.body.substring(0, 100)); try { + // First try to parse the full email const parsed = parseFullEmail(email.body); console.log('Parsed content:', { hasText: !!parsed.text, @@ -482,8 +483,32 @@ function renderEmailContent(email: Email) { hasAttachments: parsed.attachments.length > 0 }); - // Display HTML content if available, otherwise fallback to text - const content = parsed.html || parsed.text || decodeMimeContent(email.body); + // If parsing failed, try direct content extraction + let content = null; + if (parsed.html) { + content = parsed.html; + } else if (parsed.text) { + content = parsed.text; + } else { + // Try to extract content directly from body + const htmlMatch = email.body.match(/]*>[\s\S]*?<\/html>/i); + if (htmlMatch) { + content = htmlMatch[0]; + } else { + content = email.body + .replace(/<[^>]+>/g, '') + .replace(/ /g, ' ') + .replace(/&/g, '&') + .replace(/</g, '<') + .replace(/>/g, '>') + .replace(/"/g, '"') + .replace(/\r\n/g, '\n') + .replace(/=\n/g, '') + .replace(/=3D/g, '=') + .replace(/=09/g, '\t') + .trim(); + } + } if (!content) { console.log('No content available after all attempts');