import { useEffect, useState } from 'react' import { open } from '@tauri-apps/plugin-dialog' import { HardDrive, Inbox, Upload, X } from 'lucide-react' import type { Account, Folder } from '../types' import { api } from '../lib/api' const inputClass = 'rounded-lg border border-zinc-200 bg-white px-3 py-1.5 text-[13px] text-zinc-800 outline-none transition focus:border-indigo-400 focus:ring-2 focus:ring-indigo-100 dark:border-zinc-700 dark:bg-zinc-900 dark:text-zinc-100 dark:focus:ring-indigo-500/20' export function ImportModal({ open: isOpen, accounts, onClose, onImported, }: { open: boolean accounts: Account[] onClose: () => void onImported: (accountId: string, folder: string) => void }) { const targets = accounts.filter((a) => a.protocol === 'local' || a.protocol === 'imap') const [accountId, setAccountId] = useState('') const [folders, setFolders] = useState([]) const [folder, setFolder] = useState('') const [loadingFolders, setLoadingFolders] = useState(false) const [importing, setImporting] = useState(false) const [error, setError] = useState(null) useEffect(() => { if (isOpen) { const first = targets[0]?.id ?? '' setAccountId(first) setError(null) } // eslint-disable-next-line react-hooks/exhaustive-deps }, [isOpen]) useEffect(() => { if (!accountId) return const account = accounts.find((a) => a.id === accountId) if (!account) return if (account.protocol === 'local') { setFolders([{ name: 'Importiert', display_name: 'Importiert', unread: 0 }]) setFolder('Importiert') return } setLoadingFolders(true) api .listFolders(accountId) .then((f) => { setFolders(f) setFolder(f[0]?.name ?? '') }) .catch((e) => setError(String(e))) .finally(() => setLoadingFolders(false)) }, [accountId, accounts]) if (!isOpen) return null async function handlePickAndImport() { if (!accountId || !folder) return setError(null) const path = await open({ multiple: false, filters: [{ name: 'E-Mail', extensions: ['eml', 'mbox', 'mbx'] }], }) if (!path || Array.isArray(path)) return setImporting(true) try { if (path.toLowerCase().endsWith('.eml')) { await api.importEmlFile(accountId, folder, path) } else { await api.importMboxFile(accountId, folder, path) } onImported(accountId, folder) onClose() } catch (e) { setError(String(e)) } finally { setImporting(false) } } return (

Mail importieren

Unterstützt .eml (einzelne Nachricht) und .mbox (mehrere Nachrichten). Wähle zuerst, wohin importiert werden soll.

{accounts.find((a) => a.id === accountId)?.protocol === 'imap' && ( )} {accounts.find((a) => a.id === accountId)?.protocol === 'local' && (
Nachrichten werden nur lokal gespeichert, nicht auf einen Server hochgeladen.
)} {accounts.find((a) => a.id === accountId)?.protocol === 'imap' && (
Nachrichten werden per IMAP wirklich in dieses Postfach hochgeladen.
)} {error && (

{error}

)}
) }