Skip to content

Add Dialer.GetMaxUID as alt method using RFC-4731#83

Closed
MartinBrugnara wants to merge 3 commits into
BrianLeishman:masterfrom
MartinBrugnara:master
Closed

Add Dialer.GetMaxUID as alt method using RFC-4731#83
MartinBrugnara wants to merge 3 commits into
BrianLeishman:masterfrom
MartinBrugnara:master

Conversation

@MartinBrugnara

Copy link
Copy Markdown
Contributor

As per the title, it adds Dialer.GetMaxUID as an alternative and cheaper method to get the latest email UID.
This method uses imap "SEARCH + RETURN" feature and thus requires RFC-4731.

Examples have been provided in the README.md and examples/search/main.go.
Tests have been added to message_test.go and integration_test.go.
The latter are disabled for the test server (greenmail:2.1.2) does not support RFC-4731.

@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 Dialer functionality by introducing a new GetMaxUID method. This method offers a more efficient way to determine the highest email UID in a selected folder by leveraging the IMAP RFC-4731 extension for SEARCH RETURN (MAX). This optimization is particularly beneficial for applications needing to quickly identify the latest message without fetching a range of UIDs.

Highlights

  • New GetMaxUID method: Introduced Dialer.GetMaxUID to efficiently retrieve the highest email UID in a folder.
  • RFC-4731 support: The new method leverages the IMAP 'SEARCH + RETURN' feature, specifically requiring RFC-4731 for its operation.
  • Examples and Tests: Provided usage examples in README.md and examples/search/main.go, and added both unit and integration tests for the new functionality.

🧠 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
  • .gitignore
    • Added *.sw? to ignore Vim swap files.
  • README.md
    • Updated the 'Get the N most recent messages' section with an example for GetMaxUID.
  • examples/search/main.go
    • Added a call to m.GetMaxUID() and printed its result.
  • integration_test.go
    • Added a new TestIntegration_GetMaxUID test case, conditionally disabled due to lack of RFC-4731 support in the test server.
  • message.go
    • Implemented the GetMaxUID method, which executes a UID SEARCH RETURN (MAX) command.
  • message_test.go
    • Added TestParseMaxUID_re to test the parseMaxUIDSearchResponse function.
  • parse.go
    • Added a new regular expression searchMaxUIDre to match RFC-4731 ESEARCH responses.
    • Implemented parseMaxUIDSearchResponse to extract the maximum UID from the IMAP response.
Activity
  • New Dialer.GetMaxUID method added, leveraging RFC-4731 for optimized highest UID retrieval.
  • Examples for the new method were added to README.md and examples/search/main.go.
  • Unit tests for the parsing logic (parseMaxUIDSearchResponse) were included in message_test.go.
  • An integration test for GetMaxUID was added to integration_test.go, but it is currently disabled because the test IMAP server (greenmail:2.1.2) does not support RFC-4731.
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.

@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 introduces Dialer.GetMaxUID(), a more efficient method to retrieve the maximum UID from a mailbox by leveraging RFC-4731. The changes include the new method implementation, parsing logic for the server response, documentation updates in README.md, a new example, and corresponding unit and integration tests. My review focuses on improving the robustness of the response parsing and adopting best practices for disabling integration tests. Overall, this is a valuable addition.

Comment thread integration_test.go Outdated
Comment thread parse.go Outdated
MartinBrugnara and others added 2 commits March 14, 2026 20:52
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
@codecov

codecov Bot commented Mar 16, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 42.85714% with 12 lines in your changes missing coverage. Please review.
✅ Project coverage is 20.81%. Comparing base (5862654) to head (ab899cd).
⚠️ Report is 2 commits behind head on master.

Files with missing lines Patch % Lines
message.go 0.00% 5 Missing ⚠️
parse.go 64.28% 3 Missing and 2 partials ⚠️
examples/search/main.go 0.00% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master      #83      +/-   ##
==========================================
+ Coverage   20.58%   20.81%   +0.22%     
==========================================
  Files          19       19              
  Lines        2074     2095      +21     
==========================================
+ Hits          427      436       +9     
- Misses       1607     1617      +10     
- Partials       40       42       +2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

BrianLeishman added a commit that referenced this pull request Mar 16, 2026
* Add Dialer.GetMaxUID as alt method using RFC-4731

* Use t.Skip() instread of if (false)

Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>

* strings.Split -> strings.Fields; camelCase instead of snake

Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>

* fix: fix indentation and add tests for parseMaxUIDSearchResponse coverage

Fix indentation issues from applying review suggestions and add unit
tests covering error paths (no ESEARCH line, empty response, non-numeric
MAX value) to satisfy code coverage requirements.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* fix: address review feedback for parseMaxUIDSearchResponse

- Rename searchMaxUIDre to searchMaxUIDRE for naming consistency
- Use case-insensitive regex with capturing group to extract MAX value
- Handles MAX not being the last token (RFC 4731 allows MIN/MAX/COUNT)
- Add tests for case-insensitive matching and MAX-not-last scenarios

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* fix: address code review feedback for GetMaxUID

- Handle empty mailbox: ESEARCH without MAX returns 0, nil (RFC 4731)
- Detect malformed ESEARCH MAX values and return error
- Add RFC-4731 server requirement caveat to README and example
- Example now handles GetMaxUID error instead of silently ignoring it

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* refactor: simplify ESEARCH detection in parseMaxUIDSearchResponse

- Replace redundant strings.EqualFold on "* " (no letters) with ==
- Move strings.ToUpper inside prefix check to avoid uppercasing
  every non-ESEARCH line

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: Martin Brugnara <mb@martinbrugnara.me>
Co-authored-by: Martin Brugnara <martin@0x6d62.eu>
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
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.

1 participant