fix(mail): address PR #935 round-2 review

- server/mail.py: guard nc_mail_get_message against an empty OCS payload so
  MailMessage(**{}) can't raise an uncaught ValidationError (returns a clean
  'not found' instead).
- server/mail.py: cap inlined attachment content at MAX_ATTACHMENT_CONTENT_BYTES
  (5 MiB), replacing oversized bodies with a sentinel so a large attachment
  can't blow up the MCP response.
- client/mail.py: harden the OCS meta statuscode parse against a non-numeric
  value (treat as success) instead of letting int() raise an uncaught
  ValueError.
- scanner.py: log the newest-N cap hit once per (user, mailbox) at info level
  (discoverable without flooding multi-tenant logs on every scan tick).
- tests: add incremental-sync scanner cases (new message queued, reappeared
  message clears grace, deletion after grace expiry).

Deferred (tracked, card #376): include doc_type in the _potentially_deleted
grace-period key — a pre-existing cross-cutting collision the reviewer flagged
as a follow-up, not a blocker.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
Chris Coutinho
2026-06-20 12:45:47 +02:00
co-authored by Claude Opus 4.8
parent 62ee3e9f32
commit c62ccf3d0d
4 changed files with 150 additions and 5 deletions
+14 -3
View File
@@ -1362,6 +1362,12 @@ async def scan_news_items(
# wanted, at the cost of more embedding work.
MAIL_SCAN_MAX_PER_MAILBOX = 100
# Per-process record of (user_id, mailbox_id) for which the newest-N cap has
# already been logged, so the "older mail not indexed" notice is emitted once at
# info level (discoverable) rather than on every scan tick (which would flood
# multi-tenant logs).
_mail_cap_logged: set[tuple[str, int]] = set()
async def scan_mail_messages(
user_id: str,
@@ -1460,10 +1466,15 @@ async def scan_mail_messages(
)
continue
if len(messages) >= MAIL_SCAN_MAX_PER_MAILBOX:
logger.debug(
cap_key = (user_id, mailbox_id)
if len(messages) >= MAIL_SCAN_MAX_PER_MAILBOX and cap_key not in (
_mail_cap_logged
):
_mail_cap_logged.add(cap_key)
logger.info(
"[SCAN-%s] Mailbox %s hit the newest-%s cap; older messages "
"are not indexed",
"are not indexed (set MAIL_SCAN_MAX_PER_MAILBOX higher for "
"deeper history)",
scan_id,
mailbox_id,
MAIL_SCAN_MAX_PER_MAILBOX,