diff --git a/app/mail/page.tsx b/app/mail/page.tsx
index 92f1e15..7c95146 100644
--- a/app/mail/page.tsx
+++ b/app/mail/page.tsx
@@ -558,11 +558,21 @@ export default function MailPage() {
const email = emails.find(e => e.id === emailId);
if (email) {
setSelectedEmail(email);
- // Mark as read
- const updatedEmails = emails.map(e =>
- e.id === emailId ? { ...e, read: true } : e
- );
- setEmails(updatedEmails);
+ if (!email.read) {
+ // Mark as read in state
+ setEmails(emails.map(e =>
+ e.id === emailId ? { ...e, read: true } : e
+ ));
+
+ // Update read status on server
+ fetch('/api/mail/mark-read', {
+ method: 'POST',
+ headers: { 'Content-Type': 'application/json' },
+ body: JSON.stringify({ emailId })
+ }).catch(error => {
+ console.error('Error marking email as read:', error);
+ });
+ }
}
};
@@ -1037,36 +1047,29 @@ export default function MailPage() {
- {/* Delete Confirmation Dialog */}
-