Skip to content

fix(email): harden adapter against malformed IMAP responses (#2794 salvage) - #56956

Merged
teknium1 merged 1 commit into
mainfrom
salvage/2794-email-imap-guards
Jul 2, 2026
Merged

teknium1 merged 1 commit into
mainfrom
salvage/2794-email-imap-guards

Conversation

@teknium1

@teknium1 teknium1 commented Jul 2, 2026

Copy link
Copy Markdown
Collaborator

Summary

One malformed IMAP fetch response can no longer silently lose messages — the email adapter marks UIDs seen before fetching, so an unguarded msg_data[0][1] crash mid-batch permanently skipped every remaining message in that batch.

Salvage of #2794 by @CharmingGroot, ported to the relocated plugins/platforms/email/adapter.py (PR targeted the old gateway/platforms/email.py) and widened: the Message-ID split('@')[1] fix now covers all 3 send paths via a shared helper (the PR fixed 2 of 3), plus a non-bytes payload guard.

Changes

  • plugins/platforms/email/adapter.py: try/except around msg_data[0][1] (IndexError/TypeError → warn + skip), isinstance(bytes) payload check, _message_id_domain() helper with localhost fallback replacing 3 crash-prone split('@')[1] sites
  • tests/gateway/test_email_robustness.py: 9 tests incl. the batch-continues-after-malformed-response contract
  • scripts/release.py: AUTHOR_MAP entry for @CharmingGroot

Validation

Result
tests/gateway/test_email_robustness.py + test_email.py 97/97 pass
batch behavior malformed UID skipped, subsequent messages still fetched

Infographic

infographic

Nous Research

@alt-glitch alt-glitch added type/bug Something isn't working P3 Low — cosmetic, nice to have comp/plugins Plugin system and bundled plugins platform/email Email (IMAP/SMTP) adapter sweeper:risk-message-delivery Sweeper risk: may drop, duplicate, misroute, or suppress messages labels Jul 2, 2026
Salvage of #2794 by @CharmingGroot, ported to the relocated
plugins/platforms/email/adapter.py:

- Guard raw_email = msg_data[0][1] against IndexError/TypeError and
  non-bytes payloads. UIDs are added to _seen_uids before fetch, so an
  exception mid-batch permanently skipped every remaining message in
  the batch — now the bad message is logged and skipped instead.
- Message-ID domain generation falls back to 'localhost' when
  EMAIL_ADDRESS lacks '@' (now via a shared _message_id_domain() helper
  covering all 3 send paths; the PR fixed 2 of 3).
@teknium1
teknium1 force-pushed the salvage/2794-email-imap-guards branch from 2880187 to 2825728 Compare July 2, 2026 10:03
@teknium1
teknium1 merged commit 88bd1c0 into main Jul 2, 2026
31 checks passed
@teknium1
teknium1 deleted the salvage/2794-email-imap-guards branch July 2, 2026 10:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/plugins Plugin system and bundled plugins P3 Low — cosmetic, nice to have platform/email Email (IMAP/SMTP) adapter sweeper:risk-message-delivery Sweeper risk: may drop, duplicate, misroute, or suppress messages type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants