Skip to content

feat(gmail): add recipient management flags and extract shared message builder#362

Open
malob wants to merge 2 commits intogoogleworkspace:mainfrom
malob:feat/gmail-recipient-flags
Open

feat(gmail): add recipient management flags and extract shared message builder#362
malob wants to merge 2 commits intogoogleworkspace:mainfrom
malob:feat/gmail-recipient-flags

Conversation

@malob
Copy link
Contributor

@malob malob commented Mar 10, 2026

Description

Brings all four Gmail composition helpers to feature parity for recipient management:

  • +send: add --cc, --bcc
  • +reply / +reply-all: add --to (additive), --bcc
  • +forward: add --bcc

--to on reply/reply-all appends to the auto-computed To field. If an email appears in
multiple fields, dedup_recipients keeps it in the highest-priority one (To > CC > BCC).

Commit 1 — Feature

Adds the flags, dedup logic, argument parsing, tests, skill file updates, and changeset.

Commit 2 — Refactor and bugfixes

Adding the flags tripled the surface area of duplicated header-construction code across
send, reply, and forward — each independently doing the same if let Some(cc) /
push_str(&format!(...)) pattern. The second commit extracts a shared MessageBuilder
into mod.rs that centralizes:

  • CRLF header-injection sanitization — previously absent from reply and forward paths
  • RFC 2047 subject encoding — previously only in send
  • Consistent whitespace normalization on optional arguments via parse_optional_trimmed
    (also fixes --from on reply/forward, which was not previously trimmed)
  • ThreadingHeaders groupingin_reply_to and references are now a single
    Option<ThreadingHeaders> on MessageBuilder, making it structurally impossible to
    set one without the other

Additional fixes:

  • Silent auth failure in +sendErr(_) swallowed all auth errors and fell back to
    unauthenticated mode; now returns GwsError::Auth immediately (except during --dry-run)
  • try_get_one error swallowing in reply.ok().flatten() hid all errors; now
    explicitly matches UnknownArgument and propagates unexpected errors

This commit is cleanly revertable if reviewers prefer the feature without the refactor.

Dry Run Output:

Not applicable — CC/BCC/From are encoded inside the RFC 2822 raw message, not as separate
JSON fields. The users.messages.send request body ({"raw": "..."}) is structurally
unchanged.

Checklist:

  • My code follows the AGENTS.md guidelines (no generated google-* crates).
  • I have run cargo fmt --all to format the code perfectly.
  • I have run cargo clippy -- -D warnings and resolved all warnings.
  • I have added tests that prove my fix is effective or that my feature works.
  • I have provided a Changeset file (e.g. via pnpx changeset) to document my changes.

malob added 2 commits March 9, 2026 22:11
Add --cc and --bcc to +send, --to and --bcc to +reply and +reply-all,
and --bcc to +forward. This brings all four Gmail helpers to feature
parity for basic recipient management.

Key behaviors:
- --to on reply/reply-all is additive (appends to auto-computed To)
- --remove only affects auto-computed recipients, not explicit flags
- Dedup with priority To > CC > BCC via new dedup_recipients()
- Validation deferred until after all additions and dedup
- Empty/whitespace --cc/--bcc/--to filtered to None at parse time
- BCC header included in raw message (Gmail API strips before delivery)

Also includes:
- CAUTION boxes in all four SKILL.md files
- SendConfig visibility narrowed to pub(super)
- Consistent "email address(es)" wording across clap help and SKILL.md
…ssues

Extract duplicated header-construction logic from send.rs, reply.rs, and
forward.rs into a shared MessageBuilder in mod.rs. This centralizes CRLF
header-injection sanitization and RFC 2047 subject encoding that were
previously inconsistent across the three paths.

Additional changes:
- Fix silent auth failure in send.rs (Err(_) swallowed all auth errors)
- Fix try_get_one error swallowing in parse_reply_args (explicit match
  on MatchesError::UnknownArgument, propagate unexpected errors)
- Extract shared helpers: build_references, parse_optional_trimmed,
  encode_header_value, sanitize_header_value
- Introduce ForwardEnvelope (analogous to ReplyEnvelope)
- Introduce ThreadingHeaders to group in_reply_to/references
@changeset-bot
Copy link

changeset-bot bot commented Mar 10, 2026

🦋 Changeset detected

Latest commit: 6e2b0c3

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@googleworkspace/cli Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@googleworkspace-bot googleworkspace-bot added area: skills area: core Core CLI parsing, commands, error handling, utilities labels Mar 10, 2026
@gemini-code-assist
Copy link
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 significantly enhances the Gmail command-line interface by introducing comprehensive recipient management flags across +send, +reply, +reply-all, and +forward commands. It also includes a substantial refactor that extracts a shared MessageBuilder to centralize email header construction, ensuring consistent application of security measures like CRLF sanitization and RFC 2047 encoding. These changes improve both the functionality and robustness of the Gmail helpers.

Highlights

  • Expanded Recipient Management: Added --cc and --bcc flags to +send, --to (additive) and --bcc to +reply and +reply-all, and --bcc to +forward commands, bringing recipient management to feature parity across Gmail helpers.
  • Centralized Message Building: Introduced a shared MessageBuilder in mod.rs to consolidate email header construction logic, improving consistency and maintainability across +send, +reply, and +forward.
  • Enhanced Security and Standards Compliance: Implemented CRLF header-injection sanitization and standardized RFC 2047 subject encoding within the new MessageBuilder, addressing previous inconsistencies and security vulnerabilities.
  • Intelligent Recipient Deduplication: Added logic to automatically deduplicate recipients across To, CC, and BCC fields, prioritizing To > CC > BCC to ensure emails are sent efficiently and correctly.
  • Improved Argument Parsing and Error Handling: Refactored argument parsing to consistently trim whitespace from optional arguments and fixed issues where auth failures and try_get_one errors were silently swallowed.
Changelog
  • .changeset/add-recipient-flags.md
    • Added a new changeset file documenting the addition of recipient flags.
  • skills/gws-gmail-forward/SKILL.md
    • Updated documentation to include the new --bcc flag and an example.
  • skills/gws-gmail-reply-all/SKILL.md
    • Updated documentation to include the new --to and --bcc flags, examples, and refined tips.
  • skills/gws-gmail-reply/SKILL.md
    • Updated documentation to include the new --to and --bcc flags, examples, and refined tips.
  • skills/gws-gmail-send/SKILL.md
    • Updated documentation to include the new --cc and --bcc flags, examples, and revised tips.
  • src/helpers/gmail/forward.rs
    • Refactored message creation to use the new MessageBuilder and ForwardEnvelope.
    • Updated argument parsing to support --bcc and use trimmed optional values.
  • src/helpers/gmail/mod.rs
    • Introduced MessageBuilder for centralized email header construction, including CRLF sanitization, RFC 2047 encoding, and ThreadingHeaders.
    • Added build_references and parse_optional_trimmed utility functions.
    • Updated clap argument definitions for all Gmail helpers to reflect new flags and improved help text.
  • src/helpers/gmail/reply.rs
    • Implemented --to and --bcc recipient handling, including deduplication logic.
    • Refactored message creation to use MessageBuilder.
    • Improved error handling for argument parsing.
  • src/helpers/gmail/send.rs
    • Rewrote email sending logic to leverage the new MessageBuilder for constructing raw messages.
    • Added support for --cc and --bcc flags.
Activity
  • No specific activity (comments, reviews, progress updates) has been recorded for this pull request yet.
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 Generative AI Prohibited Use Policy, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

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 new recipient management flags (--cc, --bcc, --to) across the Gmail composition helpers, achieving feature parity. More importantly, it includes a major refactoring that extracts a shared MessageBuilder. This change significantly improves the codebase by centralizing header construction, which fixes critical security vulnerabilities related to header injection in the +reply and +forward commands. The refactoring also addresses other important issues, including a silent authentication failure in +send, incorrect handling of non-ASCII subjects, and parsing errors for optional arguments. The implementation is robust, with comprehensive test coverage for the new logic and bug fixes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: core Core CLI parsing, commands, error handling, utilities area: skills

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants