mail page rest
This commit is contained in:
parent
0de5f61bce
commit
1bfa98dcfd
@ -144,7 +144,9 @@ function parseFullEmail(emailRaw: string): ParsedEmailContent {
|
||||
|
||||
// Handle multipart content
|
||||
if (contentType.includes('multipart')) {
|
||||
const boundaryMatch = emailRaw.match(/boundary="?([^"\r\n;]+)"?/i);
|
||||
const boundaryMatch = emailRaw.match(/boundary="?([^"\r\n;]+)"?/i) ||
|
||||
emailRaw.match(/boundary=([^\r\n;]+)/i);
|
||||
|
||||
if (boundaryMatch) {
|
||||
const boundary = boundaryMatch[1].trim();
|
||||
const parts = emailRaw.split(new RegExp(`--${boundary}(?:--)?(\\r?\\n|$)`));
|
||||
@ -438,88 +440,58 @@ function decodeMimeContent(content: string): string {
|
||||
return cleanHtml(content);
|
||||
}
|
||||
|
||||
// Add this helper function
|
||||
const renderEmailContent = (email: Email) => {
|
||||
function renderEmailContent(email: Email) {
|
||||
console.log('=== renderEmailContent Debug ===');
|
||||
console.log('Email ID:', email.id);
|
||||
console.log('Subject:', email.subject);
|
||||
console.log('Body length:', email.body.length);
|
||||
console.log('First 200 chars of body:', email.body.substring(0, 200));
|
||||
console.log('First 100 chars:', email.body.substring(0, 100));
|
||||
|
||||
try {
|
||||
const parsed = parseFullEmail(email.body);
|
||||
console.log('Parsed content:', {
|
||||
hasText: !!parsed.text,
|
||||
hasHtml: !!parsed.html,
|
||||
textPreview: parsed.text?.substring(0, 100) || 'No text',
|
||||
htmlPreview: parsed.html?.substring(0, 100) || 'No HTML'
|
||||
});
|
||||
const parsedContent = parseFullEmail(email.body);
|
||||
console.log('Parsed content:', {
|
||||
hasText: !!parsedContent.text,
|
||||
hasHtml: !!parsedContent.html,
|
||||
hasAttachments: parsedContent.attachments.length > 0
|
||||
});
|
||||
|
||||
const content = parsed.html || parsed.text || email.body;
|
||||
const isHtml = !!parsed.html;
|
||||
// Determine content type
|
||||
const isHtml = parsedContent.html !== null;
|
||||
const content = isHtml ? parsedContent.html : parsedContent.text;
|
||||
|
||||
console.log('Selected content type:', isHtml ? 'HTML' : 'Plain text');
|
||||
console.log('Content preview:', content.substring(0, 100) + '...');
|
||||
|
||||
if (isHtml) {
|
||||
return (
|
||||
<div className="prose prose-sm max-w-none">
|
||||
{parsed.attachments.length > 0 && (
|
||||
<div className="mb-4 p-2 bg-gray-50 rounded">
|
||||
<h4 className="text-sm font-medium mb-2">Attachments:</h4>
|
||||
<div className="space-y-1">
|
||||
{parsed.attachments.map((attachment, index) => (
|
||||
<div key={index} className="flex items-center gap-2 text-sm">
|
||||
<Paperclip className="h-4 w-4 text-gray-500" />
|
||||
<span>{attachment.filename}</span>
|
||||
<span className="text-gray-500 text-xs">
|
||||
({attachment.contentType})
|
||||
</span>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
<div dangerouslySetInnerHTML={{ __html: content }} />
|
||||
</div>
|
||||
);
|
||||
} else {
|
||||
return (
|
||||
<div className="prose prose-sm max-w-none whitespace-pre-wrap">
|
||||
{parsed.attachments.length > 0 && (
|
||||
<div className="mb-4 p-2 bg-gray-50 rounded">
|
||||
<h4 className="text-sm font-medium mb-2">Attachments:</h4>
|
||||
<div className="space-y-1">
|
||||
{parsed.attachments.map((attachment, index) => (
|
||||
<div key={index} className="flex items-center gap-2 text-sm">
|
||||
<Paperclip className="h-4 w-4 text-gray-500" />
|
||||
<span>{attachment.filename}</span>
|
||||
<span className="text-gray-500 text-xs">
|
||||
({attachment.contentType})
|
||||
</span>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
<div>{content}</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
} catch (e) {
|
||||
console.error('Error in renderEmailContent:', e);
|
||||
return (
|
||||
<div className="text-sm text-gray-500">
|
||||
Error rendering email content. Please try refreshing the page.
|
||||
</div>
|
||||
);
|
||||
if (!content) {
|
||||
console.log('No content available');
|
||||
return <div className="text-gray-500">No content available</div>;
|
||||
}
|
||||
};
|
||||
|
||||
// Add this helper function
|
||||
const decodeEmailContent = (content: string, charset: string = 'utf-8') => {
|
||||
return convertCharset(content, charset);
|
||||
};
|
||||
// Clean and sanitize content
|
||||
const sanitizedContent = isHtml ?
|
||||
cleanEmailContent(content) :
|
||||
content.replace(/&/g, '&')
|
||||
.replace(/</g, '<')
|
||||
.replace(/>/g, '>')
|
||||
.replace(/\n/g, '<br>');
|
||||
|
||||
// Handle attachments
|
||||
const attachmentElements = parsedContent.attachments.map((attachment, index) => (
|
||||
<div key={index} className="mt-4 p-4 border rounded-lg bg-gray-50">
|
||||
<div className="flex items-center">
|
||||
<Paperclip className="h-5 w-5 text-gray-400 mr-2" />
|
||||
<span className="text-sm text-gray-600">{attachment.filename}</span>
|
||||
</div>
|
||||
</div>
|
||||
));
|
||||
|
||||
return (
|
||||
<div className="prose max-w-none">
|
||||
{isHtml ? (
|
||||
<div dangerouslySetInnerHTML={{ __html: sanitizedContent }} />
|
||||
) : (
|
||||
<div className="whitespace-pre-wrap">{sanitizedContent}</div>
|
||||
)}
|
||||
{attachmentElements}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function cleanEmailContent(content: string): string {
|
||||
// Remove or fix malformed URLs
|
||||
|
||||
Loading…
Reference in New Issue
Block a user