diff --git a/app/courrier/page.tsx b/app/courrier/page.tsx index 0127be3b..1283b24e 100644 --- a/app/courrier/page.tsx +++ b/app/courrier/page.tsx @@ -187,6 +187,33 @@ function parseFullEmail(emailRaw: string): ParsedEmailContent { } } + // If no content was found, try to extract content directly + if (!result.text && !result.html) { + // Try to extract HTML content + const htmlMatch = emailRaw.match(/]*>[\s\S]*?<\/html>/i); + if (htmlMatch) { + result.html = decodeEmailBody(htmlMatch[0], 'text/html'); + } else { + // Try to extract plain text + const textContent = emailRaw + .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 (textContent) { + result.text = textContent; + } + } + } + return result; } @@ -454,12 +481,44 @@ function renderEmailContent(email: Email) { hasAttachments: parsedContent.attachments.length > 0 }); - // Determine content type - const isHtml = parsedContent.html !== null; - const content = isHtml ? parsedContent.html : parsedContent.text; + // 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'); + 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; + } + } + + if (!content) { + console.log('No content available after all attempts'); return
No content available
; }