Neah version mail design fix 3 ??

This commit is contained in:
alma 2025-04-16 18:27:37 +02:00
parent 1be9b35d01
commit 0e6a1372e5

View File

@ -1127,7 +1127,52 @@ export default function MailPage() {
{email.subject || '(No subject)'}
</h3>
<div className="text-xs text-gray-500 truncate">
--{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(/<style[^>]*>[\s\S]*?<\/style>/gi, '') // Remove style tags and content
.replace(/<script[^>]*>[\s\S]*?<\/script>/gi, '') // Remove script tags and content
.replace(/<[^>]+>/g, '') // Remove remaining HTML tags
.replace(/&nbsp;|&zwnj;|&raquo;|&laquo;|&gt;/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';
})()}
</div>
</div>
</div>