mail page rest
This commit is contained in:
parent
312577bbca
commit
6e266b3dba
@ -452,20 +452,20 @@ const renderEmailContent = (email: Email) => {
|
|||||||
console.log('First 200 chars of body:', email.body.substring(0, 200));
|
console.log('First 200 chars of body:', email.body.substring(0, 200));
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const parsed = parseFullEmail(email.body);
|
const parsed = parseFullEmail(email.body) as ParsedEmailContent;
|
||||||
console.log('Parsed content:', {
|
console.log('Parsed content:', {
|
||||||
hasText: 'text' in parsed ? !!parsed.text : false,
|
hasText: !!parsed.text,
|
||||||
hasHtml: 'html' in parsed ? !!parsed.html : false,
|
hasHtml: !!parsed.html,
|
||||||
textPreview: 'text' in parsed ? parsed.text?.substring(0, 100) : 'No text',
|
textPreview: parsed.text?.substring(0, 100) || 'No text',
|
||||||
htmlPreview: 'html' in parsed ? parsed.html?.substring(0, 100) : 'No HTML'
|
htmlPreview: parsed.html?.substring(0, 100) || 'No HTML'
|
||||||
});
|
});
|
||||||
|
|
||||||
const content = 'text' in parsed ? parsed.text : ('html' in parsed ? parsed.html || '' : email.body);
|
const isHtml = !!parsed.html || email.body.includes('<');
|
||||||
|
const content = parsed.text || parsed.html || email.body;
|
||||||
|
|
||||||
console.log('Selected content type:', isHtml ? 'HTML' : 'Plain text');
|
console.log('Selected content type:', isHtml ? 'HTML' : 'Plain text');
|
||||||
console.log('Content preview:', content.substring(0, 100) + '...');
|
console.log('Content preview:', content.substring(0, 100) + '...');
|
||||||
|
|
||||||
const isHtml = 'html' in parsed ? !!parsed.html : content.includes('<');
|
|
||||||
|
|
||||||
if (isHtml) {
|
if (isHtml) {
|
||||||
// Enhanced HTML sanitization
|
// Enhanced HTML sanitization
|
||||||
const sanitizedHtml = content
|
const sanitizedHtml = content
|
||||||
@ -497,7 +497,7 @@ const renderEmailContent = (email: Email) => {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="prose prose-sm max-w-none">
|
<div className="prose prose-sm max-w-none">
|
||||||
{'attachments' in parsed && parsed.attachments && parsed.attachments.length > 0 && (
|
{parsed.attachments && parsed.attachments.length > 0 && (
|
||||||
<div className="mb-4 p-2 bg-gray-50 rounded">
|
<div className="mb-4 p-2 bg-gray-50 rounded">
|
||||||
<h4 className="text-sm font-medium mb-2">Attachments:</h4>
|
<h4 className="text-sm font-medium mb-2">Attachments:</h4>
|
||||||
<div className="space-y-1">
|
<div className="space-y-1">
|
||||||
@ -542,7 +542,7 @@ const renderEmailContent = (email: Email) => {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="prose prose-sm max-w-none whitespace-pre-wrap">
|
<div className="prose prose-sm max-w-none whitespace-pre-wrap">
|
||||||
{'attachments' in parsed && parsed.attachments && parsed.attachments.length > 0 && (
|
{parsed.attachments && parsed.attachments.length > 0 && (
|
||||||
<div className="mb-4 p-2 bg-gray-50 rounded">
|
<div className="mb-4 p-2 bg-gray-50 rounded">
|
||||||
<h4 className="text-sm font-medium mb-2">Attachments:</h4>
|
<h4 className="text-sm font-medium mb-2">Attachments:</h4>
|
||||||
<div className="space-y-1">
|
<div className="space-y-1">
|
||||||
@ -1293,7 +1293,72 @@ export default function MailPage() {
|
|||||||
htmlPreview: 'html' in parsed ? parsed.html?.substring(0, 100) : 'No HTML'
|
htmlPreview: 'html' in parsed ? parsed.html?.substring(0, 100) : 'No HTML'
|
||||||
});
|
});
|
||||||
|
|
||||||
// ... rest of the function ...
|
let preview = '';
|
||||||
|
if ('text' in parsed && parsed.text) {
|
||||||
|
preview = parsed.text;
|
||||||
|
console.log('Using text content for preview');
|
||||||
|
} else if ('html' in parsed && parsed.html) {
|
||||||
|
preview = parsed.html
|
||||||
|
.replace(/<style[^>]*>[\s\S]*?<\/style>/gi, '')
|
||||||
|
.replace(/<script[^>]*>[\s\S]*?<\/script>/gi, '')
|
||||||
|
.replace(/<[^>]+>/g, ' ')
|
||||||
|
.replace(/\s+/g, ' ')
|
||||||
|
.trim();
|
||||||
|
console.log('Using HTML content for preview');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!preview) {
|
||||||
|
console.log('No preview from parsed content, using raw body');
|
||||||
|
preview = email.body
|
||||||
|
.replace(/<[^>]+>/g, ' ')
|
||||||
|
.replace(/ |‌|»|«|>/g, ' ')
|
||||||
|
.replace(/\s+/g, ' ')
|
||||||
|
.trim();
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log('Final preview before cleaning:', preview.substring(0, 100) + '...');
|
||||||
|
|
||||||
|
// Clean up the preview
|
||||||
|
preview = preview
|
||||||
|
.replace(/^>+/gm, '')
|
||||||
|
.replace(/Content-Type:[^\n]+/g, '')
|
||||||
|
.replace(/Content-Transfer-Encoding:[^\n]+/g, '')
|
||||||
|
.replace(/--[a-zA-Z0-9]+(-[a-zA-Z0-9]+)?/g, '')
|
||||||
|
.replace(/boundary=[^\n]+/g, '')
|
||||||
|
.replace(/charset=[^\n]+/g, '')
|
||||||
|
.replace(/[\r\n]+/g, ' ')
|
||||||
|
.replace(/=3D/g, '=')
|
||||||
|
.replace(/=20/g, ' ')
|
||||||
|
.replace(/=E2=80=99/g, "'")
|
||||||
|
.replace(/=E2=80=9C/g, '"')
|
||||||
|
.replace(/=E2=80=9D/g, '"')
|
||||||
|
.replace(/=E2=80=93/g, '–')
|
||||||
|
.replace(/=E2=80=94/g, '—')
|
||||||
|
.replace(/=C2=A0/g, ' ')
|
||||||
|
.replace(/=C3=A0/g, 'à')
|
||||||
|
.replace(/=C3=A9/g, 'é')
|
||||||
|
.replace(/=C3=A8/g, 'è')
|
||||||
|
.replace(/=C3=AA/g, 'ê')
|
||||||
|
.replace(/=C3=AB/g, 'ë')
|
||||||
|
.replace(/=C3=B4/g, 'ô')
|
||||||
|
.replace(/=C3=B9/g, 'ù')
|
||||||
|
.replace(/=C3=BB/g, 'û')
|
||||||
|
.trim();
|
||||||
|
|
||||||
|
// Take first 100 characters
|
||||||
|
preview = preview.substring(0, 100);
|
||||||
|
|
||||||
|
// Try to end at a complete word
|
||||||
|
if (preview.length === 100) {
|
||||||
|
const lastSpace = preview.lastIndexOf(' ');
|
||||||
|
if (lastSpace > 80) {
|
||||||
|
preview = preview.substring(0, lastSpace);
|
||||||
|
}
|
||||||
|
preview += '...';
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log('Final preview:', preview);
|
||||||
|
return preview || 'No preview available';
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error('Error in generateEmailPreview:', e);
|
console.error('Error in generateEmailPreview:', e);
|
||||||
return 'Error generating preview';
|
return 'Error generating preview';
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user