Add sorter progress counters

The prompts used to arrive at this change since the previous commit

Add a counter to the verplaats_bestaand file

Any special observations that may be relevant for version management for this version. Be brief.

Audit mode now reports folder position and scanned message progress every 250 messages without running live mailbox scripts from Codex.
This commit is contained in:
2026-07-04 16:42:18 +02:00
parent e062db2fb6
commit d82f9792f0
2 changed files with 16 additions and 5 deletions
+1
View File
@@ -78,6 +78,7 @@ Scripts using shared IMAP folder handling:
- Default mode is dry-run; real moves require `--uitvoeren` and an interactive `JA` confirmation. - Default mode is dry-run; real moves require `--uitvoeren` and an interactive `JA` confirmation.
- Account selection is explicit with `--account <naam>`; use `--account backup` for the disposable backup mailbox. The script prints both the config account name and mailbox address before connecting. - Account selection is explicit with `--account <naam>`; use `--account backup` for the disposable backup mailbox. The script prints both the config account name and mailbox address before connecting.
- `--audit` is available only in dry-run mode. It suppresses per-message dry-run lines and prints planned move counts grouped by source folder and destination folder for step 2 and step 3. - `--audit` is available only in dry-run mode. It suppresses per-message dry-run lines and prints planned move counts grouped by source folder and destination folder for step 2 and step 3.
- Long scans show progress counters: source folders are printed as `[current/total]`, and audit mode prints `Gescand: processed/total` every 250 messages and at folder completion.
- IMAP `LIST`, `SELECT`, `UID SEARCH`, and `UID FETCH` aborts are logged and retried once after reconnecting. If reconnect also fails, the script records an `ABORT`/`ERROR` in `verplaats_log.json` instead of printing a Python traceback. - IMAP `LIST`, `SELECT`, `UID SEARCH`, and `UID FETCH` aborts are logged and retried once after reconnecting. If reconnect also fails, the script records an `ABORT`/`ERROR` in `verplaats_log.json` instead of printing a Python traceback.
- `MAP_RENAMES` is intentionally empty. - `MAP_RENAMES` is intentionally empty.
- Source folders are selected by shared `list_folders()` plus `mail_routes.is_source_folder()`. - Source folders are selected by shared `list_folders()` plus `mail_routes.is_source_folder()`.
+15 -5
View File
@@ -36,6 +36,7 @@ LOG_FILE = Path(__file__).parent / "verplaats_log.json"
DRY_RUN = "--uitvoeren" not in sys.argv DRY_RUN = "--uitvoeren" not in sys.argv
AUDIT = "--audit" in sys.argv AUDIT = "--audit" in sys.argv
PROGRESS_INTERVAL = 250
# Mappen die in één keer worden hernoemd/verplaatst (oud → nieuw). # Mappen die in één keer worden hernoemd/verplaatst (oud → nieuw).
@@ -126,6 +127,11 @@ def print_audit(title: str, by_source: Counter, by_destination: Counter):
print(f" {count:5d} {folder}") print(f" {count:5d} {folder}")
def print_progress(folder: str, processed: int, total: int):
if processed == total or processed % PROGRESS_INTERVAL == 0:
print(f" Gescand: {processed}/{total} | {folder}")
def safe_select(session: ImapSession, log: dict, stap: str, folder: str, readonly: bool): def safe_select(session: ImapSession, log: dict, stap: str, folder: str, readonly: bool):
for attempt in range(2): for attempt in range(2):
try: try:
@@ -302,7 +308,7 @@ def stap2_bronmappen_routing(session: ImapSession, log: dict, dry: bool):
totaal_mislukt = 0 totaal_mislukt = 0
al_verwerkt = set(log.get("stap2_verwerkt", [])) al_verwerkt = set(log.get("stap2_verwerkt", []))
for bron in bron_mappen: for folder_index, bron in enumerate(bron_mappen, start=1):
status, data = safe_select(session, log, "stap2", bron, readonly=dry) status, data = safe_select(session, log, "stap2", bron, readonly=dry)
mail = session.mail mail = session.mail
if status != "OK": if status != "OK":
@@ -312,7 +318,7 @@ def stap2_bronmappen_routing(session: ImapSession, log: dict, dry: bool):
n = int(data[0]) n = int(data[0])
if n == 0: if n == 0:
continue continue
print(f" {bron}: {n} berichten") print(f" [{folder_index}/{len(bron_mappen)}] {bron}: {n} berichten")
status, data = safe_uid( status, data = safe_uid(
session, log, "stap2", bron, "", "SEARCH", "ALL", readonly=dry session, log, "stap2", bron, "", "SEARCH", "ALL", readonly=dry
@@ -331,6 +337,8 @@ def stap2_bronmappen_routing(session: ImapSession, log: dict, dry: bool):
for uid in ids: for uid in ids:
verwerkt += 1 verwerkt += 1
if AUDIT:
print_progress(bron, verwerkt, len(ids))
uid_str = uid.decode() uid_str = uid.decode()
log_key = f"{bron}:{uid_str}" log_key = f"{bron}:{uid_str}"
if log_key in al_verwerkt: if log_key in al_verwerkt:
@@ -440,7 +448,7 @@ def stap3_facturen(session: ImapSession, log: dict, dry: bool):
audit_by_source = Counter() audit_by_source = Counter()
audit_by_destination = Counter() audit_by_destination = Counter()
for bron in bron_mappen: for folder_index, bron in enumerate(bron_mappen, start=1):
status, data = safe_select(session, log, "stap3", bron, readonly=dry) status, data = safe_select(session, log, "stap3", bron, readonly=dry)
mail = session.mail mail = session.mail
if status != "OK": if status != "OK":
@@ -448,10 +456,10 @@ def stap3_facturen(session: ImapSession, log: dict, dry: bool):
n = int(data[0]) n = int(data[0])
if n == 0: if n == 0:
print(f" {bron}: leeg") print(f" [{folder_index}/{len(bron_mappen)}] {bron}: leeg")
continue continue
print(f" {bron}: {n} berichten") print(f" [{folder_index}/{len(bron_mappen)}] {bron}: {n} berichten")
status, data = safe_uid( status, data = safe_uid(
session, log, "stap3", bron, "", "SEARCH", "ALL", readonly=dry session, log, "stap3", bron, "", "SEARCH", "ALL", readonly=dry
) )
@@ -464,6 +472,8 @@ def stap3_facturen(session: ImapSession, log: dict, dry: bool):
mislukt = 0 mislukt = 0
for index, uid in enumerate(ids, start=1): for index, uid in enumerate(ids, start=1):
if AUDIT:
print_progress(bron, index, len(ids))
status, data = safe_uid( status, data = safe_uid(
session, session,
log, log,