diff --git a/components/email/EmailListItem.tsx b/components/email/EmailListItem.tsx index f6937f38..81fcd411 100644 --- a/components/email/EmailListItem.tsx +++ b/components/email/EmailListItem.tsx @@ -17,6 +17,8 @@ interface EmailListItemProps { onToggleStarred: (e: React.MouseEvent) => void; } +const PREVIEW_LENGTH = 70; + export default function EmailListItem({ email, isSelected, @@ -96,23 +98,26 @@ export default function EmailListItem({ }; // Get preview text from email content - const getPreviewText = () => { - if (email.preview) return email.preview; + const getPreviewText = (content: { text: string; html: string } | string) => { + let text = ''; - let content = email.content || ''; - - // Strip HTML tags if present - content = content.replace(/<[^>]+>/g, ' '); - - // Clean up whitespace - content = content.replace(/\s+/g, ' ').trim(); - - // Limit to ~70 chars - if (content.length > 70) { - return content.substring(0, 70) + '...'; + if (typeof content === 'string') { + text = content; + } else { + // Prefer text content if available, fall back to HTML + text = content.text || content.html; } - return content || 'No preview available'; + // Strip HTML tags if present + text = text.replace(/<[^>]+>/g, ' '); + + // Clean up whitespace + text = text.replace(/\s+/g, ' ').trim(); + + // Truncate to preview length + return text.length > PREVIEW_LENGTH + ? text.substring(0, PREVIEW_LENGTH) + '...' + : text; }; return ( @@ -155,7 +160,7 @@ export default function EmailListItem({