Skip to content

Fix FETCH response bugs: literal ordering and comma-separated sequence sets - #299

Open
maneesha-xyz wants to merge 4 commits into
mainfrom
298-bug-fetch-response-merges-literals-for-multi-item-requests-breaks-strict-imap-clients-nextcloudhorde
Open

Fix FETCH response bugs: literal ordering and comma-separated sequence sets#299
maneesha-xyz wants to merge 4 commits into
mainfrom
298-bug-fetch-response-merges-literals-for-multi-item-requests-breaks-strict-imap-clients-nextcloudhorde

Conversation

@maneesha-xyz

Copy link
Copy Markdown
Collaborator

Summary

  • Each FETCH literal now follows its own item name instead of being batched after all item names — was breaking strict IMAP clients (Nextcloud, Horde) on multi-item requests. Fixes [BUG] FETCH response merges literals for multi-item requests, breaks strict IMAP clients (Nextcloud/Horde) #298.
  • Also fixes a latent data-loss bug where HEADER.FIELDS used = instead of += on the shared literal buffer, silently dropping an earlier item's literal.
  • FETCH now accepts comma-separated sequence sets (1,3,5, 1:3,7,9:*), previously rejected with BAD Invalid sequence number — was blocking folder loads in mail clients that batch-fetch this way. Reuses the already-tested utils.ParseSequenceSetWithDB instead of duplicating parsing logic.

Test plan

  • go test ./... green (excluding pre-existing, unrelated Docker-dependent e2e failures)
  • New regression tests added test-first, confirmed failing before each fix, passing after
  • Verified against live production traffic: correct interleaved literal output and successful FETCH 1,3,5 via direct raw-socket test

UID FETCH with multiple literal-bearing items (e.g. BODY.PEEK[1]
BODY.PEEK[1.MIME]) currently returns all item names first, then all
literals appended at the end, instead of each literal immediately
following its own item name. Confirms issue #298 mechanically before
the fix.
Literals were batched after all item names instead of following their
own item, breaking strict IMAP clients on multi-item FETCH.

Fixes #298
FETCH 1,3,5 currently returns BAD Invalid sequence number since the
parser only understands a single number or an a:b range.
HandleFetch had its own inline sequence-set parser understanding only
a single number or an a:b range, so any comma-separated set (1,3,5) or
combination (1:3,7,9:*) fell through to strconv.Atoi and errored.
Reuses utils.ParseSequenceSetWithDB, already used by STORE/COPY and
already tested against comma syntax, instead of duplicating the logic.
@maneesha-xyz
maneesha-xyz force-pushed the 298-bug-fetch-response-merges-literals-for-multi-item-requests-breaks-strict-imap-clients-nextcloudhorde branch from 27847d9 to 8c0bd75 Compare August 24, 2026 07:14
@maneesha-xyz maneesha-xyz self-assigned this Aug 24, 2026
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.

[BUG] FETCH response merges literals for multi-item requests, breaks strict IMAP clients (Nextcloud/Horde)

1 participant