diff --git a/app/courrier/page.tsx b/app/courrier/page.tsx index 78cb5a2a..91b8b126 100644 --- a/app/courrier/page.tsx +++ b/app/courrier/page.tsx @@ -453,6 +453,15 @@ function EmailPreview({ email }: { email: Email }) { setIsLoading(true); try { + // Check if content is already a simple preview string (less than 1000 chars) + if (email.content.length < 1000 && !email.content.includes('Content-Type:')) { + setPreview(email.content.substring(0, 150) + '...'); + setError(null); + setIsLoading(false); + return; + } + + // Otherwise try to decode it const decoded = await decodeEmail(email.content); if (mounted) { if (decoded.text) { @@ -468,8 +477,9 @@ function EmailPreview({ email }: { email: Email }) { } catch (err) { console.error('Error generating email preview:', err); if (mounted) { - setError('Error generating preview'); - setPreview(''); + // Fallback to displaying the raw content if decoding fails + setPreview(email.content.substring(0, 150) + '...'); + setError(null); } } finally { if (mounted) setIsLoading(false); @@ -712,7 +722,7 @@ export default function CourrierPage() { // Include skipCache parameter to bypass any server-side caching const response = await fetch( - `/api/courrier?folder=${encodeURIComponent(currentView)}&page=1&limit=${emailsPerPage}&_t=${timestamp}&skipCache=true`, + `/api/courrier?folder=${encodeURIComponent(currentView)}&page=1&limit=${emailsPerPage}&_t=${timestamp}&skipCache=true&preview=true`, { cache: 'no-store', headers: { @@ -764,7 +774,7 @@ export default function CourrierPage() { fromName: email.fromName || email.from?.split('@')[0] || '', to: email.to || '', subject: email.subject || '(No subject)', - content: email.preview || '', + content: email.preview || email.content || '', date: email.date || new Date().toISOString(), read: email.read || false, starred: email.starred || false, @@ -820,7 +830,7 @@ export default function CourrierPage() { const timestamp = isLoadMore || page > 1 ? '' : `&_t=${Date.now()}`; const response = await fetch( - `/api/courrier?folder=${encodeURIComponent(currentView)}&page=${page}&limit=${emailsPerPage}${timestamp}`, + `/api/courrier?folder=${encodeURIComponent(currentView)}&page=${page}&limit=${emailsPerPage}${timestamp}&preview=true`, { cache: 'no-store' } ); @@ -865,7 +875,7 @@ export default function CourrierPage() { fromName: email.fromName || email.from?.split('@')[0] || '', to: email.to || '', subject: email.subject || '(No subject)', - content: email.preview || '', // Store preview as initial content + content: email.preview || email.content || '', // Ensure we use preview if available date: email.date || new Date().toISOString(), read: email.read || false, starred: email.starred || false, @@ -1521,7 +1531,7 @@ export default function CourrierPage() { const controller = new AbortController(); const timeoutId = setTimeout(() => controller.abort(), 10000); // 10 second timeout - const response = await fetch(`/api/courrier?folder=${encodeURIComponent(newMailbox)}&page=1&limit=${emailsPerPage}`, { + const response = await fetch(`/api/courrier?folder=${encodeURIComponent(newMailbox)}&page=1&limit=${emailsPerPage}&preview=true`, { signal: controller.signal }); @@ -1542,6 +1552,7 @@ export default function CourrierPage() { to: email.to || '', subject: email.subject || '(No subject)', body: email.body || '', + content: email.preview || email.content || '', date: email.date || new Date().toISOString(), read: email.read || false, starred: email.starred || false,