Return UIDs from search_mail_messages - #11
Open
ivarsb wants to merge 1 commit into
Open
Conversation
search_messages issued IMAP SEARCH, which returns message sequence numbers. The tool serialised them under a `uids` key, but every tool a caller would chain into — get_mail_message, delete_mail_message, move_mail_message, update_mail_message_flags — issues UID commands (uid_fetch, uid_store, uid_move). Search results therefore addressed the wrong messages. The two agree only while a folder has never been expunged, since sequence numbers are renumbered on every expunge while UIDs are stable. In a fresh test mailbox seq == UID, so the mismatch looks like it works and then silently drifts: get_mail_message returns a different message than the one matched, and delete/move act on it. Switch to uid_search, matching list_messages, which already uses it. The specs stubbed :search and asserted the return value passed through, so the suite pinned the buggy contract rather than catching it — they now stub :uid_search. Net::IMAP is stubbed with instance_spy, a verifying double, so these also check uid_search exists and accepts the array-of-criteria form. No release included; production installs via `gem install mail_mcp -v X`, so this needs a version bump to land. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
search_messagesissued IMAPSEARCH, which returns message sequence numbers. The tool serialised them under auidskey, but every tool a caller would chain into —get_mail_message,delete_mail_message,move_mail_message,update_mail_message_flags— issues UID commands (uid_fetch,uid_store,uid_move). Search results therefore addressed the wrong messages.The two agree only while a folder has never been expunged: sequence numbers are renumbered on every expunge, UIDs are stable. In a fresh test mailbox
seq == UID, so the mismatch looks like it works and then silently drifts —get_mail_messagereturns a different message than the one matched, and delete/move act on it.Fix
Switch to
uid_search, matchinglist_messages, which already uses it. Search was the only sequence-number leak inImapClient; everything else was already UID-based.Also documents the return contract in the MCP tool description and the README tool table.
Tests
The specs stubbed
:searchand asserted the return value passed through, so the suite pinned the buggy contract rather than catching it. They now stub:uid_search.Net::IMAPis stubbed withinstance_spy, a verifying double, so these also checkuid_searchexists and accepts the array-of-criteria form.Verified by reverting the one-word change and re-running: both search examples fail. Full suite 84 examples / 0 failures, RuboCop clean.
Release
No version bump included. Production installs via
gem install mail_mcp -v X, so merging this does not deploy it — it needs a separate release commit, as with v1.0.3.🤖 Generated with Claude Code