diff --git a/src/indexer.py b/src/indexer.py index 1375a03..57efd81 100644 --- a/src/indexer.py +++ b/src/indexer.py @@ -214,19 +214,24 @@ def get_recent_keys(mbox: mailbox.Maildir, days: int) -> set: recent = set() maildir_root = mbox._path # type: ignore[attr-defined] - for key in mbox.keys(): - # Maildir keys are stored under cur/ or new/ — try both - for subdir in ("cur", "new"): - file_path = os.path.join(maildir_root, subdir, key) + for subdir in ("cur", "new"): + subdir_path = os.path.join(maildir_root, subdir) + try: + filenames = os.listdir(subdir_path) + except OSError: + continue + + for filename in filenames: + file_path = os.path.join(subdir_path, filename) try: - # Single stat() call instead of isfile() + getmtime() if os.stat(file_path).st_mtime >= cutoff_ts: + # Maildir keys are the filename, but the actual file on disk + # often has a suffix (like ":2,S"). mailbox.Maildir treats + # the part BEFORE the first colon as the key. + key = filename.split(":")[0] if ":" in filename else filename recent.add(key) - except FileNotFoundError: - continue # try next subdir except OSError: - pass - break # found the file (stat succeeded or non-ENOENT error), stop trying subdirs + continue return recent