diff --git a/app/mail/page.tsx b/app/mail/page.tsx index 15149676..8c1b3e97 100644 --- a/app/mail/page.tsx +++ b/app/mail/page.tsx @@ -301,50 +301,41 @@ function decodeMimeContent(content: string): string { function renderEmailContent(email: Email) { try { - // First, parse the email headers - const headers = parseEmailHeaders(email.body); - - // Get the content type and encoding - const contentType = headers.contentType || ''; - const encoding = headers.encoding || '7bit'; - const charset = headers.charset || 'utf-8'; + // Parse the full email content + const parsed = parseFullEmail(email.body); - // Split the email into headers and body - const [headerPart, ...bodyParts] = email.body.split('\r\n\r\n'); - const body = bodyParts.join('\r\n\r\n'); - - // Decode the content based on encoding - let decodedContent = body; - if (encoding.toLowerCase() === 'quoted-printable') { - decodedContent = decodeQuotedPrintable(body, charset); - } else if (encoding.toLowerCase() === 'base64') { - decodedContent = decodeBase64(body, charset); - } - - // If it's HTML content, clean and render it - if (contentType.includes('text/html')) { - const cleanedHtml = cleanHtml(decodedContent); + // If we have HTML content, render it + if (parsed.html) { return (
); } - // If it's plain text, render it with proper formatting - if (contentType.includes('text/plain')) { + // If we have text content, render it with proper formatting + if (parsed.text) { return (
- {decodedContent.split('\n').map((line, i) => ( + {parsed.text.split('\n').map((line, i) => (

{line}

))}
); } - // If we couldn't determine the content type, try to clean and display the content - const cleanedContent = cleanHtml(decodedContent); + // If we have attachments but no content, show a message + if (parsed.attachments.length > 0) { + return ( +
+ This email contains {parsed.attachments.length} attachment{parsed.attachments.length > 1 ? 's' : ''}. +
+ ); + } + + // If we couldn't parse the content, try to clean and display it + const cleanedContent = cleanHtml(email.body); return (
{cleanedContent.split('\n').map((line, i) => (