Files
mcp-home/tests/test_mail_newdir.py

66 lines
2.0 KiB
Python

#!/usr/bin/env python3
"""Regression (2026-09-26): ungelesene Mails im Maildir `new/` muessen indexiert
werden. mbsync legt Gmail-Mails ohne \\Seen in <folder>/new/ ab; der Index scannte
frueher nur cur/ und jarvis sah diese Mails nicht.
Lauf: /opt/mcp-servers/venv/bin/python -m pytest test_mail_newdir.py -q
"""
import os
import sys
import pytest
BASE = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
sys.path.insert(0, BASE)
sys.path.insert(0, os.path.join(BASE, "mail"))
from mail import mailindex # noqa: E402
pytestmark = pytest.mark.edge
MSG = (
"From: sender@example.com\r\n"
"To: rcpt@example.com\r\n"
"Subject: Newdir Regression {tag}\r\n"
"Date: Sat, 26 Sep 2026 13:58:32 +0200\r\n"
"Content-Type: text/plain; charset=utf-8\r\n"
"\r\n"
"unique-body-token-{tag}\r\n"
)
def _write_mail(path):
with open(path, "w", encoding="utf-8") as fh:
fh.write(MSG.format(tag=os.path.basename(path).split(":")[0]))
@pytest.fixture()
def newdir_index(tmp_path):
user = "newdir_test"
root = tmp_path / "maildir"
for sub, tag in (("cur", "curtoken"), ("new", "newtoken")):
d = root / "acct" / "INBOX" / sub
d.mkdir(parents=True)
_write_mail(str(d / f"1700000000.{tag}.polo,S:2,S"))
mailindex.update_user(user, str(root), log=lambda *a: None)
with open(mailindex._ready_path(user), "w") as fh:
fh.write("test")
yield user
for p in (mailindex.index_db_path(user), mailindex._ready_path(user)):
try:
os.remove(p)
except OSError:
pass
def test_new_dir_is_indexed(newdir_index):
hits = mailindex.search(newdir_index, "newtoken", limit=5)
assert hits is not None, "Index nicht nutzbar"
assert hits, "Mail aus new/ wurde nicht indexiert"
assert hits[0]["folder"] == "INBOX"
def test_cur_dir_still_indexed(newdir_index):
hits = mailindex.search(newdir_index, "curtoken", limit=5)
assert hits, "Mail aus cur/ wurde nicht indexiert"