diff --git a/app/courrier/page.tsx b/app/courrier/page.tsx index 4e73c8ef..fe1b15f6 100644 --- a/app/courrier/page.tsx +++ b/app/courrier/page.tsx @@ -272,41 +272,38 @@ function decodeMimeContent(content: string): string { function renderEmailContent(email: Email) { try { - // First try to parse the full email + // Parse the full email content const parsed = parseFullEmail(email.body); // If we have HTML content, display it if (parsed.html) { - const decodedHtml = decodeMIME(parsed.html, 'quoted-printable', 'utf-8'); return ( -
]*>[\s\S]*?<\/style>/gi, '') - .replace(/]*>[\s\S]*?<\/script>/gi, '') - .replace(/]*>/gi, '') - .replace(/]*>/gi, '') - .replace(/]*>/gi, '') - .replace(/]*>[\s\S]*?<\/title>/gi, '') - .replace(/]*>[\s\S]*?<\/head>/gi, '') - .replace(/]*>/gi, '') - .replace(/<\/body>/gi, '') - .replace(/]*>/gi, '') - .replace(/<\/html>/gi, '') - }} - /> +
+
]*>[\s\S]*?<\/style>/gi, '') + .replace(/]*>[\s\S]*?<\/script>/gi, '') + .replace(/]*>/gi, '') + .replace(/]*>/gi, '') + .replace(/]*>/gi, '') + .replace(/]*>[\s\S]*?<\/title>/gi, '') + .replace(/]*>[\s\S]*?<\/head>/gi, '') + .replace(/]*>/gi, '') + .replace(/<\/body>/gi, '') + .replace(/]*>/gi, '') + .replace(/<\/html>/gi, '') + }} + /> +
); } - // If we have text content, display it + // If we have text content, display it with proper formatting if (parsed.text) { - const decodedText = decodeMIME(parsed.text, 'quoted-printable', 'utf-8'); return ( -
- {decodedText.split('\n').map((line: string, i: number) => ( -

{line}

- ))} +
+ {parsed.text}
); } @@ -314,44 +311,53 @@ function renderEmailContent(email: Email) { // If we have attachments, display them if (parsed.attachments && parsed.attachments.length > 0) { return ( -
-

Attachments

-
- {parsed.attachments.map((attachment: { filename: string }, index: number) => ( -
- - - {attachment.filename} +
+
+ {parsed.attachments.map((attachment, index) => ( +
+ {attachment.filename} + + ({attachment.contentType})
))}
+ {parsed.body && ( +
+ {parsed.body} +
+ )}
); } - // If we couldn't parse the content, try to clean and display the raw body - const decodedBody = decodeMIME(email.body, 'quoted-printable', 'utf-8'); - const cleanedContent = decodedBody - .replace(/Content-Type:[^\n]+/g, '') - .replace(/Content-Transfer-Encoding:[^\n]+/g, '') - .replace(/MIME-Version:[^\n]+/g, '') - .replace(/--[a-zA-Z0-9]+(-[a-zA-Z0-9]+)?/g, '') - .replace(/boundary=[^\n]+/g, '') - .replace(/charset=[^\n]+/g, '') - .replace(/[\r\n]+/g, '\n') - .trim(); + // If parsing failed, try to clean and display the raw body + const cleanedBody = email.body + .replace(/Content-Type:.*?\r\n/g, '') + .replace(/Content-Transfer-Encoding:.*?\r\n/g, '') + .replace(/MIME-Version:.*?\r\n/g, '') + .replace(/--.*?--\r\n/g, '') + .replace(/--.*?\r\n/g, '') + .replace(/=\r\n/g, '') + .replace(/=3D/g, '=') + .replace(/=20/g, ' ') + .replace(/=09/g, '\t') + .replace(/=0A/g, '\n') + .replace(/=0D/g, '\r') + .replace(/=([0-9A-F]{2})/g, (_, hex) => String.fromCharCode(parseInt(hex, 16))); return ( -
- {cleanedContent.split('\n').map((line: string, i: number) => ( -

{line}

- ))} +
+ {cleanedBody} +
+ ); + } catch (error) { + console.error('Error rendering email content:', error); + return ( +
+ Unable to display email content
); - } catch (e) { - console.error('Error parsing email:', e); - return
Error displaying email content
; } }