From ca090f1ebbd821de5583b16234756fdb13544553 Mon Sep 17 00:00:00 2001 From: alma Date: Mon, 21 Apr 2025 16:21:51 +0200 Subject: [PATCH] mail page rest dang --- app/courrier/page.tsx | 63 ++++++++++++++++++++++++++++++++----------- 1 file changed, 47 insertions(+), 16 deletions(-) diff --git a/app/courrier/page.tsx b/app/courrier/page.tsx index 36c2a53d..7da31660 100644 --- a/app/courrier/page.tsx +++ b/app/courrier/page.tsx @@ -131,28 +131,41 @@ function renderEmailContent(email: Email) { if (!partHeaders || partBodyParts.length === 0) continue; const partBody = partBodyParts.join('\r\n\r\n'); - const partHeaderInfo = parseEmailHeaders(partHeaders); const contentType = extractHeader(partHeaders, 'Content-Type').toLowerCase(); const encoding = extractHeader(partHeaders, 'Content-Transfer-Encoding').toLowerCase(); const charset = extractHeader(partHeaders, 'charset') || 'utf-8'; try { + let decodedContent = ''; + if (encoding === 'base64') { + decodedContent = decodeBase64(partBody, charset); + } else if (encoding === 'quoted-printable') { + decodedContent = decodeQuotedPrintable(partBody, charset); + } else { + decodedContent = convertCharset(partBody, charset); + } + if (contentType.includes('text/html')) { - const decodedContent = encoding === 'base64' - ? decodeBase64(partBody, charset) - : decodeQuotedPrintable(partBody, charset); - htmlContent = cleanHtml(decodedContent); + // For HTML content, we want to preserve the HTML structure + // Only clean up problematic elements while keeping the formatting + htmlContent = decodedContent + .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(/<\/html>/gi, ''); } else if (contentType.includes('text/plain')) { - const decodedContent = encoding === 'base64' - ? decodeBase64(partBody, charset) - : decodeQuotedPrintable(partBody, charset); textContent = decodedContent; } else if (contentType.includes('attachment') || extractHeader(partHeaders, 'Content-Disposition').includes('attachment')) { attachments.push({ filename: extractFilename(partHeaders) || 'unnamed_attachment', - content: encoding === 'base64' - ? decodeBase64(partBody, charset) - : decodeQuotedPrintable(partBody, charset) + content: decodedContent }); } } catch (partError) { @@ -196,15 +209,33 @@ function renderEmailContent(email: Email) { const charset = extractHeader(headersPart, 'charset') || 'utf-8'; try { - const decodedBody = encoding === 'base64' - ? decodeBase64(body, charset) - : decodeQuotedPrintable(body, charset); + let decodedBody = ''; + if (encoding === 'base64') { + decodedBody = decodeBase64(body, charset); + } else if (encoding === 'quoted-printable') { + decodedBody = decodeQuotedPrintable(body, charset); + } else { + decodedBody = convertCharset(body, charset); + } if (contentType.includes('text/html')) { - const cleanedContent = cleanHtml(decodedBody); + // 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(/]*>/gi, '') + .replace(/]*>[\s\S]*?<\/title>/gi, '') + .replace(/]*>[\s\S]*?<\/head>/gi, '') + .replace(/]*>/gi, '') + .replace(/<\/body>/gi, '') + .replace(/]*>/gi, '') + .replace(/<\/html>/gi, ''); + return (
-
+
); } else {