From 1e0b24e74e62259c49de72697c7acd90bdf6ccd8 Mon Sep 17 00:00:00 2001 From: alma Date: Wed, 16 Apr 2025 18:32:27 +0200 Subject: [PATCH] Neah version mail design fix 3 ??? --- app/mail/page.tsx | 52 +++++++++++++++++++++++++++-------------------- 1 file changed, 30 insertions(+), 22 deletions(-) diff --git a/app/mail/page.tsx b/app/mail/page.tsx index 9a671a0..1873440 100644 --- a/app/mail/page.tsx +++ b/app/mail/page.tsx @@ -1131,41 +1131,49 @@ export default function MailPage() { // Get clean preview of the actual message content let preview = ''; try { - // First try to get content from the body - preview = email.body - .replace(/]*>[\s\S]*?<\/style>/gi, '') // Remove style tags and content - .replace(/]*>[\s\S]*?<\/script>/gi, '') // Remove script tags and content - .replace(/<[^>]+>/g, '') // Remove remaining HTML tags - .replace(/ |‌|»|«|>/g, ' ') // Replace common entities - .replace(/\s+/g, ' ') // Normalize whitespace + const parsed = parseFullEmail(email.body); + + // Try to get content from parsed email + preview = (parsed.text || parsed.html || '') + .replace(/]*>[\s\S]*?<\/style>/gi, '') + .replace(/]*>[\s\S]*?<\/script>/gi, '') + .replace(/<[^>]+>/g, '') + .replace(/ |‌|»|«|>/g, ' ') + .replace(/\s+/g, ' ') .trim(); - // Remove common email artifacts - preview = preview - .replace(/^>+/gm, '') // Remove quote markers - .replace(/^\s*(?:--|__)?(?:Original Message|Forwarded Message)(?:--|__)?\s*$[\s\S]*$/im, '') // Remove forwarded message headers - .replace(/^[0-9a-f]{32,}/gm, '') // Remove hex strings - .replace(/^https?:\/\/\S+$/gm, '') // Remove URLs - .replace(/^#[a-zA-Z0-9-_]+$/gm, '') // Remove hashtags - .replace(/^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/gm, '') // Remove email addresses - .trim(); - - // If still no valid preview, try subject - if (!preview || preview.length < 5) { - preview = email.subject; + // If no preview from parsed content, try direct body + if (!preview) { + preview = email.body + .replace(/<[^>]+>/g, '') + .replace(/ |‌|»|«|>/g, ' ') + .replace(/\s+/g, ' ') + .trim(); } + // Remove email artifacts and clean up + 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, ' ') + .trim(); + // Take first 100 characters preview = preview.substring(0, 100); - // If preview ends with a partial word, try to end at the last complete word + // Try to end at a complete word if (preview.length === 100) { const lastSpace = preview.lastIndexOf(' '); - if (lastSpace > 80) { // Only trim if we can keep most of the preview + if (lastSpace > 80) { preview = preview.substring(0, lastSpace); } preview += '...'; } + } catch (e) { console.error('Error generating preview:', e); preview = '';