Neah version mail forward fix

This commit is contained in:
alma 2025-04-16 20:01:16 +02:00
parent 3e4757e574
commit a159e7d99a

View File

@ -319,7 +319,15 @@ function convertCharset(text: string, fromCharset: string): string {
.replace(/\xC3\x80/g, 'À') .replace(/\xC3\x80/g, 'À')
.replace(/\xC3\x89/g, 'É') .replace(/\xC3\x89/g, 'É')
.replace(/\xC3\x87/g, 'Ç') .replace(/\xC3\x87/g, 'Ç')
.replace(/\xC2\xA0/g, ' '); // Clean up HTML entities
.replace(/ç/g, 'ç')
.replace(/é/g, 'é')
.replace(/è/g, 'ë')
.replace(/ê/g, 'ª')
.replace(/ë/g, '«')
.replace(/û/g, '»')
.replace(/ /g, ' ')
.replace(/\xA0/g, ' ');
} }
return text; return text;
@ -1306,44 +1314,100 @@ export default function MailPage() {
}; };
const getReplyBody = () => { const getReplyBody = () => {
const date = new Date(selectedEmail.date); try {
const formattedDate = date.toLocaleString(); const parsed = parseFullEmail(selectedEmail.body);
let originalContent = '';
// Parse the original email content // Get the content from either HTML or text part
const parsed = parseFullEmail(selectedEmail.body); if (parsed.html) {
let originalContent = ''; // Convert HTML to plain text for the reply
originalContent = parsed.html
.replace(/<style[^>]*>[\s\S]*?<\/style>/gi, '')
.replace(/<script[^>]*>[\s\S]*?<\/script>/gi, '')
.replace(/<br\s*\/?>/gi, '\n')
.replace(/<div[^>]*>/gi, '\n')
.replace(/<\/div>/gi, '')
.replace(/<p[^>]*>/gi, '\n')
.replace(/<\/p>/gi, '')
.replace(/<[^>]+>/g, '')
.replace(/&nbsp;|&zwnj;|&raquo;|&laquo;|&gt;|&lt;|&amp;/g, match => {
switch (match) {
case '&nbsp;': return ' ';
case '&zwnj;': return '';
case '&raquo;': return '»';
case '&laquo;': return '«';
case '&gt;': return '>';
case '&lt;': return '<';
case '&amp;': return '&';
default: return match;
}
})
.replace(/^\s+$/gm, '')
.replace(/\n{3,}/g, '\n\n')
.trim();
} else if (parsed.text) {
originalContent = parsed.text.trim();
} else {
// Fallback to raw body if parsing fails
originalContent = selectedEmail.body
.replace(/<[^>]+>/g, '')
.trim();
}
// Get the content from either HTML or text part // Clean up the content
if (parsed.html) { originalContent = originalContent
// Convert HTML to plain text for the reply .split('\n')
originalContent = parsed.html .map(line => line.trim())
.replace(/<style[^>]*>[\s\S]*?<\/style>/gi, '') // Remove style tags .filter(line => {
.replace(/<script[^>]*>[\s\S]*?<\/script>/gi, '') // Remove script tags // Remove email headers and common footer markers
.replace(/<[^>]+>/g, '') // Remove HTML tags return !line.match(/^(From|To|Sent|Subject|Date|Cc|Bcc):/i) &&
.replace(/&nbsp;|&zwnj;|&raquo;|&laquo;|&gt;/g, ' ') // Convert HTML entities to spaces !line.match(/^-{2,}/) &&
.replace(/^\s+$/gm, '') // Remove lines with only whitespace !line.match(/^_{2,}/) &&
.replace(/\n{3,}/g, '\n\n') // Normalize multiple line breaks !line.match(/^={2,}/) &&
.trim(); !line.match(/^This (email|message) has been/i) &&
} else if (parsed.text) { !line.match(/^Disclaimer/i) &&
originalContent = parsed.text.trim(); !line.match(/^[*_-]{3,}/);
} else { })
// Fallback to raw body if parsing fails .join('\n')
originalContent = selectedEmail.body
.replace(/<[^>]+>/g, '')
.trim(); .trim();
// Format the reply
const date = new Date(selectedEmail.date);
const formattedDate = date.toLocaleString('en-GB', {
day: '2-digit',
month: '2-digit',
year: 'numeric',
hour: '2-digit',
minute: '2-digit',
hour12: false
});
let replyHeader = '';
if (type === 'forward') {
replyHeader = `\n\n---------- Forwarded message ----------\n`;
replyHeader += `From: ${selectedEmail.from}\n`;
replyHeader += `Date: ${formattedDate}\n`;
replyHeader += `Subject: ${selectedEmail.subject}\n`;
replyHeader += `To: ${selectedEmail.to}\n`;
if (selectedEmail.cc) {
replyHeader += `Cc: ${selectedEmail.cc}\n`;
}
replyHeader += `\n`;
} else {
replyHeader = `\n\nOn ${formattedDate}, ${selectedEmail.from} wrote:\n`;
}
// Indent the original content
const indentedContent = originalContent
.split('\n')
.map(line => `> ${line}`)
.join('\n');
return `${replyHeader}${indentedContent}`;
} catch (error) {
console.error('Error formatting reply:', error);
return `\n\nOn ${new Date(selectedEmail.date).toLocaleString()}, ${selectedEmail.from} wrote:\n> ${selectedEmail.body}`;
} }
// Format the reply
const separator = '\n\n------------ Original Message ------------\n';
const header = `On ${formattedDate}, ${selectedEmail.from} wrote:\n`;
// Indent the original content
const indentedContent = originalContent
.split('\n')
.map(line => `> ${line}`)
.join('\n');
return `${separator}${header}${indentedContent}`;
}; };
// Open compose modal with reply details // Open compose modal with reply details