courrier preview
This commit is contained in:
parent
a62ccf9c0c
commit
36920bc9d5
@ -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(/<!--\[if\s+gte\s+mso/g, '<!--[if gte mso')
|
||||
// Fix for broken image paths that might be relative
|
||||
// Fix for broken image paths WITHOUT replacing cid: URLs
|
||||
.replace(/(src|background)="(?!(?:https?:|data:|cid:))/gi, '$1="https://')
|
||||
// Fix for base64 images that might be broken across lines
|
||||
.replace(/src="data:image\/[^;]+;base64,\s*([^"]+)\s*"/gi, (match, p1) => {
|
||||
|
||||
@ -272,33 +272,32 @@ export function formatReplyEmail(originalEmail: EmailMessage | LegacyEmailMessag
|
||||
// Get header information
|
||||
const { fromStr, dateStr, subject } = getFormattedHeaderInfo(originalEmail);
|
||||
|
||||
// Extract just the text content for a clean reply
|
||||
let emailText = '';
|
||||
|
||||
// Extract content using the centralized extraction function
|
||||
const { text, html } = extractEmailContent(originalEmail);
|
||||
emailText = text;
|
||||
|
||||
// Create a clearer reply header with separator line
|
||||
const cleanReplyHeader = `
|
||||
const replyHeader = `
|
||||
<div style="margin: 20px 0 10px 0; color: #666; border-bottom: 1px solid #ddd; padding-bottom: 5px;">
|
||||
On ${dateStr}, ${fromStr} wrote:
|
||||
</div>
|
||||
`;
|
||||
|
||||
// No character limit - display the full email content
|
||||
// Use the original HTML content if available, otherwise format the text
|
||||
const contentHtml = html || (text ? `<p>${text.replace(/\n/g, '</p><p>')}</p>` : '<p>No content available</p>');
|
||||
|
||||
// Wrap the original content in proper styling without losing the HTML structure
|
||||
const cleanHtml = `
|
||||
${cleanReplyHeader}
|
||||
${replyHeader}
|
||||
<blockquote style="margin: 0; padding-left: 10px; border-left: 3px solid #ddd; color: #505050; background-color: #f9f9f9; padding: 10px;">
|
||||
${html || `<p>${emailText.replace(/\n/g, '</p><p>')}</p>`}
|
||||
${contentHtml}
|
||||
</blockquote>
|
||||
`;
|
||||
|
||||
// Plain text version - no truncation
|
||||
// Plain text version
|
||||
const plainText = `
|
||||
On ${dateStr}, ${fromStr} wrote:
|
||||
-------------------------------------------------------------------
|
||||
${emailText.split('\n').join('\n> ')}
|
||||
${text.split('\n').join('\n> ')}
|
||||
`;
|
||||
|
||||
return {
|
||||
@ -334,15 +333,11 @@ export function formatForwardedEmail(originalEmail: EmailMessage | LegacyEmailMe
|
||||
// Get header information
|
||||
const { fromStr, toStr, ccStr, dateStr, subject } = getFormattedHeaderInfo(originalEmail);
|
||||
|
||||
// Extract just the text content for a clean forward
|
||||
let emailText = '';
|
||||
|
||||
// Extract content using the centralized extraction function
|
||||
const { text, html } = extractEmailContent(originalEmail);
|
||||
emailText = text;
|
||||
|
||||
// Create a more traditional forward format with dashed separator
|
||||
const cleanForwardHeader = `
|
||||
// Create a traditional forward format with dashed separator
|
||||
const forwardHeader = `
|
||||
<div style="margin: 20px 0 10px 0; color: #666;">
|
||||
<div style="border-bottom: 1px solid #ccc; margin-bottom: 10px; padding-bottom: 5px;">
|
||||
<div>---------------------------- Forwarded Message ----------------------------</div>
|
||||
@ -358,15 +353,12 @@ export function formatForwardedEmail(originalEmail: EmailMessage | LegacyEmailMe
|
||||
</div>
|
||||
`;
|
||||
|
||||
// No character limit - display the full email content
|
||||
const cleanHtml = `
|
||||
${cleanForwardHeader}
|
||||
<div class="forwarded-content" style="margin: 0; color: #333;">
|
||||
${html || `<p>${emailText.replace(/\n/g, '</p><p>')}</p>`}
|
||||
</div>
|
||||
`;
|
||||
// Use the original HTML content if available, otherwise format the text
|
||||
const contentHtml = html || (text ? `<p>${text.replace(/\n/g, '</p><p>')}</p>` : '<p>No content available</p>');
|
||||
|
||||
// Plain text version - no truncation
|
||||
const cleanHtml = `${forwardHeader}${contentHtml}`;
|
||||
|
||||
// Plain text version
|
||||
const plainText = `
|
||||
---------------------------- Forwarded Message ----------------------------
|
||||
From: ${fromStr}
|
||||
@ -376,7 +368,7 @@ To: ${toStr}
|
||||
${ccStr ? `Cc: ${ccStr}` : ''}
|
||||
----------------------------------------------------------------------
|
||||
|
||||
${emailText}
|
||||
${text}
|
||||
`;
|
||||
|
||||
// Check if original has attachments
|
||||
|
||||
Loading…
Reference in New Issue
Block a user