Skip to content

Preserve raw bytes in IMAP APPEND#109

Open
mpscholten wants to merge 1 commit into
qnikst:masterfrom
mpscholten:upstream/imap-append-raw-bytes
Open

Preserve raw bytes in IMAP APPEND#109
mpscholten wants to merge 1 commit into
qnikst:masterfrom
mpscholten:upstream/imap-append-raw-bytes

Conversation

@mpscholten

Copy link
Copy Markdown
Contributor

Fixes #102.

appendFull currently splits the rendered message with BS.lines, computes a new literal size from those split lines, and sends each line with bsPutCrLf. That mutates already-rendered RFC 5322/MIME bytes: CRLF input becomes CRCRLF on the wire and the literal size no longer matches the original message size.

This PR keeps the public API unchanged and sends the APPEND literal exactly as supplied:

  • literal size is BS.length mailData
  • mailData is written once with bsPut
  • the final IMAP literal terminator CRLF is still sent afterwards

Regression coverage:

  • IMAP.append conn "INBOX" "Subject: x\r\n\r\nBody\r\n" sends the exact raw message bytes after the APPEND command.

Before the fix, the new regression failed with {23} and doubled carriage returns. After the fix it passes with {20} and unchanged message bytes.

Validation:

  • nix shell nixpkgs#cabal-install nixpkgs#ghc --command cabal test imap-parsers --test-show-details=direct
  • nix shell nixpkgs#cabal-install nixpkgs#ghc --command cabal build all
  • nix shell nixpkgs#cabal-install nixpkgs#ghc --command cabal check (only the existing CHANGELOG doc-place warning remains)
  • git diff --check

Note: this includes the same imap-parsers test-target setup and https:// repository metadata fix as the other small upstream PRs because the branch is independently based on upstream master. It can be rebased to drop that overlap after the first test-target PR merges.

@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: 62fdff5430

ℹ️ 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".

Comment thread test/IMAPParsersTest.hs Outdated
steps' <- readIORef input
case steps' of
ReadLine line : rest -> writeIORef input rest >> return line
ReadBytes _ : _ -> assertFailure "expected test stream line, got bytes"

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Return a ByteString on scripted read failures

When the new imap-parsers test target is built, these failure branches are type-checked as part of popLine :: IO ByteString/popBytes :: IO ByteString, but assertFailure from HUnit returns Assertion (IO ()). That makes the newly added test suite fail to compile before any tests can run; use a polymorphic throwing helper or follow the failure with an unreachable ByteString result.

Useful? React with 👍 / 👎.

@mpscholten mpscholten force-pushed the upstream/imap-append-raw-bytes branch from afb5f56 to 6c71a13 Compare June 5, 2026 14:43
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.

appendFull is broken with MIME messages

1 participant