diff --git a/app/mail/page.tsx b/app/mail/page.tsx index 7875a4c..9a671a0 100644 --- a/app/mail/page.tsx +++ b/app/mail/page.tsx @@ -1127,7 +1127,52 @@ export default function MailPage() { {email.subject || '(No subject)'}
- --{email.id.toString().substring(0, 32)}... + {(() => { + // 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 + .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; + } + + // Take first 100 characters + preview = preview.substring(0, 100); + + // If preview ends with a partial word, try to end at the last complete word + if (preview.length === 100) { + const lastSpace = preview.lastIndexOf(' '); + if (lastSpace > 80) { // Only trim if we can keep most of the preview + preview = preview.substring(0, lastSpace); + } + preview += '...'; + } + } catch (e) { + console.error('Error generating preview:', e); + preview = ''; + } + + return preview || 'No preview available'; + })()}