Add sorter progress counters

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

User asked to add a counter to verplaats_bestaand.

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

Dry runs now show planned move counters, and execution summaries distinguish planned, moved, no-match, skipped, and failed messages. No mailbox-affecting scripts were run.
This commit is contained in:
2026-07-04 16:28:25 +02:00
parent 701be98d47
commit 33005a7cde
2 changed files with 54 additions and 6 deletions
+3
View File
@@ -76,6 +76,9 @@ Scripts using shared IMAP folder handling:
- `MAP_RENAMES` is intentionally empty.
- Source folders are selected by shared `list_folders()` plus `mail_routes.is_source_folder()`.
- Step 2 routes all eligible source folders, not just `INBOX`.
- Step 2 now reports counters per folder and in total: planned moves, actual moves when executing, no-match messages, skipped messages, and fetch/move failures.
- Dry runs now report `Gepland` counters instead of misleadingly showing zero moved.
- Step 3 invoice-quarter sorting also reports planned/moved/failure counters.
- Move success requires both `UID COPY` and `UID STORE +FLAGS \Deleted` to return `OK`.
- Step 3 no longer treats `INBOX.Facturen - verwerkt` as a source.
- IMAP mailbox names are consistently quoted and encoded through `imap_utils.quote_mailbox()`.
+51 -6
View File
@@ -131,7 +131,10 @@ def stap2_bronmappen_routing(mail, log: dict, dry: bool):
print(f" {len(bron_mappen)} bronmappen")
totaal_verplaatst = 0
totaal_gepland = 0
totaal_geen_match = 0
totaal_overgeslagen = 0
totaal_mislukt = 0
al_verwerkt = set(log.get("stap2_verwerkt", []))
for bron in bron_mappen:
@@ -151,16 +154,23 @@ def stap2_bronmappen_routing(mail, log: dict, dry: bool):
ids = [uid for uid in data[0].split() if uid]
verplaatst = 0
gepland = 0
geen_match = 0
overgeslagen = 0
mislukt = 0
verwerkt = 0
for uid in ids:
verwerkt += 1
uid_str = uid.decode()
log_key = f"{bron}:{uid_str}"
if log_key in al_verwerkt:
overgeslagen += 1
continue
status, data = mail.uid("FETCH", uid, "(BODY.PEEK[HEADER.FIELDS (FROM SUBJECT DATE)])")
if status != "OK" or not data or not data[0]:
mislukt += 1
continue
msg = email.message_from_bytes(data[0][1])
@@ -179,10 +189,12 @@ def stap2_bronmappen_routing(mail, log: dict, dry: bool):
continue
if bron == doel:
overgeslagen += 1
continue
gepland += 1
if dry:
print(f" [DRY] {bron}{doel} | {subject[:60]}")
print(f" [DRY {verwerkt}/{len(ids)}] {bron}{doel} | {subject[:60]}")
else:
ok = move_message(mail, uid, bron, doel, dry=False)
if ok:
@@ -191,16 +203,41 @@ def stap2_bronmappen_routing(mail, log: dict, dry: bool):
if verplaatst % 50 == 0:
mail.expunge()
_save_log(log)
else:
mislukt += 1
if not dry:
mail.expunge()
_save_log(log)
totaal_verplaatst += verplaatst
totaal_gepland += gepland
totaal_geen_match += geen_match
print(f" Verplaatst: {verplaatst} | Geen match: {geen_match}")
totaal_overgeslagen += overgeslagen
totaal_mislukt += mislukt
if dry:
print(
f" Gepland: {gepland} | Geen match: {geen_match}"
f" | Overgeslagen: {overgeslagen} | Fouten: {mislukt}"
)
else:
print(
f" Gepland: {gepland} | Verplaatst: {verplaatst}"
f" | Geen match: {geen_match} | Overgeslagen: {overgeslagen}"
f" | Fouten: {mislukt}"
)
print(f" Totaal verplaatst: {totaal_verplaatst} | Totaal geen match: {totaal_geen_match}")
if dry:
print(
f" Totaal gepland: {totaal_gepland} | Totaal geen match: {totaal_geen_match}"
f" | Totaal overgeslagen: {totaal_overgeslagen} | Totaal fouten: {totaal_mislukt}"
)
else:
print(
f" Totaal gepland: {totaal_gepland} | Totaal verplaatst: {totaal_verplaatst}"
f" | Totaal geen match: {totaal_geen_match} | Totaal overgeslagen: {totaal_overgeslagen}"
f" | Totaal fouten: {totaal_mislukt}"
)
# ── stap 3: facturen per kwartaal ────────────────────────────────────────────
@@ -228,27 +265,35 @@ def stap3_facturen(mail, log: dict, dry: bool):
continue
ids = [uid for uid in data[0].split() if uid]
verplaatst = 0
gepland = 0
mislukt = 0
for uid in ids:
for index, uid in enumerate(ids, start=1):
status, data = mail.uid("FETCH", uid, "(BODY.PEEK[HEADER.FIELDS (DATE SUBJECT)])")
if status != "OK" or not data or not data[0]:
mislukt += 1
continue
msg = email.message_from_bytes(data[0][1])
date_str = msg.get("Date", "")
doel = PREFIX + quarter_folder(date_str)
gepland += 1
if dry:
dt_kort = date_str[:16] if date_str else "?"
print(f" [DRY] {dt_kort}{doel}")
print(f" [DRY {index}/{len(ids)}] {dt_kort}{doel}")
else:
ok = move_message(mail, uid, bron, doel, dry=False)
if ok:
verplaatst += 1
else:
mislukt += 1
if not dry:
mail.expunge()
print(f" {verplaatst}/{n} verplaatst")
print(f" Gepland: {gepland} | Verplaatst: {verplaatst} | Fouten: {mislukt}")
else:
print(f" Gepland: {gepland} | Fouten: {mislukt}")
# ── log ──────────────────────────────────────────────────────────────────────