Fix flag handling: keywords, color names, and $labelN support#5
Open
ivarsb wants to merge 3 commits into
Open
Conversation
update_mail_message_flags forced every flag through to_sym, so net/imap rendered non-system flags as backslash system flags (e.g. \YELLOW), which servers reject. Now only the six real IMAP system flags become symbols; everything else is sent as a bare keyword atom. Also add friendly color-name mapping (red/orange/green/blue/purple -> $labelN) while still accepting raw $labelN keywords unchanged. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
This PR fixes IMAP flag encoding in update_mail_message_flags so that only true IMAP system flags are sent as Symbols (rendered by net/imap with a leading backslash), while custom keyword flags (including $labelN) are sent as Strings, with additional support for mapping friendly color names to $labelN keywords.
Changes:
- Normalize flags so only known system flags become Symbols; custom flags remain Strings.
- Add case-insensitive mapping of friendly color names (
red,orange,green,blue,purple) to Mozilla/Thunderbird$labelNkeywords for both add/remove. - Expand RSpec coverage to validate system-flag vs keyword behavior and color mapping.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| lib/mail_mcp/tools/update_mail_message_flags_tool.rb | Introduces flag normalization logic, system-flag allowlist, and color-name → $labelN mapping; updates input schema description. |
| spec/mail_mcp/tools/update_mail_message_flags_tool_spec.rb | Updates and expands tests to assert correct symbol vs string encoding and color mapping behavior. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Match system flags case-insensitively (RFC 3501) and normalize to canonical capitalization, so "seen"/"\SEEN" still set :Seen rather than being sent as a bare keyword (regression vs old to_sym path). - Clarify in the schema that \Recent is recognized but not client-settable. Co-Authored-By: Claude Opus 4.8 (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
Setting non-system flags (e.g. colors) failed with:
update_mail_message_flagsranadd.map(&:to_sym), converting every flag to a Symbol.net/imaprenders a Symbol as a system flag (with a leading backslash), so any custom keyword likeYELLOWor$label1went out as\YELLOW/\$label1and was rejected — IMAP only permits six system flags:\Seen \Answered \Flagged \Deleted \Draft \Recent.Changes
red,orange,green,blue,purplemap to the Mozilla/Thunderbird$labelNkeywords (the de-facto cross-client color convention), case-insensitively, on bothaddandremove.$label1,Important, etc. are sent unchanged, so existing usage is unaffected.\Seen/Seen:Seen(system flag)red$label1(keyword)$label1$label1(keyword, unchanged)Tests
8 examples covering system flags, custom keywords, color-name mapping (incl. case-insensitivity and remove), and raw
$labelNpass-through. All passing.🤖 Generated with Claude Code