Skip to content

feat(gmail): add --html flag for HTML email composition#417

Open
malob wants to merge 1 commit intogoogleworkspace:mainfrom
malob:feat/gmail-html-mode
Open

feat(gmail): add --html flag for HTML email composition#417
malob wants to merge 1 commit intogoogleworkspace:mainfrom
malob:feat/gmail-html-mode

Conversation

@malob
Copy link
Contributor

@malob malob commented Mar 11, 2026

Description

Adds an --html flag to all four Gmail composition commands (+send, +reply,
+reply-all, +forward). When set, --body is treated as HTML content and
Content-Type switches from text/plain to text/html.

For +send, this is straightforward — the flag just changes the content type.

For +reply, +reply-all, and +forward, the flag also changes how the
quoted/forwarded block is constructed. Instead of plain-text quoting, the HTML
output matches Gmail web UI fidelity:

  • gmail_quote / gmail_quote_container CSS classes on the outer div
  • gmail_sendername structure on the forwarded From line (<strong> + <span>)
  • mailto: links on email addresses in reply attribution and forward metadata
  • <div dir="ltr"> wrapper on quoted reply content
  • RFC 2822 dates reformatted to Gmail's display style ("Wed, Mar 4, 2026 at 3:01 PM")
  • Conditional CC line in forwards (omitted when empty, includes mailto links when present)
  • <br> separator between user body and quoted/forwarded block (not \r\n\r\n)

When the original message has an HTML body (multipart/alternative), it is used
directly in the quoted/forwarded block. When there is no HTML part, the plain text
body is HTML-escaped with <br> line breaks as a fallback (with a stderr diagnostic
so the user knows the output is a conversion, not the original formatting).

How the fidelity targets were determined

The HTML structure was reverse-engineered from real Gmail web UI messages — I examined
the raw RFC 2822 bodies of replies and forwards sent from the Gmail web interface and
matched the class names, element nesting, and attribute patterns. A few details were
intentionally skipped as not worth replicating:

  • <div class="msg{id}"> wrapper on forwarded bodies — Gmail JS internal, no rendering effect
  • Blockquote style shorthand vs. expanded properties — Gmail itself is inconsistent here
  • Inline cid: image references will appear broken in quoted/forwarded HTML (documented
    in SKILL.md tips as a known limitation; externally hosted images are unaffected)

Shared helpers extracted to mod.rs

The HTML formatting required several shared helpers in mod.rs (all pub(super)): HTML
escaping, MIME tree walking for text/html extraction, mailto link formatting, RFC 5322
address parsing, and date reformatting via chrono (already a direct dependency).
split_mailbox_list was promoted from reply.rs to shared scope, which also fixed a
latent bug where naive split(',') would break on quoted commas in display names like
"Doe, John" <john@example.com>.

Live testing

Tested on live emails using +reply --html and +forward --html against real threads.
Both rendered correctly in the Gmail web UI — quoted blocks appeared with proper formatting,
attribution lines had clickable mailto links, and the overall structure matched native
Gmail replies/forwards.

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.

Add --html flag to +send, +reply, +reply-all, and +forward, enabling
HTML email composition. When set, --body is treated as HTML content and
the Content-Type switches from text/plain to text/html.

For replies and forwards, the quoted/forwarded block matches Gmail web
UI fidelity: gmail_quote_container class, gmail_sendername structure,
mailto links in attribution and metadata, <div dir="ltr"> wrapper on
quoted content, and RFC 2822 dates reformatted to Gmail's human-friendly
style. When the original message has no HTML body, plain text is
HTML-escaped with <br> line breaks as a fallback (with a stderr
diagnostic).
@changeset-bot
Copy link

changeset-bot bot commented Mar 11, 2026

🦋 Changeset detected

Latest commit: 03965b5

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

@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 upgrades the Gmail CLI commands by introducing an --html flag, allowing users to compose and send emails with rich HTML content. It meticulously recreates the intricate HTML structure and styling found in Gmail's web interface for replies and forwards, ensuring a consistent and high-fidelity user experience. This enhancement also involved a substantial refactoring effort to centralize and improve email-related utility functions, making the codebase more robust and maintainable.

Highlights

  • New --html flag: Introduced an --html flag for all four Gmail composition commands (+send, +reply, +reply-all, +forward) to enable HTML email composition.
  • HTML Fidelity for Replies and Forwards: When --html is used with +reply, +reply-all, and +forward, the quoted/forwarded block is constructed to match Gmail web UI fidelity, including specific CSS classes, mailto links, date reformatting, and HTML-escaped content.
  • Content Type Handling: The --body content is treated as HTML and the Content-Type header switches from text/plain to text/html when the --html flag is present.
  • HTML Body Resolution: The original message's HTML body is used directly in quoted/forwarded blocks if available; otherwise, the plain text body is HTML-escaped with <br> line breaks as a fallback.
  • Shared Helper Extraction and Improvements: Several HTML formatting, MIME tree walking, mailto link formatting, RFC 5322 address parsing, and date reformatting helpers were extracted to src/helpers/gmail/mod.rs. The split_mailbox_list function was also promoted and improved to correctly handle quoted commas in display names.
Changelog
  • .changeset/add-html-mode.md
    • Added a changeset file documenting the new --html flag for HTML email composition.
  • skills/gws-gmail-forward/SKILL.md
    • Updated documentation to include the new --html flag, its description, an example, and tips regarding HTML formatting and inline images for the +forward command.
  • skills/gws-gmail-reply-all/SKILL.md
    • Updated documentation to include the new --html flag, its description, an example, and tips regarding HTML formatting and inline images for the +reply-all command.
  • skills/gws-gmail-reply/SKILL.md
    • Updated documentation to include the new --html flag, its description, an example, and tips regarding HTML formatting and inline images for the +reply command.
  • skills/gws-gmail-send/SKILL.md
    • Updated documentation to include the new --html flag, its description, an example, and tips regarding HTML content for the +send command.
  • src/helpers/gmail/forward.rs
    • Modified ForwardConfig and ForwardEnvelope structs to include an html flag.
    • Updated create_forward_raw_message to conditionally use HTML formatting for the forwarded block based on the html flag.
    • Added a new format_forwarded_message_html function to generate Gmail-fidelity HTML for forwarded messages.
    • Updated argument parsing to recognize and process the new --html flag.
    • Added new unit tests to verify the functionality of HTML forwarding and argument parsing for the --html flag.
  • src/helpers/gmail/mod.rs
    • Extended OriginalMessage struct to include an optional body_html field for storing HTML content of original messages.
    • Refactored extract_plain_text_body into a more general extract_body_by_mime function to support extracting both plain text and HTML bodies.
    • Added extract_html_body function to specifically extract HTML content from message payloads.
    • Introduced resolve_html_body to determine the appropriate HTML content for quoting/forwarding, falling back to HTML-escaped plain text if no HTML body is present.
    • Added new public helper functions: html_escape, extract_email, extract_display_name, split_mailbox_list, format_email_link, format_sender_for_attribution, format_address_list_with_links, format_date_for_attribution, and format_forward_from to support Gmail-fidelity HTML formatting.
    • Updated MessageBuilder to include an html flag, which controls the Content-Type header (text/plain or text/html) of the outgoing message.
    • Added new unit tests for HTML body extraction, HTML escaping, and the new HTML fidelity helper functions.
  • src/helpers/gmail/reply.rs
    • Modified ReplyEnvelope and ReplyConfig structs to include an html flag.
    • Updated create_reply_raw_message to conditionally use HTML formatting for the quoted original message based on the html flag.
    • Added a new format_quoted_original_html function to generate Gmail-fidelity HTML for quoted replies.
    • Removed local split_mailbox_list and extract_email functions, now using the shared versions from src/helpers/gmail/mod.rs.
    • Updated argument parsing to recognize and process the new --html flag.
    • Added new unit tests to verify the functionality of HTML replies and argument parsing for the --html flag.
  • src/helpers/gmail/send.rs
    • Modified SendConfig struct to include an html flag.
    • Updated handle_send to pass the html flag to the MessageBuilder.
    • Updated argument parsing to recognize and process the new --html flag.
    • Added new unit tests to verify sending HTML emails and argument parsing for the --html flag.
Activity
  • The author malob introduced a new feature to enable HTML email composition across Gmail CLI commands.
  • The implementation includes detailed logic to replicate Gmail's web UI HTML fidelity for replies and forwards.
  • Shared utility functions for email parsing and formatting were refactored and centralized.
  • Comprehensive unit tests were added to cover the new HTML functionality and argument parsing.
  • The author completed all checklist items, including code formatting, linting, testing, and changeset documentation.
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.

@googleworkspace-bot googleworkspace-bot added area: skills area: core Core CLI parsing, commands, error handling, utilities labels Mar 11, 2026
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 is an excellent pull request that adds a significant new feature for composing HTML emails. The changes are well-structured, with shared logic correctly refactored into the mod.rs module for reuse across the send, reply, and forward commands. The implementation pays close attention to fidelity with the Gmail web UI, including details like CSS classes, date formatting, and mailto links. Security considerations, such as HTML escaping of headers, are also handled correctly. The addition of comprehensive tests for the new HTML functionality and helper utilities is commendable. I have reviewed the code for critical and high-severity issues and found none. The implementation is robust and of high quality.

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