Neah version mail design fix 3 ???

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

View File

@ -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(/<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
const parsed = parseFullEmail(email.body);
// Try to get content from parsed email
preview = (parsed.text || parsed.html || '')
.replace(/<style[^>]*>[\s\S]*?<\/style>/gi, '')
.replace(/<script[^>]*>[\s\S]*?<\/script>/gi, '')
.replace(/<[^>]+>/g, '')
.replace(/&nbsp;|&zwnj;|&raquo;|&laquo;|&gt;/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(/&nbsp;|&zwnj;|&raquo;|&laquo;|&gt;/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 = '';