mirror of
https://github.com/bulwarkmail/webmail.git
synced 2026-11-02 00:14:23 +00:00
fix: move the import progress bar message by message for mbox files
This commit is contained in:
@@ -129,6 +129,14 @@ describe('runImport', () => {
|
||||
expect(fake.imported[0].receivedAt).toBe('2020-05-05T10:00:00Z');
|
||||
});
|
||||
|
||||
it('moves the progress message by message through a small mbox', async () => {
|
||||
const fake = fakeClient();
|
||||
const fractions: number[] = [];
|
||||
await runImport(options(fake.client, [file(mbox(10))], { onProgress: (p) => { if (p.phase === 'running') fractions.push(p.fraction); } }));
|
||||
const between = new Set(fractions.filter((f) => f > 0 && f < 1).map((f) => f.toFixed(2)));
|
||||
expect(between.size).toBeGreaterThanOrEqual(5);
|
||||
});
|
||||
|
||||
it('puts several messages in one Email/import and keeps uploads within the server limit', async () => {
|
||||
const fake = fakeClient({ uploadConcurrency: 4 });
|
||||
await runImport(options(fake.client, [file(mbox(45))]));
|
||||
|
||||
@@ -180,11 +180,14 @@ async function* mboxFromChunks(
|
||||
options: SourceOptions,
|
||||
startIndex: number,
|
||||
onIndex: (next: number) => void,
|
||||
/** Called with each message's offset in the stream, for a progress that moves message by message. */
|
||||
onOffset?: (offset: number) => void,
|
||||
): ItemSource {
|
||||
const splitter = new MboxSplitter({ maxMessageBytes: options.maxMessageBytes });
|
||||
let index = startIndex;
|
||||
const emit = function* (messages: MboxMessage[]): Generator<ImportItem> {
|
||||
for (const m of messages) {
|
||||
onOffset?.(m.offset);
|
||||
const i = index++;
|
||||
yield i < options.skipBefore ? { kind: "skipped", index: i, reason: "resumed" } : mboxItem(m, i, folder);
|
||||
}
|
||||
@@ -206,7 +209,8 @@ async function* fileChunks(file: Blob, onProgress?: (fraction: number) => void):
|
||||
}
|
||||
|
||||
export async function* mboxSource(file: File, options: SourceOptions): ItemSource {
|
||||
yield* mboxFromChunks(fileChunks(file, options.onProgress), [], options, 0, () => {});
|
||||
// Reads run ahead in 1 MB pieces; the messages handed over say how far the import really is.
|
||||
yield* mboxFromChunks(fileChunks(file), [], options, 0, () => {}, (offset) => options.onProgress?.(offset / Math.max(1, file.size)));
|
||||
options.onProgress?.(1);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user