courrier preview
This commit is contained in:
parent
b149c52931
commit
3c57a3ed65
@ -1,5 +1,6 @@
|
|||||||
import { EmailMessage, EmailContent, EmailAddress, LegacyEmailMessage } from '@/types/email';
|
import { EmailMessage, EmailContent, EmailAddress, LegacyEmailMessage } from '@/types/email';
|
||||||
import { processContentWithDirection } from './text-direction';
|
import { extractEmailContent } from '@/lib/utils/email-content';
|
||||||
|
import { detectTextDirection } from '@/lib/utils/text-direction';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adapts a legacy email format to the standardized EmailMessage format
|
* Adapts a legacy email format to the standardized EmailMessage format
|
||||||
@ -161,14 +162,17 @@ function normalizeContent(email: LegacyEmailMessage): EmailContent {
|
|||||||
else if (email.formattedContent) initialContent.html = email.formattedContent;
|
else if (email.formattedContent) initialContent.html = email.formattedContent;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Use the centralized content processor
|
// Use extractEmailContent from our centralized utilities
|
||||||
const processedContent = processContentWithDirection(initialContent);
|
const { html, text } = extractEmailContent(initialContent);
|
||||||
|
|
||||||
|
// Detect direction from text
|
||||||
|
const direction = detectTextDirection(text || '');
|
||||||
|
|
||||||
return {
|
return {
|
||||||
html: processedContent.html,
|
html,
|
||||||
text: processedContent.text,
|
text,
|
||||||
isHtml: !!processedContent.html,
|
isHtml: !!html,
|
||||||
direction: processedContent.direction
|
direction
|
||||||
};
|
};
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Error normalizing email content:', error);
|
console.error('Error normalizing email content:', error);
|
||||||
|
|||||||
@ -282,23 +282,18 @@ export function formatReplyEmail(originalEmail: EmailMessage | LegacyEmailMessag
|
|||||||
// Create simple reply with header
|
// Create simple reply with header
|
||||||
const cleanReplyHeader = `<div style="margin: 20px 0 10px 0; color: #666; border-bottom: 1px solid #eee; padding-bottom: 10px;">On ${dateStr}, ${fromStr} wrote:</div>`;
|
const cleanReplyHeader = `<div style="margin: 20px 0 10px 0; color: #666; border-bottom: 1px solid #eee; padding-bottom: 10px;">On ${dateStr}, ${fromStr} wrote:</div>`;
|
||||||
|
|
||||||
// Limit text to reasonable size and format as simple HTML
|
// No character limit - display the full email content
|
||||||
const maxChars = 1000;
|
|
||||||
const truncatedText = emailText.length > maxChars
|
|
||||||
? emailText.slice(0, maxChars) + '... [message truncated]'
|
|
||||||
: emailText;
|
|
||||||
|
|
||||||
const cleanHtml = `
|
const cleanHtml = `
|
||||||
${cleanReplyHeader}
|
${cleanReplyHeader}
|
||||||
<blockquote style="margin: 0; padding-left: 10px; border-left: 2px solid #ddd; color: #505050;">
|
<blockquote style="margin: 0; padding-left: 10px; border-left: 2px solid #ddd; color: #505050;">
|
||||||
<p>${truncatedText.replace(/\n/g, '</p><p>')}</p>
|
<p>${emailText.replace(/\n/g, '</p><p>')}</p>
|
||||||
</blockquote>
|
</blockquote>
|
||||||
`;
|
`;
|
||||||
|
|
||||||
// Plain text version
|
// Plain text version - no truncation
|
||||||
const plainText = `
|
const plainText = `
|
||||||
On ${dateStr}, ${fromStr} wrote:
|
On ${dateStr}, ${fromStr} wrote:
|
||||||
> ${truncatedText.split('\n').join('\n> ')}
|
> ${emailText.split('\n').join('\n> ')}
|
||||||
`;
|
`;
|
||||||
|
|
||||||
return {
|
return {
|
||||||
@ -353,16 +348,11 @@ export function formatForwardedEmail(originalEmail: EmailMessage | LegacyEmailMe
|
|||||||
</div>
|
</div>
|
||||||
`;
|
`;
|
||||||
|
|
||||||
// Limit text to reasonable size and format as simple HTML
|
// No character limit - display the full email content
|
||||||
const maxChars = 1500;
|
|
||||||
const truncatedText = emailText.length > maxChars
|
|
||||||
? emailText.slice(0, maxChars) + '... [message truncated]'
|
|
||||||
: emailText;
|
|
||||||
|
|
||||||
const cleanHtml = `
|
const cleanHtml = `
|
||||||
${cleanForwardHeader}
|
${cleanForwardHeader}
|
||||||
<blockquote style="margin: 0; padding-left: 10px; border-left: 2px solid #ddd; color: #505050;">
|
<blockquote style="margin: 0; padding-left: 10px; border-left: 2px solid #ddd; color: #505050;">
|
||||||
<p>${truncatedText.replace(/\n/g, '</p><p>')}</p>
|
<p>${emailText.replace(/\n/g, '</p><p>')}</p>
|
||||||
</blockquote>
|
</blockquote>
|
||||||
`;
|
`;
|
||||||
|
|
||||||
@ -375,7 +365,7 @@ Subject: ${subject || ''}
|
|||||||
To: ${toStr}
|
To: ${toStr}
|
||||||
${ccStr ? `Cc: ${ccStr}\n` : ''}
|
${ccStr ? `Cc: ${ccStr}\n` : ''}
|
||||||
|
|
||||||
${truncatedText}
|
${emailText}
|
||||||
`;
|
`;
|
||||||
|
|
||||||
// Check if original has attachments
|
// Check if original has attachments
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user