courrier preview
This commit is contained in:
parent
b149c52931
commit
3c57a3ed65
@ -1,5 +1,6 @@
|
||||
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
|
||||
@ -161,14 +162,17 @@ function normalizeContent(email: LegacyEmailMessage): EmailContent {
|
||||
else if (email.formattedContent) initialContent.html = email.formattedContent;
|
||||
}
|
||||
|
||||
// Use the centralized content processor
|
||||
const processedContent = processContentWithDirection(initialContent);
|
||||
// Use extractEmailContent from our centralized utilities
|
||||
const { html, text } = extractEmailContent(initialContent);
|
||||
|
||||
// Detect direction from text
|
||||
const direction = detectTextDirection(text || '');
|
||||
|
||||
return {
|
||||
html: processedContent.html,
|
||||
text: processedContent.text,
|
||||
isHtml: !!processedContent.html,
|
||||
direction: processedContent.direction
|
||||
html,
|
||||
text,
|
||||
isHtml: !!html,
|
||||
direction
|
||||
};
|
||||
} catch (error) {
|
||||
console.error('Error normalizing email content:', error);
|
||||
|
||||
@ -282,23 +282,18 @@ export function formatReplyEmail(originalEmail: EmailMessage | LegacyEmailMessag
|
||||
// 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>`;
|
||||
|
||||
// Limit text to reasonable size and format as simple HTML
|
||||
const maxChars = 1000;
|
||||
const truncatedText = emailText.length > maxChars
|
||||
? emailText.slice(0, maxChars) + '... [message truncated]'
|
||||
: emailText;
|
||||
|
||||
// No character limit - display the full email content
|
||||
const cleanHtml = `
|
||||
${cleanReplyHeader}
|
||||
<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>
|
||||
`;
|
||||
|
||||
// Plain text version
|
||||
// Plain text version - no truncation
|
||||
const plainText = `
|
||||
On ${dateStr}, ${fromStr} wrote:
|
||||
> ${truncatedText.split('\n').join('\n> ')}
|
||||
> ${emailText.split('\n').join('\n> ')}
|
||||
`;
|
||||
|
||||
return {
|
||||
@ -353,16 +348,11 @@ export function formatForwardedEmail(originalEmail: EmailMessage | LegacyEmailMe
|
||||
</div>
|
||||
`;
|
||||
|
||||
// Limit text to reasonable size and format as simple HTML
|
||||
const maxChars = 1500;
|
||||
const truncatedText = emailText.length > maxChars
|
||||
? emailText.slice(0, maxChars) + '... [message truncated]'
|
||||
: emailText;
|
||||
|
||||
// No character limit - display the full email content
|
||||
const cleanHtml = `
|
||||
${cleanForwardHeader}
|
||||
<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>
|
||||
`;
|
||||
|
||||
@ -375,7 +365,7 @@ Subject: ${subject || ''}
|
||||
To: ${toStr}
|
||||
${ccStr ? `Cc: ${ccStr}\n` : ''}
|
||||
|
||||
${truncatedText}
|
||||
${emailText}
|
||||
`;
|
||||
|
||||
// Check if original has attachments
|
||||
|
||||
Loading…
Reference in New Issue
Block a user