mirror of
https://github.com/bulwarkmail/webmail.git
synced 2026-11-02 00:14:23 +00:00
A message that failed for a passing reason (a dropped connection, a server error, an expired token) used to count as done, so continuing the import skipped it for good, and a slow upload followed by a cancel imported the messages after it twice. - The checkpoint keeps every message that is done, also past a gap, and the next run of the same import tries only the rest again. - Ten failures in a row, a full mailbox (overQuota) or a refusal (forbidden) stop the import with a message instead of going through the whole file. - An upload without an answer pauses the import instead of failing the message: 30 seconds, then until the upload window ends. - Email/import, the export's Blob/get and folder listing pass the client's own 429 pause by, and a 429 on them doesn't pause the rest of the app. - Signing out stops the job of that account only, writes no checkpoint and imports nothing more afterwards; another account's sign-out leaves the job alone. - One tab imports a file at a time (Web Locks), and Import waits until the dialog knows whether an earlier run can be continued. The import dialog tests now wait for the Import button to be enabled before clicking it, since it stays off during that lookup.
64 lines
2.1 KiB
TypeScript
64 lines
2.1 KiB
TypeScript
import { runExport, folderTree, type ExportFolder, type ExportFormat } from "@/lib/mail-export/engine";
|
|
import type { ExportSink } from "@/lib/mail-export/sinks";
|
|
import type { IJMAPClient } from "@/lib/jmap/client-interface";
|
|
import { useAuthStore } from "@/stores/auth-store";
|
|
import { useMailTransferStore } from "@/stores/mail-transfer-store";
|
|
|
|
export interface StartExportInput {
|
|
format: ExportFormat;
|
|
/** JMAP account of the folder (or of the whole export). */
|
|
accountId: string;
|
|
/** One folder (its id in its account); the whole account when absent. */
|
|
mailboxId?: string;
|
|
sink: ExportSink;
|
|
}
|
|
|
|
/** Runs an export as the dialog's job. */
|
|
export function startExport(input: StartExportInput): void {
|
|
const auth = useAuthStore.getState();
|
|
if (!auth.client) return;
|
|
const client: IJMAPClient = auth.client;
|
|
const controller = new AbortController();
|
|
let ended: () => void = () => {};
|
|
const finished = new Promise<void>((resolve) => { ended = resolve; });
|
|
useMailTransferStore.getState().startJob({
|
|
kind: "export",
|
|
controller,
|
|
scope: auth.activeAccountId ?? "default",
|
|
finished,
|
|
progress: { phase: "running", exported: 0, failed: 0, failures: [], total: 0, fraction: 0 },
|
|
});
|
|
void (async () => {
|
|
try {
|
|
await run();
|
|
} finally {
|
|
ended();
|
|
}
|
|
})();
|
|
async function run() {
|
|
let folders: ExportFolder[];
|
|
try {
|
|
folders = input.mailboxId
|
|
? [{ mailboxId: input.mailboxId, path: [] }]
|
|
: folderTree(await client.getMailboxes(input.accountId));
|
|
} catch (error) {
|
|
await input.sink.abort().catch(() => {});
|
|
useMailTransferStore.getState().updateProgress({
|
|
phase: "failed", exported: 0, failed: 0, failures: [], total: 0, fraction: 0,
|
|
error: error instanceof Error ? error.message : String(error),
|
|
});
|
|
return;
|
|
}
|
|
const result = await runExport({
|
|
client,
|
|
accountId: input.accountId,
|
|
folders,
|
|
format: input.format,
|
|
sink: input.sink,
|
|
signal: controller.signal,
|
|
onProgress: (progress) => useMailTransferStore.getState().updateProgress(progress),
|
|
});
|
|
useMailTransferStore.getState().updateProgress(result);
|
|
}
|
|
}
|