Skip to content

imap-proto: handle unknown FETCH attributes (RFC 8474 EMAILID/THREADID)#193

Open
x-hannibal wants to merge 3 commits intodjc:mainfrom
x-hannibal:feat/rfc8474-unknown-fetch-attr
Open

imap-proto: handle unknown FETCH attributes (RFC 8474 EMAILID/THREADID)#193
x-hannibal wants to merge 3 commits intodjc:mainfrom
x-hannibal:feat/rfc8474-unknown-fetch-attr

Conversation

@x-hannibal
Copy link
Copy Markdown

Problem

RFC-compliant IMAP servers can include extension attributes in FETCH responses that imap-proto does not yet explicitly support. Known cases:

  • RFC 8474 §5 OBJECTID: EMAILID, THREADID — sent by Apache James 3.9, Dovecot (with OBJECTID plugin), and others
  • RFC 8514 §2: SAVEDATE
  • Any future extension attribute

When one of these attributes appears in a FETCH list, msg_att's alt() exhausts all known parsers. Because nom 7's alt returns the last alternative's error (not the deepest), the caller sees a TakeWhile1 error from response_tagged's imap_tag — which tries to match * as a tag character and fails. The entire response is dropped.

Fix

Add msg_att_unknown as the last arm of msg_att's alt(). It consumes:

  • a single-level parenthesised value (...) — covers EMAILID (Mxxx), THREADID (Txxx)
  • an nstring — covers THREADID NIL, SAVEDATE "date-time"
  • a bare atom or number — fallback for any remaining scalar value

and returns AttributeValue::Unknown so the rest of the FETCH attribute list can be parsed without error.

AttributeValue::Unknown is added to the enum as a documented variant. The name and raw value are consumed and discarded; callers that need the actual value for a specific extension should open a dedicated tracking issue or PR to add first-class support.

Tests

Four new tests in parser/tests.rs:

Test Input
test_fetch_rfc8474_emailid EMAILID (Mxxx) alongside UID + BODY[]<0>
test_fetch_rfc8474_threadid THREADID (Txxx) alongside UID + BODY[]<0>
test_fetch_rfc8474_threadid_nil THREADID NIL (RFC 8474 §5.2 allows NIL)
test_fetch_rfc8474_emailid_and_threadid both in the same FETCH response

All 86 existing tests continue to pass.

Notes

  • msg_att_unknown is intentionally the last alternative so it never shadows an explicitly supported attribute.
  • Single-level parentheses only — deeply nested values (which do not appear in any known extension attribute grammar) are not handled. A dedicated parser can be added per RFC if needed.

RFC-compliant servers (Apache James 3.9, Dovecot with OBJECTID plugin,
Stalwart) can include extension attributes in FETCH responses that this
crate does not yet explicitly support:

  * RFC 8474 §5 OBJECTID: EMAILID, THREADID
  * RFC 8514 §2 SAVEDATE (and any future extensions)

When any such attribute appears in a FETCH list, msg_att's alt() exhausts
all known parsers and nom returns a TakeWhile1 error from the last
alternative (response_tagged), causing the entire response to be dropped.

Fix: add msg_att_unknown as the last arm of msg_att's alt(). It consumes:
  - a single-level parenthesised value  (EMAILID (Mxxx), THREADID (Txxx))
  - an nstring                          (THREADID NIL, SAVEDATE "date-time")
  - a bare atom / number                (fallback for scalar values)

and returns AttributeValue::Unknown so the rest of the FETCH attribute
list can be parsed without error. The name and raw value are discarded;
callers that need the actual value should open a dedicated tracking issue.

Four new tests cover: EMAILID, THREADID, THREADID NIL, EMAILID+THREADID
combined in the same FETCH response. All 86 existing tests still pass.
@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 28, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 76.71%. Comparing base (6593414) to head (1c548e6).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #193      +/-   ##
==========================================
+ Coverage   76.35%   76.71%   +0.36%     
==========================================
  Files          21       21              
  Lines        2829     2847      +18     
==========================================
+ Hits         2160     2184      +24     
+ Misses        669      663       -6     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant