diff options
Diffstat (limited to '.ai/scripts/maildir-flag-manager.py')
| -rwxr-xr-x | .ai/scripts/maildir-flag-manager.py | 38 |
1 files changed, 22 insertions, 16 deletions
diff --git a/.ai/scripts/maildir-flag-manager.py b/.ai/scripts/maildir-flag-manager.py index 9c4a59c..97ed1d8 100755 --- a/.ai/scripts/maildir-flag-manager.py +++ b/.ai/scripts/maildir-flag-manager.py @@ -119,28 +119,34 @@ def process_maildir(maildir_path, flag, dry_run=False): print(f" Skipping {maildir_path} (not found)", file=sys.stderr) return 0, 0, 0 - changed = 0 - skipped = 0 - errors = 0 - + # Snapshot the file list before any rename. Adding S to a new/ file + # moves it to cur/ via rename_with_flag; without a snapshot, the + # moved file gets re-encountered during the cur/ scan and inflates + # the skipped count. + file_paths = [] for subdir in ('new', 'cur'): subdir_path = os.path.join(maildir_path, subdir) if not os.path.isdir(subdir_path): continue - for filename in os.listdir(subdir_path): file_path = os.path.join(subdir_path, filename) - if not os.path.isfile(file_path): - continue - - try: - if rename_with_flag(file_path, flag, dry_run): - changed += 1 - else: - skipped += 1 - except Exception as e: - print(f" Error on {filename}: {e}", file=sys.stderr) - errors += 1 + if os.path.isfile(file_path): + file_paths.append(file_path) + + changed = 0 + skipped = 0 + errors = 0 + + for file_path in file_paths: + try: + if rename_with_flag(file_path, flag, dry_run): + changed += 1 + else: + skipped += 1 + except Exception as e: + print(f" Error on {os.path.basename(file_path)}: {e}", + file=sys.stderr) + errors += 1 return changed, skipped, errors |
