mail page rest
This commit is contained in:
parent
59c7260b9a
commit
0cd481ac09
@ -301,53 +301,50 @@ function decodeMimeContent(content: string): string {
|
||||
|
||||
function renderEmailContent(email: Email) {
|
||||
try {
|
||||
// First, parse the full email to get headers and body
|
||||
const parsed = parseFullEmail(email.body);
|
||||
// First, parse the email headers
|
||||
const headers = parseEmailHeaders(email.body);
|
||||
|
||||
// If we have HTML content, render it
|
||||
if (parsed.html) {
|
||||
// Get the content type and encoding
|
||||
const contentType = headers.contentType || '';
|
||||
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 (
|
||||
<div
|
||||
className="prose max-w-none"
|
||||
dangerouslySetInnerHTML={{ __html: parsed.html }}
|
||||
dangerouslySetInnerHTML={{ __html: cleanedHtml }}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
// If we have text content, render it
|
||||
if (parsed.text) {
|
||||
|
||||
// If it's plain text, render it with proper formatting
|
||||
if (contentType.includes('text/plain')) {
|
||||
return (
|
||||
<div className="whitespace-pre-wrap font-sans text-base leading-relaxed">
|
||||
{parsed.text.split('\n').map((line, i) => (
|
||||
{decodedContent.split('\n').map((line, i) => (
|
||||
<p key={i} className="mb-2">{line}</p>
|
||||
))}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
// If we have attachments, display them
|
||||
if (parsed.attachments && parsed.attachments.length > 0) {
|
||||
return (
|
||||
<div className="mt-6 border-t border-gray-200 pt-6">
|
||||
<h3 className="text-sm font-semibold text-gray-900 mb-4">Attachments</h3>
|
||||
<div className="space-y-2">
|
||||
{parsed.attachments.map((attachment, index) => (
|
||||
<div key={index} className="flex items-center space-x-2 p-2 border rounded">
|
||||
<Paperclip className="h-4 w-4 text-gray-400" />
|
||||
<span className="text-sm text-gray-600 truncate">
|
||||
{attachment.filename}
|
||||
</span>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
// If we couldn't parse the content, try to decode and clean the raw body
|
||||
const decodedBody = decodeMIME(email.body, 'quoted-printable', 'utf-8');
|
||||
const cleanedContent = cleanHtml(decodedBody);
|
||||
|
||||
// If we couldn't determine the content type, try to clean and display the content
|
||||
const cleanedContent = cleanHtml(decodedContent);
|
||||
return (
|
||||
<div className="whitespace-pre-wrap font-sans text-base leading-relaxed">
|
||||
{cleanedContent.split('\n').map((line, i) => (
|
||||
|
||||
Loading…
Reference in New Issue
Block a user