diff --git a/lib/mail-parser-wrapper.ts b/lib/mail-parser-wrapper.ts index ea78b01b..efb2204c 100644 --- a/lib/mail-parser-wrapper.ts +++ b/lib/mail-parser-wrapper.ts @@ -103,10 +103,14 @@ export async function decodeEmail(emailContent: string): Promise { export function cleanHtml(html: string): string { try { + // Enhanced configuration to preserve more HTML elements for complex emails return DOMPurify.sanitize(html, { - ALLOWED_TAGS: ['p', 'br', 'div', 'span', 'a', 'img', 'strong', 'em', 'u', 'ul', 'ol', 'li', 'blockquote', 'pre', 'code', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6'], - ALLOWED_ATTR: ['href', 'src', 'alt', 'title', 'class', 'style'], - ALLOWED_URI_REGEXP: /^(?:(?:(?:f|ht)tps?|mailto|tel):|[^a-z]|[a-z+.\-]+(?:[^a-z+.\-:]|$))/i + ADD_TAGS: ['style', 'meta', 'link', 'table', 'thead', 'tbody', 'tr', 'td', 'th', 'hr'], + ADD_ATTR: ['*', 'colspan', 'rowspan', 'cellpadding', 'cellspacing', 'border', 'bgcolor', 'width', 'height', 'align', 'valign', 'class', 'id', 'style'], + ALLOW_UNKNOWN_PROTOCOLS: true, + WHOLE_DOCUMENT: true, + KEEP_CONTENT: true, + RETURN_DOM: false }); } catch (error) { console.error('Error cleaning HTML:', error);