courrier clean 2$

This commit is contained in:
alma 2025-04-26 21:01:12 +02:00
parent 91751b23ca
commit e40df0ad87

View File

@ -25,6 +25,63 @@ DOMPurify.addHook('afterSanitizeAttributes', function(node) {
}
});
// Configure DOMPurify to enforce LTR for English-only content
DOMPurify.addHook('afterSanitizeAttributes', function(node) {
// Always set direction to LTR for all elements
if (node.hasAttribute('dir')) {
node.setAttribute('dir', 'ltr');
}
// Ensure text alignment is left-aligned for all elements
if (node.hasAttribute('style')) {
let style = node.getAttribute('style') || '';
// Remove any right-to-left text alignment
if (style.includes('text-align: right') || style.includes('text-align:right')) {
style = style.replace(/text-align:\s*right\s*;?/gi, '');
style = style.trim();
// Add semicolon if needed
if (style && !style.endsWith(';')) {
style += ';';
}
}
// Add left alignment if not already specified
if (!style.includes('text-align:')) {
style += (style ? ' ' : '') + 'text-align: left;';
}
node.setAttribute('style', style);
}
});
// Clear existing hooks first
DOMPurify.removeHook('afterSanitizeAttributes');
// Configure DOMPurify for English-only content (always LTR)
DOMPurify.addHook('afterSanitizeAttributes', function(node) {
// Always set direction to LTR for all elements
node.setAttribute('dir', 'ltr');
// Ensure text alignment is left-aligned for all elements
if (node.hasAttribute('style')) {
let style = node.getAttribute('style') || '';
// Remove any right-to-left text alignment
if (style.includes('text-align: right') || style.includes('text-align:right')) {
style = style.replace(/text-align:\s*right\s*;?/gi, '');
style = style.trim();
}
// Add left alignment
style = (style ? style + '; ' : '') + 'text-align: left;';
node.setAttribute('style', style);
} else {
// If no style exists, add default left alignment
node.setAttribute('style', 'text-align: left;');
}
});
// Interface definitions
export interface EmailAddress {
name: string;
@ -134,26 +191,26 @@ export function formatForwardedEmail(email: EmailMessage): {
// Just wrap the content in appropriate styling without adding another header
const content = `
<div style="min-height: 20px;"></div>
<div style="direction: ltr; text-align: left;" dir="ltr" class="email-original-content">
<div class="email-original-content">
${originalContent}
</div>
`;
return { subject, content };
}
// Create formatted content with explicit LTR formatting
// Create formatted content for forwarded email
const content = `
<div style="min-height: 20px;"></div>
<div style="border-top: 1px solid #ccc; margin-top: 10px; padding-top: 10px; direction: ltr; text-align: left;" dir="ltr">
<div style="font-family: Arial, sans-serif; color: #333; direction: ltr; text-align: left;" dir="ltr">
<div style="margin-bottom: 15px; direction: ltr; text-align: left;" dir="ltr">
<div style="direction: ltr; text-align: left;" dir="ltr">---------- Forwarded message ---------</div>
<div style="direction: ltr; text-align: left;" dir="ltr"><b>From:</b> ${fromString}</div>
<div style="direction: ltr; text-align: left;" dir="ltr"><b>Date:</b> ${dateString}</div>
<div style="direction: ltr; text-align: left;" dir="ltr"><b>Subject:</b> ${email.subject || ''}</div>
<div style="direction: ltr; text-align: left;" dir="ltr"><b>To:</b> ${toString}</div>
<div style="border-top: 1px solid #ccc; margin-top: 10px; padding-top: 10px;">
<div style="font-family: Arial, sans-serif; color: #333;">
<div style="margin-bottom: 15px;">
<div>---------- Forwarded message ---------</div>
<div><b>From:</b> ${fromString}</div>
<div><b>Date:</b> ${dateString}</div>
<div><b>Subject:</b> ${email.subject || ''}</div>
<div><b>To:</b> ${toString}</div>
</div>
<div style="direction: ltr; text-align: left;" dir="ltr" class="email-original-content">
<div class="email-original-content">
${originalContent}
</div>
</div>
@ -197,7 +254,7 @@ export function formatReplyEmail(email: EmailMessage, type: 'reply' | 'reply-all
});
// Create quote header
const quoteHeader = `<div style="font-weight: 500; direction: ltr; text-align: left;" dir="ltr">On ${formattedDate}, ${fromText} wrote:</div>`;
const quoteHeader = `<div style="font-weight: 500;">On ${formattedDate}, ${fromText} wrote:</div>`;
// Get and sanitize original content
const quotedContent = sanitizeHtml(email.html || email.content || email.text || '');
@ -216,13 +273,13 @@ export function formatReplyEmail(email: EmailMessage, type: 'reply' | 'reply-all
cc = formatEmailAddresses(allRecipients);
}
// Format content with explicit LTR for quoted parts
// Format content for reply
const content = `
<div style="min-height: 20px;"></div>
<div class="reply-body" style="direction: ltr; text-align: left;" dir="ltr">
<div class="quote-header" style="color: #555; font-size: 13px; margin: 20px 0 10px 0; direction: ltr; text-align: left;" dir="ltr">${quoteHeader}</div>
<blockquote style="margin: 0; padding: 10px 0 10px 15px; border-left: 3px solid #ddd; color: #555; background-color: #f8f8f8; border-radius: 4px; direction: ltr; text-align: left;" dir="ltr">
<div class="quoted-content" style="font-size: 13px; direction: ltr; text-align: left;" dir="ltr">
<div class="reply-body">
<div class="quote-header" style="color: #555; font-size: 13px; margin: 20px 0 10px 0;">${quoteHeader}</div>
<blockquote style="margin: 0; padding: 10px 0 10px 15px; border-left: 3px solid #ddd; color: #555; background-color: #f8f8f8; border-radius: 4px;">
<div class="quoted-content" style="font-size: 13px;">
${quotedContent}
</div>
</blockquote>