From 36920bc9d5464e11f4fed00cce311bb447d41a46 Mon Sep 17 00:00:00 2001 From: alma Date: Thu, 1 May 2025 12:30:13 +0200 Subject: [PATCH] courrier preview --- lib/utils/email-content.ts | 29 ++++++++++++++++++++++++-- lib/utils/email-utils.ts | 42 +++++++++++++++----------------------- 2 files changed, 44 insertions(+), 27 deletions(-) diff --git a/lib/utils/email-content.ts b/lib/utils/email-content.ts index 93517166..8c06fc09 100644 --- a/lib/utils/email-content.ts +++ b/lib/utils/email-content.ts @@ -236,6 +236,31 @@ export function processHtmlContent(htmlContent: string, textContent?: string): s } }); + // Fix image URLs - preserve cid: URLs for email attachments + const images = tempDiv.querySelectorAll('img'); + images.forEach(img => { + const src = img.getAttribute('src'); + if (src) { + // Don't modify cid: URLs as they are handled specially in email clients + if (src.startsWith('cid:')) { + // Keep cid: URLs as they are + console.log('Preserving CID reference:', src); + } + // Fix http:// URLs to https:// for security + else if (src.startsWith('http://')) { + img.setAttribute('src', src.replace('http://', 'https://')); + } + // Handle relative URLs that might be broken + else if (!src.startsWith('https://') && !src.startsWith('data:')) { + if (src.startsWith('/')) { + img.setAttribute('src', `https://example.com${src}`); + } else { + img.setAttribute('src', `https://example.com/${src}`); + } + } + } + }); + // Get the fixed HTML sanitizedContent = tempDiv.innerHTML; } @@ -243,11 +268,11 @@ export function processHtmlContent(htmlContent: string, textContent?: string): s console.error('Error fixing URLs in content:', e); } - // Fix common email client quirks + // Fix common email client quirks without breaking cid: URLs return sanitizedContent // Fix for Outlook WebVML content .replace(/