From 1211b43f466a315c084c3dfa7b4882ef5808950d Mon Sep 17 00:00:00 2001 From: alma Date: Thu, 1 May 2025 12:38:32 +0200 Subject: [PATCH] courrier preview --- lib/utils/email-content.ts | 26 +++----------------------- lib/utils/email-utils.ts | 21 +-------------------- 2 files changed, 4 insertions(+), 43 deletions(-) diff --git a/lib/utils/email-content.ts b/lib/utils/email-content.ts index 2bf663b8..dac643c4 100644 --- a/lib/utils/email-content.ts +++ b/lib/utils/email-content.ts @@ -278,35 +278,15 @@ export function processHtmlContent(htmlContent: string, textContent?: string): s textNodes.forEach(node => { if (node.nodeValue) { // Replace sequences of whitespace with a single space - // But don't change whitespace in
 tags
-            if (!isInPreTag(node)) {
-              node.nodeValue = node.nodeValue.replace(/\s+/g, ' ').trim();
-            }
+            node.nodeValue = node.nodeValue.replace(/\s+/g, ' ').trim();
           }
         });
         
-        // Helper function to check if a node is inside a pre tag
-        function isInPreTag(node: Node): boolean {
-          let parent = node.parentNode;
-          while (parent) {
-            if (parent.nodeName.toLowerCase() === 'pre') {
-              return true;
-            }
-            parent = parent.parentNode;
-          }
-          return false;
-        }
-        
         // Remove empty paragraphs and divs that contain only whitespace
         const emptyElements = tempDiv.querySelectorAll('p, div, span');
         emptyElements.forEach(el => {
           if (el.innerHTML.trim() === '' || el.innerHTML === ' ') {
-            // Only remove if not a child of a layout container like table
-            if (el.parentNode && 
-                el.parentNode.nodeName.toLowerCase() !== 'td' && 
-                el.parentNode.nodeName.toLowerCase() !== 'th') {
-              el.parentNode?.removeChild(el);
-            }
+            el.parentNode?.removeChild(el);
           }
         });
         
@@ -332,7 +312,7 @@ export function processHtmlContent(htmlContent: string, textContent?: string): s
       .replace(/src="data:image\/[^;]+;base64,\s*([^"]+)\s*"/gi, (match, p1) => {
         return `src="data:image/png;base64,${p1.replace(/\s+/g, '')}"`;
       })
-      // Remove excessive whitespace from the HTML string itself, but be careful not to break preformatted text
+      // Remove excessive whitespace from the HTML string itself
       .replace(/>\s+ <');
   } catch (error) {
     console.error('Error processing HTML content:', error);
diff --git a/lib/utils/email-utils.ts b/lib/utils/email-utils.ts
index a14e6c07..c7a2ab8a 100644
--- a/lib/utils/email-utils.ts
+++ b/lib/utils/email-utils.ts
@@ -372,27 +372,8 @@ export function formatForwardedEmail(originalEmail: EmailMessage | LegacyEmailMe
   `;
   
   // Use the original HTML content if available, otherwise format the text
-  let contentHtml = '';
+  const contentHtml = html || (text ? `

${text.replace(/\n/g, '

')}

` : '

No content available

'); - if (html) { - // Preserve the original HTML structure - // The key is to preserve all formatting without trying to modify it - contentHtml = ``; - } else if (text) { - // For plain text, convert to HTML with proper line breaks - const formattedText = text - .replace(/&/g, '&') - .replace(//g, '>') - .replace(/\n/g, '
'); - - contentHtml = ``; - } else { - contentHtml = '
No content available
'; - } - - // Just concatenate the header with the original content - // Don't try to process or reformat the original content const cleanHtml = `${forwardHeader}${contentHtml}`; // Plain text version - with clearer formatting