diff --git a/app/mail/page.tsx b/app/mail/page.tsx index 703f8771..15149676 100644 --- a/app/mail/page.tsx +++ b/app/mail/page.tsx @@ -301,53 +301,50 @@ function decodeMimeContent(content: string): string { function renderEmailContent(email: Email) { try { - // First, parse the full email to get headers and body - const parsed = parseFullEmail(email.body); + // First, parse the email headers + const headers = parseEmailHeaders(email.body); - // If we have HTML content, render it - if (parsed.html) { + // Get the content type and encoding + const contentType = headers.contentType || ''; + const encoding = headers.encoding || '7bit'; + const charset = headers.charset || 'utf-8'; + + // 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); return (
); } - - // If we have text content, render it - if (parsed.text) { + + // If it's plain text, render it with proper formatting + if (contentType.includes('text/plain')) { return ({line}
))}