courrier clean 2$
This commit is contained in:
parent
d7bbb68b5e
commit
104c0d9f94
@ -49,9 +49,7 @@ import {
|
||||
CommandShortcut,
|
||||
} from '@/components/ui/command';
|
||||
import { useSession } from 'next-auth/react';
|
||||
import DOMPurify from 'isomorphic-dompurify';
|
||||
import ComposeEmail from '@/components/email/ComposeEmail';
|
||||
import { decodeEmail, cleanHtml } from '@/lib/mail-parser-wrapper';
|
||||
import { Attachment as MailParserAttachment } from 'mailparser';
|
||||
import { LoadingFix } from './loading-fix';
|
||||
|
||||
@ -169,15 +167,15 @@ function EmailContent({ email }: { email: Email }) {
|
||||
// Update the email content with the fetched full content
|
||||
email.content = fullContent.content;
|
||||
|
||||
// Render the content
|
||||
const sanitizedHtml = DOMPurify.sanitize(fullContent.content);
|
||||
// Render the content using the centralized cleaner
|
||||
const sanitizedHtml = cleanHtmlContent(fullContent.content);
|
||||
setContent(
|
||||
<div
|
||||
className="email-content prose prose-sm max-w-none dark:prose-invert"
|
||||
dangerouslySetInnerHTML={{ __html: sanitizedHtml }}
|
||||
/>
|
||||
);
|
||||
setDebugInfo('Rendered fetched HTML content');
|
||||
setDebugInfo('Rendered fetched HTML content with centralized formatter');
|
||||
setError(null);
|
||||
setIsLoading(false);
|
||||
}
|
||||
@ -200,39 +198,36 @@ function EmailContent({ email }: { email: Email }) {
|
||||
|
||||
// Check if content is already HTML
|
||||
if (formattedEmail.startsWith('<') && formattedEmail.endsWith('>')) {
|
||||
// Content is likely HTML, sanitize and display directly
|
||||
const sanitizedHtml = DOMPurify.sanitize(formattedEmail);
|
||||
// Content is likely HTML, sanitize using the centralized cleaner
|
||||
const sanitizedHtml = cleanHtmlContent(formattedEmail);
|
||||
setContent(
|
||||
<div
|
||||
className="email-content prose prose-sm max-w-none dark:prose-invert"
|
||||
dangerouslySetInnerHTML={{ __html: sanitizedHtml }}
|
||||
/>
|
||||
);
|
||||
setDebugInfo('Rendered existing HTML content');
|
||||
setDebugInfo('Rendered existing HTML content with centralized formatter');
|
||||
} else {
|
||||
// Use mailparser for more complex formats
|
||||
console.log('Parsing email content');
|
||||
const parsedEmail = await decodeEmail(formattedEmail);
|
||||
// For plain text or complex formats, use the centralized formatter
|
||||
const cleanedContent = cleanHtmlContent(formattedEmail);
|
||||
|
||||
if (parsedEmail.html) {
|
||||
const sanitizedHtml = DOMPurify.sanitize(parsedEmail.html);
|
||||
// If it looks like HTML, render it as HTML
|
||||
if (cleanedContent.includes('<') && cleanedContent.includes('>')) {
|
||||
setContent(
|
||||
<div
|
||||
className="email-content prose prose-sm max-w-none dark:prose-invert"
|
||||
dangerouslySetInnerHTML={{ __html: sanitizedHtml }}
|
||||
dangerouslySetInnerHTML={{ __html: cleanedContent }}
|
||||
/>
|
||||
);
|
||||
setDebugInfo('Rendered HTML content from parser');
|
||||
} else if (parsedEmail.text) {
|
||||
setDebugInfo('Rendered content as HTML using centralized formatter');
|
||||
} else {
|
||||
// Otherwise, render as plain text
|
||||
setContent(
|
||||
<div className="email-content whitespace-pre-wrap">
|
||||
{parsedEmail.text}
|
||||
{cleanedContent}
|
||||
</div>
|
||||
);
|
||||
setDebugInfo('Rendered text content from parser');
|
||||
} else {
|
||||
setContent(<div className="text-gray-500">No displayable content available</div>);
|
||||
setDebugInfo('No HTML or text content in parsed email');
|
||||
setDebugInfo('Rendered content as text using centralized formatter');
|
||||
}
|
||||
}
|
||||
|
||||
@ -458,19 +453,20 @@ function EmailPreview({ email }: { email: Email }) {
|
||||
try {
|
||||
// If we have the content already, extract preview from it
|
||||
if (email.content) {
|
||||
const plainText = email.content.replace(/<[^>]*>/g, ' ').trim();
|
||||
// Use cleanHtmlContent to safely extract text from HTML
|
||||
const cleanContent = cleanHtmlContent(email.content);
|
||||
const plainText = cleanContent.replace(/<[^>]*>/g, ' ').trim();
|
||||
if (mounted) {
|
||||
setPreview(plainText.substring(0, 150) + '...');
|
||||
}
|
||||
} else {
|
||||
// Fallback to using parser for older emails
|
||||
const decoded = await decodeEmail(email.content || '');
|
||||
// Use the centralized cleaner instead of decodeEmail
|
||||
const cleanContent = cleanHtmlContent(email.content || '');
|
||||
const plainText = cleanContent.replace(/<[^>]*>/g, ' ').trim();
|
||||
|
||||
if (mounted) {
|
||||
if (decoded.text) {
|
||||
setPreview(decoded.text.substring(0, 150) + '...');
|
||||
} else if (decoded.html) {
|
||||
const cleanText = decoded.html.replace(/<[^>]*>/g, ' ').trim();
|
||||
setPreview(cleanText.substring(0, 150) + '...');
|
||||
if (plainText) {
|
||||
setPreview(plainText.substring(0, 150) + '...');
|
||||
} else {
|
||||
setPreview('No preview available');
|
||||
}
|
||||
@ -518,6 +514,20 @@ function generateEmailPreview(email: Email) {
|
||||
return <EmailPreview email={email} />;
|
||||
}
|
||||
|
||||
// Add this interface before the CourrierPage component
|
||||
interface EmailData {
|
||||
to: string;
|
||||
cc?: string;
|
||||
bcc?: string;
|
||||
subject: string;
|
||||
body: string;
|
||||
attachments?: Array<{
|
||||
name: string;
|
||||
content: string;
|
||||
type: string;
|
||||
}>;
|
||||
}
|
||||
|
||||
export default function CourrierPage() {
|
||||
const router = useRouter();
|
||||
const { data: session } = useSession();
|
||||
@ -2363,7 +2373,7 @@ export default function CourrierPage() {
|
||||
attachments={attachments}
|
||||
setAttachments={setAttachments}
|
||||
handleSend={handleSend}
|
||||
onSend={async (emailData) => {
|
||||
onSend={async (emailData: EmailData) => {
|
||||
console.log('Email sent:', emailData);
|
||||
setShowCompose(false);
|
||||
setIsReplying(false);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user