Skip to content

Commit b4a3899

Browse files
author
Mathias Millet
committed
feat: improve folder move-emails performance
1 parent 021890b commit b4a3899

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

mmuxer/cli/folder.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from pathlib import Path
22

3+
import more_itertools
34
import typer
45
from rich import print
56
from rich.pretty import Node, pretty_repr
@@ -104,13 +105,13 @@ def move_emails(source_folder: str, dest_folder: str):
104105
total_emails = len(box.numbers())
105106
with progress_when_tty() as progress:
106107
task = progress.add_task("[bold blue]Preparing to move emails...", total=total_emails)
107-
for msg in box.fetch(bulk=100, mark_seen=False):
108-
box.move(msg.uid, dest_folder)
109-
nb_moved += 1
108+
for chunk in more_itertools.chunked(box.uids(), 50):
109+
box.move(chunk, dest_folder)
110+
nb_moved += len(chunk)
110111
progress.update(
111112
task,
112113
description=f"[bold blue]Moved {nb_moved}/{total_emails} emails...",
113-
advance=1,
114+
advance=len(chunk),
114115
)
115116

116117
print(f"[bold green]Moved {nb_moved}/{total_emails} emails.")

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ dependencies = [
1818
"watchfiles >= 0.18",
1919
"boolean.py >= 4.0",
2020
"sievelib>=1.4.2",
21+
"more-itertools>=10.8.0",
2122
]
2223

2324
classifiers = [

0 commit comments

Comments
 (0)