diff --git a/app/courrier/page.tsx b/app/courrier/page.tsx index 146dca20..d9dfc7fb 100644 --- a/app/courrier/page.tsx +++ b/app/courrier/page.tsx @@ -74,6 +74,13 @@ interface Attachment { interface ParsedEmailContent { headers: string; body: string; + html?: string; + text?: string; + attachments?: Array<{ + filename: string; + content: string; + contentType: string; + }>; } interface ParsedEmailMetadata { @@ -245,89 +252,79 @@ function decodeMimeContent(content: string): string { } function renderEmailContent(email: Email) { - console.log('=== renderEmailContent Debug ==='); - console.log('Email ID:', email.id); - console.log('Subject:', email.subject); - console.log('Body length:', email.body.length); - 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.body, - hasHtml: !!parsed.headers, - hasAttachments: parsed.headers.length > 0 - }); - - // Determine content and type - let content = ''; - let isHtml = false; - - if (parsed.headers) { - // Use our existing MIME decoding for HTML content - content = decodeMIME(parsed.headers, 'quoted-printable', 'utf-8'); - isHtml = true; - } else if (parsed.body) { - // Use our existing MIME decoding for plain text content - content = decodeMIME(parsed.body, 'quoted-printable', 'utf-8'); - isHtml = false; - } else { - // Try to extract content directly from body using our existing functions - const htmlMatch = email.body.match(/]*>[\s\S]*?<\/html>/i); - if (htmlMatch) { - content = decodeMIME(htmlMatch[0], 'quoted-printable', 'utf-8'); - isHtml = true; - } else { - // Use our existing text extraction function - content = extractTextFromHtml(email.body); - isHtml = false; - } + + // If we have HTML content, display it + if (parsed.html) { + return ( +