diff --git a/components/email/email-viewer.tsx b/components/email/email-viewer.tsx
index 563291be..0193011f 100644
--- a/components/email/email-viewer.tsx
+++ b/components/email/email-viewer.tsx
@@ -61,6 +61,7 @@ import {
Inbox,
Folder,
Sun,
+ Upload,
Moon,
HelpCircle,
} from "lucide-react";
@@ -72,6 +73,7 @@ import { useContactStore, getContactDisplayName, getContactPrimaryEmail } from "
import { toast } from "@/stores/toast-store";
import { useDeviceDetection } from "@/hooks/use-media-query";
import { useAuthStore } from "@/stores/auth-store";
+import { useEmailStore } from "@/stores/email-store";
import { useThemeStore } from "@/stores/theme-store";
import { EmailIdentityBadge } from "./email-identity-badge";
import { UnsubscribeBanner } from "./unsubscribe-banner";
@@ -2221,6 +2223,45 @@ export function EmailViewer({
}
}, []);
+ // Export email as .eml file
+ const handleExportEmail = async () => {
+ if (!email?.blobId || !client) return;
+ try {
+ const subject = (email.subject || 'email').replace(/[<>:"/\\|?*]+/g, '_').slice(0, 100);
+ await client.downloadBlob(email.blobId, `${subject}.eml`, 'message/rfc822');
+ } catch {
+ toast.error(tNotifications('export_email_error'));
+ }
+ };
+
+ // Import email from .eml file
+ const handleImportEmail = () => {
+ if (!client) return;
+ const input = document.createElement('input');
+ input.type = 'file';
+ input.accept = '.eml,message/rfc822';
+ input.onchange = async (e) => {
+ const file = (e.target as HTMLInputElement).files?.[0];
+ if (!file) return;
+ try {
+ const { selectedMailbox, mailboxes, fetchEmails } = useEmailStore.getState();
+ const mailbox = mailboxes.find(mb => mb.id === selectedMailbox);
+ const mailboxId = mailbox?.originalId || selectedMailbox;
+ if (!mailboxId) {
+ toast.error(tNotifications('import_email_error'));
+ return;
+ }
+ const blob = new Blob([await file.arrayBuffer()], { type: 'message/rfc822' });
+ await client.importRawEmail(blob, { [mailboxId]: true }, { '$seen': true });
+ toast.success(tNotifications('import_email_success'));
+ await fetchEmails(client);
+ } catch {
+ toast.error(tNotifications('import_email_error'));
+ }
+ };
+ input.click();
+ };
+
// Print only the email content in a new window
const handlePrint = () => {
if (!email) return;
@@ -2483,6 +2524,21 @@ export function EmailViewer({
{t('view_source')}
+