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