refactor(email): fold #92979 review findings into the IMAP ID gate

Two shape fixes from the review of #92979, no behavior change:

- Read imap.capabilities directly instead of the getattr(...) or ()
  fallback — a real imaplib.IMAP4 always sets the attribute in
  _connect() (raising if the server sends no CAPABILITY), so the
  default branch only existed for a MagicMock(spec=["xatom"]) that no
  production path produces. Drop the test that pinned it.
- Trim tests to the invariant bar: the four mock tests duplicated what
  test_email_imap_id_protocol.py proves on the wire (real imaplib, real
  socket, command order), and the phase parametrize (startup vs poll)
  exercised the same single _send_imap_id call site twice. Keep the
  three id_mode cases through the poll path.

42 tests pass; mutation check: guard removed -> the absent-ID case
fails with the #39856 SELECT error, restored -> green.
This commit is contained in:
kshitijk4poor
2026-09-06 21:29:58 +05:30
committed by kshitij
parent 8fd3e08ab9
commit 66f1668850
3 changed files with 4 additions and 67 deletions

View File

@@ -148,8 +148,7 @@ def _send_imap_id(imap: "imaplib.IMAP4") -> None:
connection, which imaplib cannot surface here — the failure appears one command later
as a misleading SELECT error and the adapter retries forever (Purelymail, #39856).
``imap.capabilities`` is populated by imaplib at connect, so the check is free."""
caps = getattr(imap, "capabilities", ()) or ()
if "ID" not in caps:
if "ID" not in imap.capabilities:
logger.debug(
"[Email] Server does not advertise IMAP ID capability; skipping ID"
)