mail page rest
This commit is contained in:
parent
eb8e2c96cf
commit
59c7260b9a
@ -1319,53 +1319,52 @@ export default function CourrierPage() {
|
|||||||
|
|
||||||
// Get the content from either HTML or text part
|
// Get the content from either HTML or text part
|
||||||
if (parsed.html) {
|
if (parsed.html) {
|
||||||
// Convert HTML to plain text for the reply
|
// Convert HTML to plain text while preserving structure
|
||||||
originalContent = parsed.html
|
originalContent = parsed.html
|
||||||
.replace(/<style[^>]*>[\s\S]*?<\/style>/gi, '')
|
.replace(/<style[^>]*>[\s\S]*?<\/style>/gi, '')
|
||||||
.replace(/<script[^>]*>[\s\S]*?<\/script>/gi, '')
|
.replace(/<script[^>]*>[\s\S]*?<\/script>/gi, '')
|
||||||
.replace(/<br\s*\/?>/gi, '\n')
|
.replace(/<br\s*\/?>/gi, '\n')
|
||||||
.replace(/<div[^>]*>/gi, '\n')
|
.replace(/<div[^>]*>/gi, '\n')
|
||||||
.replace(/<\/div>/gi, '')
|
.replace(/<\/div>/gi, '\n')
|
||||||
.replace(/<p[^>]*>/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(/<[^>]+>/g, '')
|
||||||
.replace(/ |‌|»|«|>/g, match => {
|
.replace(/ /g, ' ')
|
||||||
switch (match) {
|
.replace(/&/g, '&')
|
||||||
case ' ': return ' ';
|
.replace(/</g, '<')
|
||||||
case '‌': return '';
|
.replace(/>/g, '>')
|
||||||
case '»': return '»';
|
.replace(/"/g, '"')
|
||||||
case '«': return '«';
|
|
||||||
case '>': return '>';
|
|
||||||
case '<': return '<';
|
|
||||||
case '&': return '&';
|
|
||||||
default: return match;
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.replace(/^\s+$/gm, '')
|
.replace(/^\s+$/gm, '')
|
||||||
.replace(/\n{3,}/g, '\n\n')
|
.replace(/\n{3,}/g, '\n\n')
|
||||||
.trim();
|
.trim();
|
||||||
} else if (parsed.text) {
|
} else if (parsed.text) {
|
||||||
originalContent = parsed.text.trim();
|
originalContent = parsed.text.trim();
|
||||||
} else {
|
} else {
|
||||||
// Fallback to raw body if parsing fails
|
|
||||||
originalContent = selectedEmail.body
|
originalContent = selectedEmail.body
|
||||||
.replace(/<[^>]+>/g, '')
|
.replace(/<[^>]+>/g, '')
|
||||||
.trim();
|
.trim();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Clean up the content
|
// Clean up the content while preserving important formatting
|
||||||
originalContent = originalContent
|
originalContent = originalContent
|
||||||
.split('\n')
|
.split('\n')
|
||||||
.map(line => line.trim())
|
.map(line => line.trim())
|
||||||
.filter(line => {
|
.filter(line => {
|
||||||
// Remove email client signatures and headers
|
|
||||||
return !line.match(/^(From|To|Sent|Subject|Date|Cc|Bcc):/i) &&
|
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(/^This (email|message) has been/i) &&
|
||||||
!line.match(/^Disclaimer/i) &&
|
!line.match(/^Disclaimer/i) &&
|
||||||
!line.match(/^[*_-]{3,}/) &&
|
!line.match(/^[*_-]{3,}$/) &&
|
||||||
!line.match(/^Envoyé depuis/i) &&
|
!line.match(/^Envoyé depuis/i) &&
|
||||||
!line.match(/^Envoyé à partir de/i) &&
|
!line.match(/^Envoyé à partir de/i) &&
|
||||||
!line.match(/^Sent from/i) &&
|
!line.match(/^Sent from/i) &&
|
||||||
@ -1377,7 +1376,7 @@ export default function CourrierPage() {
|
|||||||
.join('\n')
|
.join('\n')
|
||||||
.trim();
|
.trim();
|
||||||
|
|
||||||
// Format the reply
|
// Format the reply with proper email headers
|
||||||
const date = new Date(selectedEmail.date);
|
const date = new Date(selectedEmail.date);
|
||||||
const formattedDate = date.toLocaleString('en-GB', {
|
const formattedDate = date.toLocaleString('en-GB', {
|
||||||
day: '2-digit',
|
day: '2-digit',
|
||||||
@ -1400,14 +1399,13 @@ export default function CourrierPage() {
|
|||||||
}
|
}
|
||||||
replyHeader += `\n`;
|
replyHeader += `\n`;
|
||||||
} else {
|
} else {
|
||||||
// Simple header for reply and reply all
|
|
||||||
replyHeader = `\n\nOn ${formattedDate}, ${selectedEmail.from} wrote:\n`;
|
replyHeader = `\n\nOn ${formattedDate}, ${selectedEmail.from} wrote:\n`;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Indent the original content
|
// Properly indent the original content with blockquotes
|
||||||
const indentedContent = originalContent
|
const indentedContent = originalContent
|
||||||
.split('\n')
|
.split('\n')
|
||||||
.map(line => line ? `> ${line}` : '>') // Keep empty lines as '>' for better readability
|
.map(line => line ? `> ${line}` : '>')
|
||||||
.join('\n');
|
.join('\n');
|
||||||
|
|
||||||
return `${replyHeader}${indentedContent}`;
|
return `${replyHeader}${indentedContent}`;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user