Skip to content

Fix flag handling: keywords, color names, and $labelN support#5

Open
ivarsb wants to merge 3 commits into
mainfrom
additional-labels-fix
Open

Fix flag handling: keywords, color names, and $labelN support#5
ivarsb wants to merge 3 commits into
mainfrom
additional-labels-fix

Conversation

@ivarsb

@ivarsb ivarsb commented Jun 30, 2026

Copy link
Copy Markdown
Member

Problem

Setting non-system flags (e.g. colors) failed with:

IMAP authentication failed: Error in IMAP command UID STORE: Invalid system flag \YELLOW

update_mail_message_flags ran add.map(&:to_sym), converting every flag to a Symbol. net/imap renders a Symbol as a system flag (with a leading backslash), so any custom keyword like YELLOW or $label1 went out as \YELLOW / \$label1 and was rejected — IMAP only permits six system flags: \Seen \Answered \Flagged \Deleted \Draft \Recent.

Changes

  • Correct flag encoding — only the six real IMAP system flags become Symbols; everything else is sent as a bare keyword atom (String), which is what custom/keyword flags require.
  • Friendly color namesred, orange, green, blue, purple map to the Mozilla/Thunderbird $labelN keywords (the de-facto cross-client color convention), case-insensitively, on both add and remove.
  • Raw keywords still pass through$label1, Important, etc. are sent unchanged, so existing usage is unaffected.
Input Sent to IMAP
\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 $labelN pass-through. All passing.

🤖 Generated with Claude Code

ivarsb and others added 2 commits June 30, 2026 16:28
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>

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 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 $labelN keywords 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.

Comment thread lib/mail_mcp/tools/update_mail_message_flags_tool.rb
Comment thread lib/mail_mcp/tools/update_mail_message_flags_tool.rb
- 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>
@ivarsb ivarsb requested a review from ebeigarts June 30, 2026 13:41
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.

2 participants