mail page rest
This commit is contained in:
parent
d88ffc12da
commit
28612fb39e
@ -436,7 +436,7 @@ function cleanHtml(html: string): string {
|
||||
function decodeMimeContent(content: string): string {
|
||||
if (!content) return '';
|
||||
|
||||
// Check if this is an Infomaniak multipart message
|
||||
// Check if this is a multipart message
|
||||
if (content.includes('Content-Type: multipart/')) {
|
||||
const boundary = content.match(/boundary="([^"]+)"/)?.[1];
|
||||
if (boundary) {
|
||||
@ -474,93 +474,42 @@ function renderEmailContent(email: Email) {
|
||||
console.log('Body length:', email.body.length);
|
||||
console.log('First 100 chars:', email.body.substring(0, 100));
|
||||
|
||||
const parsedContent = parseFullEmail(email.body);
|
||||
console.log('Parsed content:', {
|
||||
hasText: !!parsedContent.text,
|
||||
hasHtml: !!parsedContent.html,
|
||||
hasAttachments: parsedContent.attachments.length > 0
|
||||
});
|
||||
try {
|
||||
const parsed = parseFullEmail(email.body);
|
||||
console.log('Parsed content:', {
|
||||
hasText: !!parsed.text,
|
||||
hasHtml: !!parsed.html,
|
||||
hasAttachments: parsed.attachments.length > 0
|
||||
});
|
||||
|
||||
// Determine content type and get content
|
||||
let content = null;
|
||||
let isHtml = false;
|
||||
|
||||
if (parsedContent.html) {
|
||||
content = parsedContent.html;
|
||||
isHtml = true;
|
||||
} else if (parsedContent.text) {
|
||||
content = parsedContent.text;
|
||||
isHtml = false;
|
||||
}
|
||||
|
||||
if (!content) {
|
||||
console.log('No content available from parsing, trying direct body');
|
||||
// Try to extract content directly from body
|
||||
const htmlMatch = email.body.match(/<html[^>]*>[\s\S]*?<\/html>/i);
|
||||
if (htmlMatch) {
|
||||
content = htmlMatch[0];
|
||||
isHtml = true;
|
||||
} else {
|
||||
content = email.body
|
||||
.replace(/<[^>]+>/g, '')
|
||||
.replace(/ /g, ' ')
|
||||
.replace(/&/g, '&')
|
||||
.replace(/</g, '<')
|
||||
.replace(/>/g, '>')
|
||||
.replace(/"/g, '"')
|
||||
.replace(/\r\n/g, '\n')
|
||||
.replace(/=\n/g, '')
|
||||
.replace(/=3D/g, '=')
|
||||
.replace(/=09/g, '\t')
|
||||
.trim();
|
||||
isHtml = false;
|
||||
// Display HTML content if available, otherwise fallback to text
|
||||
const content = parsed.html || parsed.text || decodeMimeContent(email.body);
|
||||
|
||||
if (!content) {
|
||||
console.log('No content available after all attempts');
|
||||
return <div className="text-gray-500">No content available</div>;
|
||||
}
|
||||
}
|
||||
|
||||
if (!content) {
|
||||
console.log('No content available after all attempts');
|
||||
return <div className="text-gray-500">No content available</div>;
|
||||
}
|
||||
|
||||
// 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>
|
||||
// Handle attachments
|
||||
const attachmentElements = parsed.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>
|
||||
</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
|
||||
return content.replace(/=3D"(http[^"]+)"/g, (match, url) => {
|
||||
try {
|
||||
return `"${decodeURIComponent(url)}"`;
|
||||
} catch {
|
||||
return '';
|
||||
}
|
||||
});
|
||||
return (
|
||||
<div className="prose max-w-none">
|
||||
<div dangerouslySetInnerHTML={{ __html: content }} />
|
||||
{attachmentElements}
|
||||
</div>
|
||||
);
|
||||
} catch (e) {
|
||||
console.error('Error parsing email:', e);
|
||||
return <div className="text-gray-500">Error displaying email content</div>;
|
||||
}
|
||||
}
|
||||
|
||||
// Define the exact folder names from IMAP
|
||||
|
||||
Loading…
Reference in New Issue
Block a user