fix(indexer): resolve Maildir keys by scanning filesystem directly
perso/mcp-maildir/pipeline/head This commit looks good
perso/mcp-maildir/pipeline/head This commit looks good
This commit is contained in:
+14
-9
@@ -214,19 +214,24 @@ def get_recent_keys(mbox: mailbox.Maildir, days: int) -> set:
|
|||||||
recent = set()
|
recent = set()
|
||||||
maildir_root = mbox._path # type: ignore[attr-defined]
|
maildir_root = mbox._path # type: ignore[attr-defined]
|
||||||
|
|
||||||
for key in mbox.keys():
|
for subdir in ("cur", "new"):
|
||||||
# Maildir keys are stored under cur/ or new/ — try both
|
subdir_path = os.path.join(maildir_root, subdir)
|
||||||
for subdir in ("cur", "new"):
|
try:
|
||||||
file_path = os.path.join(maildir_root, subdir, key)
|
filenames = os.listdir(subdir_path)
|
||||||
|
except OSError:
|
||||||
|
continue
|
||||||
|
|
||||||
|
for filename in filenames:
|
||||||
|
file_path = os.path.join(subdir_path, filename)
|
||||||
try:
|
try:
|
||||||
# Single stat() call instead of isfile() + getmtime()
|
|
||||||
if os.stat(file_path).st_mtime >= cutoff_ts:
|
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)
|
recent.add(key)
|
||||||
except FileNotFoundError:
|
|
||||||
continue # try next subdir
|
|
||||||
except OSError:
|
except OSError:
|
||||||
pass
|
continue
|
||||||
break # found the file (stat succeeded or non-ENOENT error), stop trying subdirs
|
|
||||||
|
|
||||||
return recent
|
return recent
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user