From 7269d4a07d7e885f41f37fc3acc5b7652728a039 Mon Sep 17 00:00:00 2001 From: alma Date: Fri, 25 Apr 2025 16:55:06 +0200 Subject: [PATCH] panel 2 courier api --- app/courrier/page.tsx | 41 +++++++++++++++++++++++++++++++++++------ 1 file changed, 35 insertions(+), 6 deletions(-) diff --git a/app/courrier/page.tsx b/app/courrier/page.tsx index 75bf143d..5f23b293 100644 --- a/app/courrier/page.tsx +++ b/app/courrier/page.tsx @@ -101,36 +101,65 @@ function splitEmailHeadersAndBody(emailBody: string): { headers: string; body: s } function EmailContent({ email }: { email: Email }) { + // Add debugging logs + console.log("EmailContent rendering with:", { + hasContent: Boolean(email.content), + contentLength: email.content?.length || 0, + hasTextContent: Boolean(email.textContent), + textContentLength: email.textContent?.length || 0, + hasRawContent: Boolean(email.rawContent), + rawContentLength: email.rawContent?.length || 0, + hasBody: Boolean(email.body), + bodyLength: email.body?.length || 0 + }); + // Use state to track if we've rendered content const [renderedContent, setRenderedContent] = useState(false); + // Use a more defensive approach with content + const hasContent = email.content !== undefined && email.content !== null && email.content.trim() !== ''; + const hasTextContent = email.textContent !== undefined && email.textContent !== null && email.textContent.trim() !== ''; + const hasRawContent = email.rawContent !== undefined && email.rawContent !== null && email.rawContent.trim() !== ''; + const hasBody = email.body !== undefined && email.body !== null && email.body.trim() !== ''; + // If textContent is available, render it directly - if (email.textContent && !renderedContent) { + if (hasTextContent && !renderedContent) { setRenderedContent(true); return (
- {email.textContent} + {email.textContent || ''}
); } // If html content is available, render it directly - if (email.content && !renderedContent) { + if (hasContent && !renderedContent) { setRenderedContent(true); return (
+ ); + } + + // Try body field (backward compatibility) + if (hasBody && !renderedContent) { + setRenderedContent(true); + return ( +
); } // Fallback to raw content if available - if (email.rawContent && !renderedContent) { + if (hasRawContent && !renderedContent) { setRenderedContent(true); return (
- {email.rawContent} + {email.rawContent || ''}
); }