mail page rest
This commit is contained in:
parent
0cd481ac09
commit
850ad73244
@ -301,50 +301,41 @@ function decodeMimeContent(content: string): string {
|
|||||||
|
|
||||||
function renderEmailContent(email: Email) {
|
function renderEmailContent(email: Email) {
|
||||||
try {
|
try {
|
||||||
// First, parse the email headers
|
// Parse the full email content
|
||||||
const headers = parseEmailHeaders(email.body);
|
const parsed = parseFullEmail(email.body);
|
||||||
|
|
||||||
// Get the content type and encoding
|
// If we have HTML content, render it
|
||||||
const contentType = headers.contentType || '';
|
if (parsed.html) {
|
||||||
const encoding = headers.encoding || '7bit';
|
|
||||||
const charset = headers.charset || 'utf-8';
|
|
||||||
|
|
||||||
// Split the email into headers and body
|
|
||||||
const [headerPart, ...bodyParts] = email.body.split('\r\n\r\n');
|
|
||||||
const body = bodyParts.join('\r\n\r\n');
|
|
||||||
|
|
||||||
// Decode the content based on encoding
|
|
||||||
let decodedContent = body;
|
|
||||||
if (encoding.toLowerCase() === 'quoted-printable') {
|
|
||||||
decodedContent = decodeQuotedPrintable(body, charset);
|
|
||||||
} else if (encoding.toLowerCase() === 'base64') {
|
|
||||||
decodedContent = decodeBase64(body, charset);
|
|
||||||
}
|
|
||||||
|
|
||||||
// If it's HTML content, clean and render it
|
|
||||||
if (contentType.includes('text/html')) {
|
|
||||||
const cleanedHtml = cleanHtml(decodedContent);
|
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
className="prose max-w-none"
|
className="prose max-w-none"
|
||||||
dangerouslySetInnerHTML={{ __html: cleanedHtml }}
|
dangerouslySetInnerHTML={{ __html: parsed.html }}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// If it's plain text, render it with proper formatting
|
// If we have text content, render it with proper formatting
|
||||||
if (contentType.includes('text/plain')) {
|
if (parsed.text) {
|
||||||
return (
|
return (
|
||||||
<div className="whitespace-pre-wrap font-sans text-base leading-relaxed">
|
<div className="whitespace-pre-wrap font-sans text-base leading-relaxed">
|
||||||
{decodedContent.split('\n').map((line, i) => (
|
{parsed.text.split('\n').map((line, i) => (
|
||||||
<p key={i} className="mb-2">{line}</p>
|
<p key={i} className="mb-2">{line}</p>
|
||||||
))}
|
))}
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// If we couldn't determine the content type, try to clean and display the content
|
// If we have attachments but no content, show a message
|
||||||
const cleanedContent = cleanHtml(decodedContent);
|
if (parsed.attachments.length > 0) {
|
||||||
|
return (
|
||||||
|
<div className="text-muted-foreground">
|
||||||
|
This email contains {parsed.attachments.length} attachment{parsed.attachments.length > 1 ? 's' : ''}.
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// If we couldn't parse the content, try to clean and display it
|
||||||
|
const cleanedContent = cleanHtml(email.body);
|
||||||
return (
|
return (
|
||||||
<div className="whitespace-pre-wrap font-sans text-base leading-relaxed">
|
<div className="whitespace-pre-wrap font-sans text-base leading-relaxed">
|
||||||
{cleanedContent.split('\n').map((line, i) => (
|
{cleanedContent.split('\n').map((line, i) => (
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user