Skip to content

fix: handle IMAP LITERAL+ ({NNN+}) syntax from Gmail#81

Merged
BrianLeishman merged 2 commits into
masterfrom
fix/issue-80-literal-plus
Mar 11, 2026
Merged

fix: handle IMAP LITERAL+ ({NNN+}) syntax from Gmail#81
BrianLeishman merged 2 commits into
masterfrom
fix/issue-80-literal-plus

Conversation

@BrianLeishman

Copy link
Copy Markdown
Owner

Summary

  • Adds support for IMAP LITERAL+ (RFC 7888) {NNN+}\r\n syntax across all three parsing layers: Exec wire reading, findFetchContentEnd boundary detection, and parseFetchTokens tokenization
  • Gmail advertises LITERAL+ and uses this syntax in FETCH responses, causing "mismatched parentheses" errors when email bodies contain parentheses
  • Updates the atom regex to match {NNN+}, strips + before size parsing in Exec, and handles + with } validation in the token parser

Closes #80

Test plan

  • 6 new tests in issue80_test.go covering all LITERAL+ scenarios
  • Exec wire assembly with {NNN+} bodies
  • Token parsing with {NNN+} literals containing parentheses
  • Full ParseFetchResponse end-to-end with LITERAL+ and nested parens in body
  • Multi-record LITERAL+ responses
  • Empty body {0+} edge case
  • Mixed standard {NNN} and LITERAL+ {NNN+} in same response
  • All existing tests pass, race detector clean

🤖 Generated with Claude Code

Gmail advertises LITERAL+ (RFC 7888) and uses {NNN+}\r\n in FETCH
responses. The parser only recognized standard {NNN}\r\n, causing
"mismatched parentheses" errors when email bodies contained parens.

Fixes all three affected code paths: Exec wire reading, response
boundary detection, and token parsing.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings March 11, 2026 13:32

Copilot AI 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.

Pull request overview

This PR fixes IMAP FETCH parsing against Gmail by adding support for RFC 7888 non-synchronizing literals ({NNN+}\r\n) across wire assembly, FETCH boundary detection, and tokenization—preventing “mismatched parentheses” errors when literal bodies contain parentheses.

Changes:

  • Extend literal marker detection to recognize {NNN+} in the shared atom regex.
  • Update Exec literal size parsing to strip a trailing + before Atoi.
  • Teach findFetchContentEnd and parseFetchTokens to accept {NNN+} and parse the size correctly.
  • Add a focused regression test suite for issue #80 covering LITERAL+ scenarios and edge cases.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
parse.go Adds {NNN+} support in token parsing and FETCH content boundary scanning, and broadens the literal marker regex.
exec.go Strips the LITERAL+ + suffix when parsing literal sizes during wire reads.
issue80_test.go Adds regression tests covering Exec-style literal assembly and end-to-end FETCH parsing with {NNN+} (including parentheses in bodies).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@gemini-code-assist

Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request enhances the IMAP client's robustness by introducing comprehensive support for the LITERAL+ syntax defined in RFC 7888. This change is crucial for correctly parsing FETCH responses from servers like Gmail that advertise and use this syntax, preventing errors related to literal body content, especially when it contains parentheses. The modifications ensure that literal sizes are accurately extracted and processed across all relevant parsing stages, improving overall compatibility and reliability.

Highlights

  • IMAP LITERAL+ Support: Implemented full support for the IMAP LITERAL+ (RFC 7888) syntax, which uses {NNN+} for literal sizes.
  • Gmail Compatibility Fix: Resolved "mismatched parentheses" errors encountered when processing FETCH responses from Gmail, which utilizes LITERAL+ syntax.
  • Parsing Layer Updates: Modified the Exec wire reading, findFetchContentEnd boundary detection, and parseFetchTokens tokenization to correctly interpret and handle LITERAL+ literals.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Changelog
  • exec.go
    • Modified the Exec function to correctly parse literal sizes by stripping the '+' character from {NNN+} syntax before converting the size string to an integer.
  • issue80_test.go
    • Added a new test file containing six new tests to thoroughly validate the handling of LITERAL+ syntax in various scenarios, including Exec wire assembly, token parsing, findFetchContentEnd behavior, multi-record responses, empty bodies, and mixed standard/LITERAL+ responses.
  • parse.go
    • Updated the atom regular expression to match both standard {NNN} and LITERAL+ {NNN+} patterns.
    • Modified the parseFetchTokens function to correctly handle the '+' character within LITERAL+ size specifications, ensuring proper tokenization.
    • Adjusted the findFetchContentEnd function to recognize and correctly calculate the length of LITERAL+ bodies, preventing parsing errors when literal content contains parentheses.
Activity
  • New tests were added in issue80_test.go to cover all LITERAL+ scenarios, including Exec wire assembly, token parsing, ParseFetchResponse end-to-end, multi-record LITERAL+ responses, empty body edge cases, and mixed standard/LITERAL+ responses.
  • All existing tests passed, and the race detector ran clean, indicating no regressions or concurrency issues.
  • The pull request was generated using Claude Code.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

- Replace artifact upload with codecov/codecov-action@v5
- Add push trigger on master for baseline coverage
- Add Codecov badge to README

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@codecov-commenter

Copy link
Copy Markdown

Welcome to Codecov 🎉

Once you merge this PR into your default branch, you're all set! Codecov will compare coverage reports and display results in all future pull requests.

Thanks for integrating Codecov - We've got you covered ☂️

@BrianLeishman BrianLeishman merged commit 812d3b2 into master Mar 11, 2026
1 check passed

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request adds support for RFC 7888's LITERAL+ syntax in IMAP responses. The changes include modifying exec.go to strip the trailing + from literal size strings before integer conversion, and updating parse.go to adjust the atom regular expression and the parseFetchTokens and findFetchContentEnd functions to correctly handle the + character in literal size declarations. A new test file, issue80_test.go, was added with comprehensive test cases to validate the correct parsing and assembly of LITERAL+ responses. A review comment suggests an improvement to an error message in parse.go, recommending that it report the exact numeric string passed to strconv.Atoi when parsing literal sizes, rather than the full literal string that might include a +, for better debugging.

Comment thread parse.go
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.

parseFetchTokens:"mismatched parentheses" while fetching old mail from imap.gmail.com

3 participants