feat: support color flags in flag/unflag commands#49
Conversation
Add --color / -c flag to the flag and unflag commands, supporting Apple Mail and Fastmail color flags via the IETF $MailFlagBit keywords. Valid colors: red, orange, yellow, green, blue, purple, gray. The flag command sets $flagged plus the appropriate $MailFlagBit0/1/2 keywords. The unflag command now clears all color bits alongside $flagged per the IETF spec recommendation. With --color on unflag, only the color bits are removed while keeping the email flagged. Closes #33
There was a problem hiding this comment.
Pull request overview
This PR adds support for colored flags in the flag and unflag commands, implementing the IETF MailFlagBit specification for flag colors. The implementation allows users to set one of seven flag colors (red, orange, yellow, green, blue, purple, gray) when flagging emails, and provides options to selectively clear color bits while maintaining flag state.
Changes:
- Adds
FlagColortype with 3-bit encoding for seven IETF-standard flag colors - Extends
flagcommand with--colorstring flag to set colored flags - Extends
unflagcommand with--colorboolean flag to clear only color bits - Updates plain
unflagto also clear all color bits per IETF spec recommendation
Reviewed changes
Copilot reviewed 11 out of 11 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| internal/client/color.go | New file implementing FlagColor type with parsing, validation, and JMAP patch generation for 3-bit color encoding |
| internal/client/color_test.go | Comprehensive unit tests for color parsing, bit encoding, and all three client methods (SetFlaggedWithColor, SetUnflagged, ClearFlagColor) |
| internal/client/email.go | Adds SetFlaggedWithColor and ClearFlagColor methods; updates SetUnflagged to clear color bits alongside $flagged |
| internal/client/email_test.go | Updates TestUnflagPatchStructure to verify color bits are cleared when unflagging |
| cmd/flag.go | Adds --color string flag with validation and integration to SetFlaggedWithColor |
| cmd/unflag.go | Adds --color boolean flag to conditionally call ClearFlagColor instead of SetUnflagged |
| cmd/docs_drift_test.go | Extends drift detection tests to cover flag and unflag commands |
| docs/CLI-REFERENCE.md | Documents new --color flags for both commands with usage examples and IETF spec references |
| tests/help.md | Updates help output snapshots to include --color flag in both commands |
| tests/flags.md | Adds CLI snapshot tests for valid/invalid color usage and flag parsing |
| docs/plans/done/2026-02-17-support-color-flags-in-flag-unflag-commands.md | Planning document capturing design decisions and IETF spec alignment |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Rename `c` to `parsedColor` in the color parsing block to avoid shadowing with the client variable `c` declared later in the same function. Also update Copilot instructions to document intentional patterns: - ValidColorNames hardcoded rainbow ordering - Scrut edge-case arguments for boolean flag testing
…-flags-in-flag-unflag-commands * origin/main: fix: stop global flags section at next heading or rule test: add unit tests for remaining SearchEmails filter options test: derive drift coverage commands from root test: include session in drift-prevention coverage test: extend CLI drift-prevention tests to all commands # Conflicts: # cmd/docs_drift_test.go
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 12 out of 12 changed files in this pull request and generated no new comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Summary
--color/-cflag to theflagcommand, accepting one of 7 color names (red,orange,yellow,green,blue,purple,gray) to set IETF$MailFlagBitkeywords alongside$flagged--color/-cboolean flag to theunflagcommand to clear only color bits while keeping the email flaggedunflagto also clear all color bits per the IETF spec recommendationFlagColortype ininternal/client/color.gowith 3-bit encoding, parsing, and JMAP patch generationTest plan
ParseFlagColor(valid names, case-insensitive, invalid input)FlagColor.Patch()verifying correct bit patterns for all 7 colorsSetFlaggedWithColor,SetUnflagged(now clears color bits), andClearFlagColorpatch structureflag --color orange,flag -c blue,flag --color magenta(invalid),unflag --colorflagandunflagCloses #33