courrier preview
This commit is contained in:
parent
2900e0d188
commit
c1aa1e8f10
@ -274,47 +274,6 @@ export function formatReplyEmail(originalEmail: EmailMessage | LegacyEmailMessag
|
|||||||
// Get recipient addresses
|
// Get recipient addresses
|
||||||
const { to, cc } = getRecipientAddresses(email, type);
|
const { to, cc } = getRecipientAddresses(email, type);
|
||||||
|
|
||||||
// Get email content and sanitize it
|
|
||||||
const originalContent = email.content;
|
|
||||||
|
|
||||||
// Extract text and html content
|
|
||||||
let htmlContent = '';
|
|
||||||
let textContent = '';
|
|
||||||
let direction: 'ltr' | 'rtl' = 'ltr';
|
|
||||||
|
|
||||||
// Handle different content formats
|
|
||||||
if (typeof originalContent === 'string') {
|
|
||||||
console.log('formatReplyEmail: content is string, length:', originalContent.length);
|
|
||||||
// Simple string content
|
|
||||||
textContent = originalContent;
|
|
||||||
const isHtml = isHtmlContent(originalContent);
|
|
||||||
if (isHtml) {
|
|
||||||
htmlContent = originalContent;
|
|
||||||
} else {
|
|
||||||
// If it's plain text, convert to HTML
|
|
||||||
htmlContent = formatPlainTextToHtml(originalContent);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (originalContent) {
|
|
||||||
console.log('formatReplyEmail: content is object:', {
|
|
||||||
hasHtml: !!originalContent.html,
|
|
||||||
htmlLength: originalContent.html?.length || 0,
|
|
||||||
hasText: !!originalContent.text,
|
|
||||||
textLength: originalContent.text?.length || 0,
|
|
||||||
direction: originalContent.direction
|
|
||||||
});
|
|
||||||
|
|
||||||
// Standard EmailContent object
|
|
||||||
htmlContent = originalContent.html || '';
|
|
||||||
textContent = originalContent.text || '';
|
|
||||||
direction = originalContent.direction || 'ltr' as const;
|
|
||||||
|
|
||||||
// If no HTML but has text, convert text to HTML
|
|
||||||
if (!htmlContent && textContent) {
|
|
||||||
htmlContent = formatPlainTextToHtml(textContent);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get quote header
|
// Get quote header
|
||||||
const { fromStr, dateStr } = getFormattedHeaderInfo(email);
|
const { fromStr, dateStr } = getFormattedHeaderInfo(email);
|
||||||
|
|
||||||
@ -322,31 +281,27 @@ export function formatReplyEmail(originalEmail: EmailMessage | LegacyEmailMessag
|
|||||||
const sender = fromStr;
|
const sender = fromStr;
|
||||||
const date = dateStr;
|
const date = dateStr;
|
||||||
|
|
||||||
// Create the quoted reply content
|
// Process the original content using formatEmailContent for consistent rendering
|
||||||
if (htmlContent) {
|
const { text: textContent, html: originalHtmlContent } = extractEmailContent(email.content);
|
||||||
// Format HTML reply
|
|
||||||
console.log('Formatting HTML reply, quoted content length:', htmlContent.length);
|
|
||||||
const sanitizedReplyContent = sanitizeHtml(htmlContent);
|
|
||||||
console.log('Sanitized reply content length:', sanitizedReplyContent.length);
|
|
||||||
console.log('Sanitized reply content truncated sample:',
|
|
||||||
sanitizedReplyContent.length > 100
|
|
||||||
? sanitizedReplyContent.substring(0, 100) + '...'
|
|
||||||
: sanitizedReplyContent || 'EMPTY');
|
|
||||||
|
|
||||||
htmlContent = `
|
|
||||||
<div style="margin: 20px 0 10px 0; color: #666; border-bottom: 1px solid #ddd; padding-bottom: 5px;">
|
|
||||||
On ${date}, ${sender} wrote:
|
|
||||||
</div>
|
|
||||||
<blockquote style="margin: 0; padding-left: 10px; border-left: 3px solid #ddd; color: #505050; background-color: #f9f9f9; padding: 10px;">
|
|
||||||
${sanitizedReplyContent}
|
|
||||||
</blockquote>
|
|
||||||
`;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
// Get the properly formatted content using the same utility as the preview panel
|
||||||
|
const processedContent = formatEmailContent(email.content);
|
||||||
|
|
||||||
|
// Create the quoted reply HTML
|
||||||
|
const htmlContent = `
|
||||||
|
<div style="margin: 20px 0 10px 0; color: #666; border-bottom: 1px solid #ddd; padding-bottom: 5px;">
|
||||||
|
On ${date}, ${sender} wrote:
|
||||||
|
</div>
|
||||||
|
<blockquote style="margin: 0; padding-left: 10px; border-left: 3px solid #ddd; color: #505050; background-color: #f9f9f9; padding: 10px;">
|
||||||
|
${processedContent}
|
||||||
|
</blockquote>
|
||||||
|
`;
|
||||||
|
|
||||||
|
// Format plain text reply if available
|
||||||
|
let formattedTextContent = '';
|
||||||
if (textContent) {
|
if (textContent) {
|
||||||
// Format plain text reply
|
|
||||||
const lines = textContent.split(/\r\n|\r|\n/);
|
const lines = textContent.split(/\r\n|\r|\n/);
|
||||||
textContent = `On ${date}, ${sender} wrote:\n\n${lines.map(line => `> ${line}`).join('\n')}`;
|
formattedTextContent = `On ${date}, ${sender} wrote:\n\n${lines.map(line => `> ${line}`).join('\n')}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
const result = {
|
const result = {
|
||||||
@ -355,9 +310,9 @@ export function formatReplyEmail(originalEmail: EmailMessage | LegacyEmailMessag
|
|||||||
subject,
|
subject,
|
||||||
content: {
|
content: {
|
||||||
html: htmlContent,
|
html: htmlContent,
|
||||||
text: textContent,
|
text: formattedTextContent || textContent,
|
||||||
isHtml: true,
|
isHtml: true,
|
||||||
direction,
|
direction: typeof email.content === 'object' && email.content ? email.content.direction || 'ltr' : 'ltr',
|
||||||
},
|
},
|
||||||
attachments: email.attachments?.map(att => {
|
attachments: email.attachments?.map(att => {
|
||||||
// Create properly typed attachment
|
// Create properly typed attachment
|
||||||
@ -419,106 +374,52 @@ export function formatForwardedEmail(originalEmail: EmailMessage | LegacyEmailMe
|
|||||||
// Original sent date
|
// Original sent date
|
||||||
const date = dateStr;
|
const date = dateStr;
|
||||||
|
|
||||||
// Get email content
|
// Process the original content using formatEmailContent for consistent rendering
|
||||||
const originalContent = email.content;
|
const { text: textContent } = extractEmailContent(email.content);
|
||||||
|
|
||||||
// Extract text and html content
|
// Get the properly formatted content using the same utility as the preview panel
|
||||||
let htmlContent = '';
|
const processedContent = formatEmailContent(email.content);
|
||||||
let textContent = '';
|
|
||||||
let direction: 'ltr' | 'rtl' = 'ltr';
|
|
||||||
|
|
||||||
// Handle different content formats
|
// Create the forwarded email HTML content with the properly processed content
|
||||||
if (typeof originalContent === 'string') {
|
const htmlContent = `
|
||||||
console.log('formatForwardedEmail: content is string, length:', originalContent.length);
|
<div style="margin: 20px 0 10px 0; color: #666; font-family: Arial, sans-serif;">
|
||||||
// Simple string content
|
---------- Forwarded message ----------<br>
|
||||||
textContent = originalContent;
|
<table style="margin: 10px 0 15px 0; border-collapse: collapse; font-size: 13px; color: #333;">
|
||||||
const isHtml = isHtmlContent(originalContent);
|
<tbody>
|
||||||
if (isHtml) {
|
<tr>
|
||||||
htmlContent = originalContent;
|
<td style="padding: 3px 10px 3px 0; font-weight: bold; text-align: right; vertical-align: top;">From:</td>
|
||||||
} else {
|
<td style="padding: 3px 0;">${fromStr}</td>
|
||||||
// If it's plain text, convert to HTML
|
</tr>
|
||||||
htmlContent = formatPlainTextToHtml(originalContent);
|
<tr>
|
||||||
}
|
<td style="padding: 3px 10px 3px 0; font-weight: bold; text-align: right; vertical-align: top;">Date:</td>
|
||||||
}
|
<td style="padding: 3px 0;">${date}</td>
|
||||||
else if (originalContent) {
|
</tr>
|
||||||
console.log('formatForwardedEmail: content is object:', {
|
<tr>
|
||||||
hasHtml: !!originalContent.html,
|
<td style="padding: 3px 10px 3px 0; font-weight: bold; text-align: right; vertical-align: top;">Subject:</td>
|
||||||
htmlLength: originalContent.html?.length || 0,
|
<td style="padding: 3px 0;">${email.subject || ''}</td>
|
||||||
hasText: !!originalContent.text,
|
</tr>
|
||||||
textLength: originalContent.text?.length || 0,
|
<tr>
|
||||||
direction: originalContent.direction
|
<td style="padding: 3px 10px 3px 0; font-weight: bold; text-align: right; vertical-align: top;">To:</td>
|
||||||
});
|
<td style="padding: 3px 0;">${toStr}</td>
|
||||||
|
</tr>
|
||||||
// Standard EmailContent object
|
${ccStr ? `
|
||||||
htmlContent = originalContent.html || '';
|
<tr>
|
||||||
textContent = originalContent.text || '';
|
<td style="padding: 3px 10px 3px 0; font-weight: bold; text-align: right; vertical-align: top;">Cc:</td>
|
||||||
direction = originalContent.direction || 'ltr' as const;
|
<td style="padding: 3px 0;">${ccStr}</td>
|
||||||
|
</tr>
|
||||||
// If no HTML but has text, convert text to HTML
|
` : ''}
|
||||||
if (!htmlContent && textContent) {
|
</tbody>
|
||||||
htmlContent = formatPlainTextToHtml(textContent);
|
</table>
|
||||||
}
|
</div>
|
||||||
}
|
<blockquote style="margin: 0; padding-left: 10px; border-left: 3px solid #ddd; color: #505050; background-color: #f9f9f9; padding: 10px;">
|
||||||
|
${processedContent}
|
||||||
// Create the forwarded email HTML content
|
</blockquote>
|
||||||
if (htmlContent) {
|
`;
|
||||||
console.log('Formatting HTML forward, original content length:', htmlContent.length);
|
|
||||||
|
|
||||||
// Important: First sanitize the content portion only
|
|
||||||
const sanitizedReplyContent = sanitizeHtml(htmlContent);
|
|
||||||
console.log('Sanitized forward content length:', sanitizedReplyContent.length);
|
|
||||||
console.log('Sanitized forward content truncated sample:',
|
|
||||||
sanitizedReplyContent.length > 100
|
|
||||||
? sanitizedReplyContent.substring(0, 100) + '...'
|
|
||||||
: sanitizedReplyContent || 'EMPTY');
|
|
||||||
|
|
||||||
// Create the complete forwarded email with header info
|
|
||||||
const fullForwardedEmail = `
|
|
||||||
<div style="margin: 20px 0 10px 0; color: #666; font-family: Arial, sans-serif;">
|
|
||||||
---------- Forwarded message ----------<br>
|
|
||||||
<table style="margin: 10px 0 15px 0; border-collapse: collapse; font-size: 13px; color: #333;">
|
|
||||||
<tbody>
|
|
||||||
<tr>
|
|
||||||
<td style="padding: 3px 10px 3px 0; font-weight: bold; text-align: right; vertical-align: top;">From:</td>
|
|
||||||
<td style="padding: 3px 0;">${fromStr}</td>
|
|
||||||
</tr>
|
|
||||||
<tr>
|
|
||||||
<td style="padding: 3px 10px 3px 0; font-weight: bold; text-align: right; vertical-align: top;">Date:</td>
|
|
||||||
<td style="padding: 3px 0;">${date}</td>
|
|
||||||
</tr>
|
|
||||||
<tr>
|
|
||||||
<td style="padding: 3px 10px 3px 0; font-weight: bold; text-align: right; vertical-align: top;">Subject:</td>
|
|
||||||
<td style="padding: 3px 0;">${email.subject || ''}</td>
|
|
||||||
</tr>
|
|
||||||
<tr>
|
|
||||||
<td style="padding: 3px 10px 3px 0; font-weight: bold; text-align: right; vertical-align: top;">To:</td>
|
|
||||||
<td style="padding: 3px 0;">${toStr}</td>
|
|
||||||
</tr>
|
|
||||||
${ccStr ? `
|
|
||||||
<tr>
|
|
||||||
<td style="padding: 3px 10px 3px 0; font-weight: bold; text-align: right; vertical-align: top;">Cc:</td>
|
|
||||||
<td style="padding: 3px 0;">${ccStr}</td>
|
|
||||||
</tr>
|
|
||||||
` : ''}
|
|
||||||
</tbody>
|
|
||||||
</table>
|
|
||||||
</div>
|
|
||||||
<blockquote style="margin: 0; padding-left: 10px; border-left: 3px solid #ddd; color: #505050; background-color: #f9f9f9; padding: 10px;">
|
|
||||||
${sanitizedReplyContent}
|
|
||||||
</blockquote>
|
|
||||||
`;
|
|
||||||
|
|
||||||
// Now we have the full forwarded email structure without sanitizing it again
|
|
||||||
htmlContent = fullForwardedEmail;
|
|
||||||
|
|
||||||
console.log('Final forward HTML content length:', htmlContent.length,
|
|
||||||
'contains table:', htmlContent.includes('<table'),
|
|
||||||
'contains forwarded message:', htmlContent.includes('---------- Forwarded message ----------'));
|
|
||||||
}
|
|
||||||
|
|
||||||
// Format the plain text version
|
// Format plain text version
|
||||||
|
let formattedTextContent = '';
|
||||||
if (textContent) {
|
if (textContent) {
|
||||||
textContent = `
|
formattedTextContent = `
|
||||||
---------- Forwarded message ----------
|
---------- Forwarded message ----------
|
||||||
From: ${fromStr}
|
From: ${fromStr}
|
||||||
Date: ${date}
|
Date: ${date}
|
||||||
@ -535,9 +436,9 @@ ${textContent}
|
|||||||
subject,
|
subject,
|
||||||
content: {
|
content: {
|
||||||
html: htmlContent,
|
html: htmlContent,
|
||||||
text: textContent,
|
text: formattedTextContent || textContent,
|
||||||
isHtml: true,
|
isHtml: true,
|
||||||
direction,
|
direction: typeof email.content === 'object' && email.content ? email.content.direction || 'ltr' : 'ltr',
|
||||||
},
|
},
|
||||||
attachments: email.attachments?.map(att => {
|
attachments: email.attachments?.map(att => {
|
||||||
// Create properly typed attachment
|
// Create properly typed attachment
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user