Neah version mail design fix 3 ???
This commit is contained in:
parent
0e6a1372e5
commit
1e0b24e74e
@ -1131,41 +1131,49 @@ export default function MailPage() {
|
|||||||
// Get clean preview of the actual message content
|
// Get clean preview of the actual message content
|
||||||
let preview = '';
|
let preview = '';
|
||||||
try {
|
try {
|
||||||
// First try to get content from the body
|
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(/ |‌|»|«|>/g, ' ')
|
||||||
|
.replace(/\s+/g, ' ')
|
||||||
|
.trim();
|
||||||
|
|
||||||
|
// If no preview from parsed content, try direct body
|
||||||
|
if (!preview) {
|
||||||
preview = email.body
|
preview = email.body
|
||||||
.replace(/<style[^>]*>[\s\S]*?<\/style>/gi, '') // Remove style tags and content
|
.replace(/<[^>]+>/g, '')
|
||||||
.replace(/<script[^>]*>[\s\S]*?<\/script>/gi, '') // Remove script tags and content
|
.replace(/ |‌|»|«|>/g, ' ')
|
||||||
.replace(/<[^>]+>/g, '') // Remove remaining HTML tags
|
.replace(/\s+/g, ' ')
|
||||||
.replace(/ |‌|»|«|>/g, ' ') // Replace common entities
|
|
||||||
.replace(/\s+/g, ' ') // Normalize whitespace
|
|
||||||
.trim();
|
.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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 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
|
// Take first 100 characters
|
||||||
preview = preview.substring(0, 100);
|
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) {
|
if (preview.length === 100) {
|
||||||
const lastSpace = preview.lastIndexOf(' ');
|
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 = preview.substring(0, lastSpace);
|
||||||
}
|
}
|
||||||
preview += '...';
|
preview += '...';
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error('Error generating preview:', e);
|
console.error('Error generating preview:', e);
|
||||||
preview = '';
|
preview = '';
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user