Skip to content

Add exact UID-set fetch API - #121

Merged
qnikst merged 1 commit into
qnikst:masterfrom
mpscholten:codex/fetch-exact-uid-set
Aug 8, 2026
Merged

qnikst merged 1 commit into
qnikst:masterfrom
mpscholten:codex/fetch-exact-uid-set

Conversation

@mpscholten

Copy link
Copy Markdown
Contributor

Summary

  • add fetchByByteStringSet for fetching arbitrary data items from an exact list of UIDs
  • encode sparse UIDs as an IMAP sequence-set such as 101,205,999, rather than widening them to a range
  • return immediately for an empty UID list without sending an invalid UID FETCH command
  • preserve the existing raw ByteString values and response-UID mapping used by fetchByByteStringR

Why

IMAP searches commonly return sparse UIDs. The existing fetchByByteStringR API accepts only a contiguous range, so using the first and last search result can fetch many unrelated messages between them. Calling the single-UID API in a loop avoids over-fetching but adds one network round trip per message.

This helper allows callers to batch metadata reads such as BODYSTRUCTURE for exactly the search results they need.

Validation

  • Nix doCheck build with GHC 9.10.3
  • imap-parsers: 50 cases, 0 errors, 0 failures
  • Haddock generation
  • regression coverage for sparse and empty UID sets

@mpscholten
mpscholten marked this pull request as ready for review August 8, 2026 15:35

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 271d6e236d

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

fetchByByteStringSet _ [] _ = return []
fetchByByteStringSet conn uids command =
fetchCommandBS conn
("UID FETCH "++intercalate "," (map show uids)++" "++command) proc

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Split large UID sets into bounded FETCH commands

When this helper receives a large SEARCH result, it serializes every UID into one unbounded IMAP command line. IMAP servers commonly impose command-line length limits, so sufficiently large but valid UID sets will be rejected with BAD instead of being fetched—particularly in the bulk search-result use case this API targets. Partition the UIDs into bounded sequence-set commands and concatenate their responses, or expose and document an explicit size limit.

Useful? React with 👍 / 👎.

@mpscholten

Copy link
Copy Markdown
Contributor Author

@qnikst this one is also good to go I think :)

@qnikst

qnikst commented Aug 8, 2026

Copy link
Copy Markdown
Owner

I have approved, but I find codex comment useful. If there is a need and it’s not hard it would be nice to implement that, otherwise it opens a possibility for DDoS attack or unrecoverable failure, if server rejects messages that are too big

but it’s ok to have that in a separate pr

@qnikst

qnikst commented Aug 8, 2026

Copy link
Copy Markdown
Owner

And I will merge this one, I don’t think we will break the internet by adding clear et solution later ;)

@qnikst
qnikst merged commit a0398fb into qnikst:master Aug 8, 2026
23 checks passed
@qnikst

qnikst commented Aug 8, 2026

Copy link
Copy Markdown
Owner

Merged, thanks for your work!

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.

2 participants