fix: handle IMAP LITERAL+ ({NNN+}) syntax from Gmail#81
Conversation
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>
There was a problem hiding this comment.
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 sharedatomregex. - Update
Execliteral size parsing to strip a trailing+beforeAtoi. - Teach
findFetchContentEndandparseFetchTokensto 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.
Summary of ChangesHello, 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
🧠 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
Activity
Using Gemini Code AssistThe 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
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 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
|
- 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>
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 ☂️ |
There was a problem hiding this comment.
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.
Summary
{NNN+}\r\nsyntax across all three parsing layers:Execwire reading,findFetchContentEndboundary detection, andparseFetchTokenstokenization"mismatched parentheses"errors when email bodies contain parenthesesatomregex to match{NNN+}, strips+before size parsing in Exec, and handles+with}validation in the token parserCloses #80
Test plan
issue80_test.gocovering all LITERAL+ scenarios{NNN+}bodies{NNN+}literals containing parenthesesParseFetchResponseend-to-end with LITERAL+ and nested parens in body{0+}edge case{NNN}and LITERAL+{NNN+}in same response🤖 Generated with Claude Code