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) {
|
||||
// Update the email content with the fetched full content
|
||||
email.content = fullContent.content;
|
||||
email.contentFetched = true;
|
||||
|
||||
// Render the content - call ourselves again now that we have content
|
||||
setDebugInfo('Content fetched from API, reprocessing');
|
||||
loadContent();
|
||||
return;
|
||||
// Render the content
|
||||
const sanitizedHtml = DOMPurify.sanitize(fullContent.content);
|
||||
setContent(
|
||||
<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
|
||||
console.log('Processing content for email:', email.id);
|
||||
console.log('Using existing content for email');
|
||||
|
||||
const formattedEmail = email.content.trim();
|
||||
if (!formattedEmail) {
|
||||
@ -158,13 +165,23 @@ function EmailContent({ email }: { email: Email }) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
// Always try to use the mail parser first for consistency
|
||||
console.log('Parsing email content with mailparser');
|
||||
// Check if content is already HTML
|
||||
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('Rendered existing HTML content');
|
||||
} else {
|
||||
// Use mailparser for more complex formats
|
||||
console.log('Parsing email content');
|
||||
const parsedEmail = await decodeEmail(formattedEmail);
|
||||
|
||||
if (parsedEmail.html) {
|
||||
console.log('Using HTML content from parser');
|
||||
const sanitizedHtml = DOMPurify.sanitize(parsedEmail.html);
|
||||
setContent(
|
||||
<div
|
||||
@ -174,7 +191,6 @@ function EmailContent({ email }: { email: Email }) {
|
||||
);
|
||||
setDebugInfo('Rendered HTML content from parser');
|
||||
} else if (parsedEmail.text) {
|
||||
console.log('Using text content from parser');
|
||||
setContent(
|
||||
<div className="email-content whitespace-pre-wrap">
|
||||
{parsedEmail.text}
|
||||
@ -182,48 +198,8 @@ function EmailContent({ email }: { email: Email }) {
|
||||
);
|
||||
setDebugInfo('Rendered text content from parser');
|
||||
} else {
|
||||
// Fallback to direct display if parser didn't give us anything
|
||||
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('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');
|
||||
setContent(<div className="text-gray-500">No displayable content available</div>);
|
||||
setDebugInfo('No HTML or text content in parsed email');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user