diff --git a/app/courrier/page.tsx b/app/courrier/page.tsx index 1283b24e..ac228e5c 100644 --- a/app/courrier/page.tsx +++ b/app/courrier/page.tsx @@ -436,7 +436,7 @@ function cleanHtml(html: string): string { function decodeMimeContent(content: string): string { if (!content) return ''; - // Check if this is an Infomaniak multipart message + // Check if this is a multipart message if (content.includes('Content-Type: multipart/')) { const boundary = content.match(/boundary="([^"]+)"/)?.[1]; if (boundary) { @@ -474,93 +474,42 @@ function renderEmailContent(email: Email) { console.log('Body length:', email.body.length); console.log('First 100 chars:', email.body.substring(0, 100)); - const parsedContent = parseFullEmail(email.body); - console.log('Parsed content:', { - hasText: !!parsedContent.text, - hasHtml: !!parsedContent.html, - hasAttachments: parsedContent.attachments.length > 0 - }); + try { + const parsed = parseFullEmail(email.body); + console.log('Parsed content:', { + hasText: !!parsed.text, + hasHtml: !!parsed.html, + hasAttachments: parsed.attachments.length > 0 + }); - // Determine content type and get content - let content = null; - let isHtml = false; - - if (parsedContent.html) { - content = parsedContent.html; - isHtml = true; - } else if (parsedContent.text) { - content = parsedContent.text; - isHtml = false; - } - - if (!content) { - console.log('No content available from parsing, trying direct body'); - // Try to extract content directly from body - const htmlMatch = email.body.match(/]*>[\s\S]*?<\/html>/i); - if (htmlMatch) { - content = htmlMatch[0]; - isHtml = true; - } 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(); - isHtml = false; + // Display HTML content if available, otherwise fallback to text + const content = parsed.html || parsed.text || decodeMimeContent(email.body); + + if (!content) { + console.log('No content available after all attempts'); + return