Case-insensitive IMAP response parsing (RFC 3501)#116
Draft
mpscholten wants to merge 2 commits into
Draft
Conversation
Adds UIDPLUS extension support so callers can recover the UIDs the server assigns on APPEND/COPY and target expunges by UID: - appendFullUID: like appendFull, returns the APPENDUID response code - copyUID / copyUIDs / copyUIDR: UID COPY returning the COPYUID code - uidExpunge / uidExpungeR: UID EXPUNGE over a UID set or range New types AppendUID and CopyUID, the UIDSet alias, and the APPENDUID/COPYUID/UIDNOTSTICKY status codes with their parsers. sendCommandWithResponse exposes the tagged ServerResponse so the response codes can be read. The existing appendFull/copyFull keep their old signatures by discarding the UID result. Covered by new parser cases in baseTest and a dedicated imapUIDPlusTest group exercising the API against scripted server responses.
RFC 3501 keywords, response codes, flag names and status attributes are case-insensitive, but the parser matched them with case-sensitive `string`, so any server replying with non-canonical casing (e.g. `ok`, `* search`, `[uidvalidity ...]`, `\seen`) caused a parse error. Adds `stringCI`/`charCI` and applies them throughout the response parser. Along the way the tagged/fatal response handling is factored into `pWithTaggedOrFatal`, `pDone` is split into `pRespCode`/`pRespText`/`pStatusCode`, and string parsing is unified (`pQuotedString`/`pLiteralString`/`pAString`/`pMailboxName`). This also: - surfaces an untagged `* BYE` as a fatal response instead of failing - accepts an empty `* SEARCH` reply (no matches) - accepts a `NIL` hierarchy separator in LIST/LSUB - stops `atomChar` from running past CR/LF Covered by a new caseInsensitiveTest group.
This was referenced Jun 13, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Stacked on #115 (UIDPLUS). This branch is based on the UIDPLUS branch, so until #115 merges the diff here also shows those commits — the change that belongs to this PR is the single commit "Make IMAP response parsing case-insensitive (RFC 3501)". Please review/merge #115 first; I'll rebase this onto
masterafterwards so the diff narrows to just the parser change.What
RFC 3501 keywords, response codes, flag names and status attributes are case-insensitive, but the response parser matched them with case-sensitive
string. A server replying with non-canonical casing —a001 ok,* search …,[uidvalidity …],\seen— caused a hard parseerror. Several real-world servers (Exchange/Office365 among them) don't use the exact canonical uppercase.This adds
stringCI/charCIand applies them throughout the parser.While restructuring, also fixed
pWithTaggedOrFatalpDoneintopRespCode/pRespText/pStatusCodepQuotedString/pLiteralString/pAString/pMailboxName* BYEas a fatal response (BAD) instead of failing to parse* SEARCHreply (zero matches)NILhierarchy separator inLIST/LSUBatomCharfrom running past CR/LFTests
New
caseInsensitiveTestgroup: lowercase tagged/bracketed status codes, lowercase flags, untagged BYE, empty SEARCH, lowercase SEARCH keyword, NIL LIST separator.cabal testpasses (GHC 9.8.4).🤖 Generated with Claude Code