mail page rest

This commit is contained in:
alma 2025-04-21 15:53:53 +02:00
parent eb8e2c96cf
commit 59c7260b9a

View File

@ -1319,53 +1319,52 @@ export default function CourrierPage() {
// Get the content from either HTML or text part
if (parsed.html) {
// Convert HTML to plain text for the reply
// Convert HTML to plain text while preserving structure
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(/<\/div>/gi, '\n')
.replace(/<p[^>]*>/gi, '\n')
.replace(/<\/p>/gi, '')
.replace(/<\/p>/gi, '\n')
.replace(/<li[^>]*>/gi, '\n• ')
.replace(/<\/li>/gi, '\n')
.replace(/<ul[^>]*>/gi, '\n')
.replace(/<\/ul>/gi, '\n')
.replace(/<ol[^>]*>/gi, '\n')
.replace(/<\/ol>/gi, '\n')
.replace(/<blockquote[^>]*>/gi, '\n> ')
.replace(/<\/blockquote>/gi, '\n')
.replace(/<[^>]+>/g, '')
.replace(/&nbsp;|&zwnj;|&raquo;|&laquo;|&gt;/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(/&nbsp;/g, ' ')
.replace(/&amp;/g, '&')
.replace(/&lt;/g, '<')
.replace(/&gt;/g, '>')
.replace(/&quot;/g, '"')
.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();
}
// Clean up the content
// Clean up the content while preserving important formatting
originalContent = originalContent
.split('\n')
.map(line => line.trim())
.filter(line => {
// Remove email client signatures and headers
return !line.match(/^(From|To|Sent|Subject|Date|Cc|Bcc):/i) &&
!line.match(/^-{2,}/) &&
!line.match(/^_{2,}/) &&
!line.match(/^={2,}/) &&
!line.match(/^-{2,}$/) &&
!line.match(/^_{2,}$/) &&
!line.match(/^={2,}$/) &&
!line.match(/^This (email|message) has been/i) &&
!line.match(/^Disclaimer/i) &&
!line.match(/^[*_-]{3,}/) &&
!line.match(/^[*_-]{3,}$/) &&
!line.match(/^Envoyé depuis/i) &&
!line.match(/^Envoyé à partir de/i) &&
!line.match(/^Sent from/i) &&
@ -1377,7 +1376,7 @@ export default function CourrierPage() {
.join('\n')
.trim();
// Format the reply
// Format the reply with proper email headers
const date = new Date(selectedEmail.date);
const formattedDate = date.toLocaleString('en-GB', {
day: '2-digit',
@ -1400,14 +1399,13 @@ export default function CourrierPage() {
}
replyHeader += `\n`;
} else {
// Simple header for reply and reply all
replyHeader = `\n\nOn ${formattedDate}, ${selectedEmail.from} wrote:\n`;
}
// Indent the original content
// Properly indent the original content with blockquotes
const indentedContent = originalContent
.split('\n')
.map(line => line ? `> ${line}` : '>') // Keep empty lines as '>' for better readability
.map(line => line ? `> ${line}` : '>')
.join('\n');
return `${replyHeader}${indentedContent}`;