From b983d5fdc927903e306cfc2b05db8096764594a8 Mon Sep 17 00:00:00 2001 From: alma Date: Mon, 21 Apr 2025 18:49:27 +0200 Subject: [PATCH] mail page fix --- app/courrier/page.tsx | 80 ++++++++++++++++++++----------------------- 1 file changed, 38 insertions(+), 42 deletions(-) diff --git a/app/courrier/page.tsx b/app/courrier/page.tsx index 5cde4257..b7d0a76c 100644 --- a/app/courrier/page.tsx +++ b/app/courrier/page.tsx @@ -134,10 +134,10 @@ function renderEmailContent(email: Email) { let htmlContent = ''; let textContent = ''; let attachments: { filename: string; content: string }[] = []; - - for (const part of parts) { - if (!part.trim()) continue; - + + for (const part of parts) { + if (!part.trim()) continue; + const [partHeaders, ...partBodyParts] = part.split('\r\n\r\n'); if (!partHeaders || partBodyParts.length === 0) continue; @@ -152,11 +152,11 @@ function renderEmailContent(email: Email) { decodedContent = decodeBase64(partBody, charset); } else if (encoding === 'quoted-printable') { decodedContent = decodeQuotedPrintable(partBody, charset); - } else { + } else { decodedContent = convertCharset(partBody, charset); } - if (contentType.includes('text/html')) { + if (contentType.includes('text/html')) { // For HTML content, we want to preserve the HTML structure // Only clean up problematic elements while keeping the formatting htmlContent = decodedContent @@ -225,23 +225,23 @@ function renderEmailContent(email: Email) { decodedBody = decodeBase64(body, charset); } else if (encoding === 'quoted-printable') { decodedBody = decodeQuotedPrintable(body, charset); - } else { + } else { decodedBody = convertCharset(body, charset); } if (contentType.includes('text/html')) { // For HTML content, preserve the HTML structure const cleanedHtml = decodedBody - .replace(/]*>[\s\S]*?<\/style>/gi, '') - .replace(/]*>[\s\S]*?<\/script>/gi, '') - .replace(/]*>/gi, '') - .replace(/]*>/gi, '') + .replace(/]*>[\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(/]*>[\s\S]*?<\/title>/gi, '') + .replace(/]*>[\s\S]*?<\/head>/gi, '') + .replace(/]*>/gi, '') + .replace(/<\/body>/gi, '') + .replace(/]*>/gi, '') .replace(/<\/html>/gi, ''); return ( @@ -252,13 +252,13 @@ function renderEmailContent(email: Email) { } else { return (
-
+
{decodedBody.split('\n').map((line: string, i: number) => ( -

{line}

- ))} -
+

{line}

+ ))}
- ); +
+ ); } } catch (decodeError) { console.error('Error decoding email body:', decodeError); @@ -398,24 +398,20 @@ function getReplyBody(email: Email, type: 'reply' | 'reply-all' | 'forward'): st if (type === 'forward') { return ` -

{email.subject || '(No subject)'} @@ -1152,7 +1148,7 @@ export default function CourrierPage() { // Parse headers using our MIME decoder const headerInfo = parseEmailHeaders(headersPart); const boundary = extractBoundary(headersPart); - + let preview = ''; // If it's a multipart email @@ -1382,7 +1378,7 @@ export default function CourrierPage() { const getReplyTo = () => { if (type === 'forward') return ''; - return selectedEmail.from; + return selectedEmail.from; }; const getReplyCc = () => { @@ -1392,7 +1388,7 @@ export default function CourrierPage() { const getReplySubject = () => { const subject = selectedEmail.subject || ''; - if (type === 'forward') { + if (type === 'forward') { return subject.startsWith('Fwd:') ? subject : `Fwd: ${subject}`; } return subject.startsWith('Re:') ? subject : `Re: ${subject}`;