mail page rest dang

This commit is contained in:
alma 2025-04-21 16:21:51 +02:00
parent 784d673063
commit ca090f1ebb

View File

@ -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(/<style[^>]*>[\s\S]*?<\/style>/gi, '')
.replace(/<script[^>]*>[\s\S]*?<\/script>/gi, '')
.replace(/<meta[^>]*>/gi, '')
.replace(/<link[^>]*>/gi, '')
.replace(/<base[^>]*>/gi, '')
.replace(/<title[^>]*>[\s\S]*?<\/title>/gi, '')
.replace(/<head[^>]*>[\s\S]*?<\/head>/gi, '')
.replace(/<body[^>]*>/gi, '')
.replace(/<\/body>/gi, '')
.replace(/<html[^>]*>/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(/<style[^>]*>[\s\S]*?<\/style>/gi, '')
.replace(/<script[^>]*>[\s\S]*?<\/script>/gi, '')
.replace(/<meta[^>]*>/gi, '')
.replace(/<link[^>]*>/gi, '')
.replace(/<base[^>]*>/gi, '')
.replace(/<title[^>]*>[\s\S]*?<\/title>/gi, '')
.replace(/<head[^>]*>[\s\S]*?<\/head>/gi, '')
.replace(/<body[^>]*>/gi, '')
.replace(/<\/body>/gi, '')
.replace(/<html[^>]*>/gi, '')
.replace(/<\/html>/gi, '');
return (
<div className="email-content">
<div className="prose max-w-none" dangerouslySetInnerHTML={{ __html: cleanedContent }} />
<div className="prose max-w-none" dangerouslySetInnerHTML={{ __html: cleanedHtml }} />
</div>
);
} else {