From 3daa93bc95b17a62061005889b5c5af072672c1f Mon Sep 17 00:00:00 2001 From: alma Date: Tue, 15 Apr 2025 21:57:48 +0200 Subject: [PATCH] mail page imap connection 14 --- app/mail/page.tsx | 61 ++++++++++++++++++----------------------------- 1 file changed, 23 insertions(+), 38 deletions(-) diff --git a/app/mail/page.tsx b/app/mail/page.tsx index 54dafa3..b911bb8 100644 --- a/app/mail/page.tsx +++ b/app/mail/page.tsx @@ -41,35 +41,30 @@ interface Email { category: string; } -// Improved MIME decoding function +// Improved MIME decoding function for all emails const decodeMimeContent = (content: string) => { try { - // First, try to extract the main content + // Remove MIME headers and metadata let cleanContent = content - // Remove MIME headers and metadata - .replace(/^This is a multi-part message.*?utf-8"/s, '') + // Remove MIME headers + .replace(/^This is a multi-part message.*?charset="utf-8"/s, '') .replace(/---InfomaniakPhpMail.*?Content-Transfer-Encoding:.*?\n/g, '') .replace(/Content-Type:.*?\n/g, '') .replace(/Content-Transfer-Encoding:.*?\n/g, '') - // Clean up special characters and formatting - .replace(/=C2=A0/g, ' ') - .replace(/=\n/g, '') + // Clean up special characters and encoding + .replace(/=C2=A0/g, ' ') // non-breaking space + .replace(/=E2=80=(93|94)/g, '-') // dashes + .replace(/=\n/g, '') // soft line breaks .replace(/=([0-9A-F]{2})/g, (_, hex) => String.fromCharCode(parseInt(hex, 16))) - .replace(/\[IMG:.*?\]/g, '') - .replace(/\*([^*]+)\*/g, '$1') - .replace(/\[ ?LINK: ([^\]]+) ?\]/g, '$1') + // Format links and content markers + .replace(/\[IMG:(.*?)\]/g, '') // remove image placeholders + .replace(/\[ ?LINK: ([^\]]+?) ?\]/g, (_, url) => url) // clean up links + .replace(/\*(.*?)\*/g, '$1') // remove asterisk formatting // Clean up whitespace - .replace(/\s+/g, ' ') + .replace(/\n{3,}/g, '\n\n') // reduce multiple line breaks + .replace(/^\s+|\s+$/gm, '') // trim each line .trim(); - // Extract just the welcome message and first paragraph if it's the welcome email - if (cleanContent.includes('Welcome to your professional mailbox')) { - const welcomeMatch = cleanContent.match(/Welcome to your professional mailbox!(.+?)(?=\*Getting started\*|$)/s); - if (welcomeMatch) { - return welcomeMatch[0].trim(); - } - } - return cleanContent; } catch (error) { console.error('Error decoding MIME content:', error); @@ -173,24 +168,14 @@ export default function MailPage() { return account ? account.color : 'bg-gray-500'; }; - // Handle email selection - const handleEmailClick = async (emailId: number) => { - // Mark as read in IMAP - try { - await fetch('/api/mail/mark-read', { - method: 'POST', - headers: { 'Content-Type': 'application/json' }, - body: JSON.stringify({ emailId }) - }); - - const updatedEmails = emails.map(email => - email.id === emailId ? { ...email, read: true } : email - ); - setEmails(updatedEmails); - setSelectedEmail(emailId); - } catch (error) { - console.error('Error marking email as read:', error); - } + // Update email click handler to work without mark-read endpoint + const handleEmailClick = (emailId: number) => { + // Since the mark-read endpoint is not available, just update the UI + const updatedEmails = emails.map(email => + email.id === emailId ? { ...email, read: true } : email + ); + setEmails(updatedEmails); + setSelectedEmail(emailId); }; // Toggle starred status @@ -743,7 +728,7 @@ export default function MailPage() {
-

{getSelectedEmail()?.body}

+

{decodeMimeContent(getSelectedEmail()?.body || '')}

)}