panel 2 courier api restore
This commit is contained in:
parent
65cd0f37ec
commit
2abeec4a8c
@ -135,17 +135,24 @@ function EmailContent({ email }: { email: Email }) {
|
|||||||
if (mounted) {
|
if (mounted) {
|
||||||
// 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;
|
||||||
email.contentFetched = true;
|
|
||||||
|
|
||||||
// Render the content - call ourselves again now that we have content
|
// Render the content
|
||||||
setDebugInfo('Content fetched from API, reprocessing');
|
const sanitizedHtml = DOMPurify.sanitize(fullContent.content);
|
||||||
loadContent();
|
setContent(
|
||||||
return;
|
<div
|
||||||
|
className="email-content prose prose-sm max-w-none dark:prose-invert"
|
||||||
|
dangerouslySetInnerHTML={{ __html: sanitizedHtml }}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
setDebugInfo('Rendered fetched HTML content');
|
||||||
|
setError(null);
|
||||||
|
setIsLoading(false);
|
||||||
}
|
}
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Use existing content if available
|
// Use existing content if available
|
||||||
console.log('Processing content for email:', email.id);
|
console.log('Using existing content for email');
|
||||||
|
|
||||||
const formattedEmail = email.content.trim();
|
const formattedEmail = email.content.trim();
|
||||||
if (!formattedEmail) {
|
if (!formattedEmail) {
|
||||||
@ -158,13 +165,23 @@ function EmailContent({ email }: { email: Email }) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
// Check if content is already HTML
|
||||||
// Always try to use the mail parser first for consistency
|
if (formattedEmail.startsWith('<') && formattedEmail.endsWith('>')) {
|
||||||
console.log('Parsing email content with mailparser');
|
// Content is likely HTML, sanitize and display directly
|
||||||
|
const sanitizedHtml = DOMPurify.sanitize(formattedEmail);
|
||||||
|
setContent(
|
||||||
|
<div
|
||||||
|
className="email-content prose prose-sm max-w-none dark:prose-invert"
|
||||||
|
dangerouslySetInnerHTML={{ __html: sanitizedHtml }}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
setDebugInfo('Rendered existing HTML content');
|
||||||
|
} else {
|
||||||
|
// Use mailparser for more complex formats
|
||||||
|
console.log('Parsing email content');
|
||||||
const parsedEmail = await decodeEmail(formattedEmail);
|
const parsedEmail = await decodeEmail(formattedEmail);
|
||||||
|
|
||||||
if (parsedEmail.html) {
|
if (parsedEmail.html) {
|
||||||
console.log('Using HTML content from parser');
|
|
||||||
const sanitizedHtml = DOMPurify.sanitize(parsedEmail.html);
|
const sanitizedHtml = DOMPurify.sanitize(parsedEmail.html);
|
||||||
setContent(
|
setContent(
|
||||||
<div
|
<div
|
||||||
@ -174,7 +191,6 @@ function EmailContent({ email }: { email: Email }) {
|
|||||||
);
|
);
|
||||||
setDebugInfo('Rendered HTML content from parser');
|
setDebugInfo('Rendered HTML content from parser');
|
||||||
} else if (parsedEmail.text) {
|
} else if (parsedEmail.text) {
|
||||||
console.log('Using text content from parser');
|
|
||||||
setContent(
|
setContent(
|
||||||
<div className="email-content whitespace-pre-wrap">
|
<div className="email-content whitespace-pre-wrap">
|
||||||
{parsedEmail.text}
|
{parsedEmail.text}
|
||||||
@ -182,48 +198,8 @@ function EmailContent({ email }: { email: Email }) {
|
|||||||
);
|
);
|
||||||
setDebugInfo('Rendered text content from parser');
|
setDebugInfo('Rendered text content from parser');
|
||||||
} else {
|
} else {
|
||||||
// Fallback to direct display if parser didn't give us anything
|
setContent(<div className="text-gray-500">No displayable content available</div>);
|
||||||
if (formattedEmail.startsWith('<') && formattedEmail.endsWith('>')) {
|
setDebugInfo('No HTML or text content in parsed email');
|
||||||
// Content is likely HTML, sanitize and display directly
|
|
||||||
const sanitizedHtml = DOMPurify.sanitize(formattedEmail);
|
|
||||||
setContent(
|
|
||||||
<div
|
|
||||||
className="email-content prose prose-sm max-w-none dark:prose-invert"
|
|
||||||
dangerouslySetInnerHTML={{ __html: sanitizedHtml }}
|
|
||||||
/>
|
|
||||||
);
|
|
||||||
setDebugInfo('Rendered raw HTML content');
|
|
||||||
} else {
|
|
||||||
// Just display as text
|
|
||||||
setContent(
|
|
||||||
<div className="email-content whitespace-pre-wrap">
|
|
||||||
{formattedEmail}
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
setDebugInfo('Rendered raw text content');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (parseError) {
|
|
||||||
console.error('Error parsing email with mailparser:', parseError);
|
|
||||||
// Fallback to direct display if parser fails
|
|
||||||
if (formattedEmail.startsWith('<') && formattedEmail.endsWith('>')) {
|
|
||||||
// Content is likely HTML, sanitize and display directly
|
|
||||||
const sanitizedHtml = DOMPurify.sanitize(formattedEmail);
|
|
||||||
setContent(
|
|
||||||
<div
|
|
||||||
className="email-content prose prose-sm max-w-none dark:prose-invert"
|
|
||||||
dangerouslySetInnerHTML={{ __html: sanitizedHtml }}
|
|
||||||
/>
|
|
||||||
);
|
|
||||||
setDebugInfo('Fallback: Rendered as HTML after parser error');
|
|
||||||
} else {
|
|
||||||
// Just display as text
|
|
||||||
setContent(
|
|
||||||
<div className="email-content whitespace-pre-wrap">
|
|
||||||
{formattedEmail}
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
setDebugInfo('Fallback: Rendered as text after parser error');
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user