From 338f23104e4892afff45c325e41924447263f2be Mon Sep 17 00:00:00 2001 From: alma Date: Thu, 24 Apr 2025 16:36:21 +0200 Subject: [PATCH] mime change --- app/courrier/page.tsx | 338 ++++++++++++++++++++++++++++++++---------- 1 file changed, 258 insertions(+), 80 deletions(-) diff --git a/app/courrier/page.tsx b/app/courrier/page.tsx index 21938c49..6e931607 100644 --- a/app/courrier/page.tsx +++ b/app/courrier/page.tsx @@ -1128,6 +1128,184 @@ export default function CourrierPage() { } }; + // Add back the renderSidebarNav function + const renderSidebarNav = () => ( + + ); + + // Add back the handleReply function + const handleReply = (type: 'reply' | 'reply-all' | 'forward') => { + if (!selectedEmail) return; + + const getReplyTo = () => { + if (type === 'forward') return ''; + return selectedEmail.from; + }; + + const getReplyCc = () => { + if (type !== 'reply-all') return ''; + return selectedEmail.cc || ''; + }; + + const getReplySubject = () => { + const subject = selectedEmail.subject || ''; + if (type === 'forward') { + return subject.startsWith('Fwd:') ? subject : `Fwd: ${subject}`; + } + return subject.startsWith('Re:') ? subject : `Re: ${subject}`; + }; + + // Get the formatted original email content + const originalContent = getReplyBody(selectedEmail, type); + + // Create a clean structure with clear separation + const formattedContent = ` +
+
+ ${originalContent} +
+ `; + + // Update the compose form + setComposeTo(getReplyTo()); + setComposeCc(getReplyCc()); + setComposeSubject(getReplySubject()); + setComposeBody(formattedContent); + setComposeBcc(''); + + // Show the compose form and CC field for Reply All + setShowCompose(true); + setShowCc(type === 'reply-all'); + setShowBcc(false); + setAttachments([]); + }; + + // Add back the toggleStarred function + const toggleStarred = async (emailId: number, e?: React.MouseEvent) => { + if (e) { + e.stopPropagation(); + } + + const email = emails.find(e => e.id === emailId); + if (!email) return; + + try { + const response = await fetch('/api/courrier/toggle-star', { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + }, + body: JSON.stringify({ emailId, starred: !email.starred }), + }); + + if (!response.ok) { + throw new Error('Failed to toggle star'); + } + + // Update email in state + setEmails(emails.map(e => + e.id === emailId ? { ...e, starred: !e.starred } : e + )); + } catch (error) { + console.error('Error toggling star:', error); + } + }; + + // Add back the handleSend function + const handleSend = async () => { + if (!composeTo) { + alert('Please specify at least one recipient'); + return; + } + + try { + const response = await fetch('/api/courrier/send', { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + }, + body: JSON.stringify({ + to: composeTo, + cc: composeCc, + bcc: composeBcc, + subject: composeSubject, + body: composeBody, + attachments: attachments, + }), + }); + + const data = await response.json(); + + if (!response.ok) { + if (data.error === 'Attachment size limit exceeded') { + alert(`Error: ${data.error}\nThe following files are too large:\n${data.details.oversizedFiles.join('\n')}`); + } else { + alert(`Error sending email: ${data.error}`); + } + return; + } + + // Clear compose form and close modal + setComposeTo(''); + setComposeCc(''); + setComposeBcc(''); + setComposeSubject(''); + setComposeBody(''); + setAttachments([]); + setShowCompose(false); + } catch (error) { + console.error('Error sending email:', error); + alert('Failed to send email. Please try again.'); + } + }; + + // Add back the renderDeleteConfirmDialog function + const renderDeleteConfirmDialog = () => ( + + + + Delete Emails + + Are you sure you want to delete {selectedEmails.length} selected email{selectedEmails.length > 1 ? 's' : ''}? This action cannot be undone. + + + + Cancel + Delete + + + + ); + if (error) { return (
@@ -1152,92 +1330,92 @@ export default function CourrierPage() {
- {/* Sidebar */} -
- {/* Courrier Title */} -
-
- - COURRIER -
-
- - {/* Compose button and refresh button */} -
- - -
- {/* Accounts Section */} -
- - - {accountsDropdownOpen && ( -
- {accounts.map(account => ( -
- + {/* Compose button and refresh button */} +
+ +
- )} -
- {/* Navigation */} - {renderSidebarNav()} -
+ {/* Accounts Section */} +
+ + + {accountsDropdownOpen && ( +
+ {accounts.map(account => ( +
+ +
+ ))} +
+ )} +
- {/* Main content area */} -
- {/* Email list panel */} - {renderEmailListWrapper()} -
-
+ {/* Navigation */} + {renderSidebarNav()}
+ + {/* Main content area */} +
+ {/* Email list panel */} + {renderEmailListWrapper()} +
+
+
{/* Compose Email Modal */} @@ -1283,4 +1461,4 @@ export default function CourrierPage() { {renderDeleteConfirmDialog()} ); -} +} \ No newline at end of file