Skip to content

fix(gmail): RFC 2047 encode draft address headers#458

Open
sonwr wants to merge 1 commit intogoogleworkspace:mainfrom
sonwr:fix/gmail-rfc2047-draft-address-headers
Open

fix(gmail): RFC 2047 encode draft address headers#458
sonwr wants to merge 1 commit intogoogleworkspace:mainfrom
sonwr:fix/gmail-rfc2047-draft-address-headers

Conversation

@sonwr
Copy link

@sonwr sonwr commented Mar 13, 2026

Description

Fixes #404.

This updates Gmail draft message building to RFC 2047 encode sanitized non-ASCII From, Cc, and Bcc header values, matching the existing Subject handling.

Reproduction:

  • On origin/main, cargo test message_builder_encodes_non_ascii_optional_headers -- --nocapture failed because optional draft address headers were emitted as raw UTF-8.
  • With this patch, the same test passes and the full Rust validation suite passes locally.

Dry Run Output:

Not applicable.

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.

@changeset-bot
Copy link

changeset-bot bot commented Mar 13, 2026

🦋 Changeset detected

Latest commit: 4928d9b

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 Patch

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 the area: core Core CLI parsing, commands, error handling, utilities label Mar 13, 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 addresses an issue where non-ASCII characters in From, Cc, and Bcc headers of Gmail draft messages were not being properly encoded. By applying RFC 2047 encoding, the changes ensure that these headers are correctly formatted, preventing potential failures and improving compatibility for internationalized email addresses.

Highlights

  • RFC 2047 Encoding: Implemented RFC 2047 encoding for From, Cc, and Bcc headers in Gmail draft messages to correctly handle non-ASCII characters.
  • Header Consistency: Aligned the encoding behavior for From, Cc, and Bcc headers with the existing Subject header handling, ensuring uniform message construction.
  • Test Coverage: Added a new test case (test_message_builder_encodes_non_ascii_optional_headers) to validate the correct RFC 2047 encoding of non-ASCII characters in optional address headers.
Changelog
  • .changeset/fix-gmail-rfc2047-draft-address-headers.md
    • fix(gmail): RFC 2047 encode non-ASCII draft From/Cc/Bcc headers
Activity
  • Identified a failing test (cargo test message_builder_encodes_non_ascii_optional_headers) on origin/main due to raw UTF-8 emission in optional draft address headers.
  • Confirmed that the previously failing test now passes with the applied patch.
  • Verified that the full Rust validation suite passes locally.
  • Ensured adherence to AGENTS.md guidelines, cargo fmt --all, cargo clippy -- -D warnings, and added a Changeset file.
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 addresses an issue with non-ASCII characters in email address headers by applying RFC 2047 encoding to From, Cc, and Bcc values. This is a good fix that improves email format compliance. The change is supported by a new test case. However, my review found that the To header is not being encoded, which is inconsistent with how Subject, From, Cc, and Bcc are handled. This oversight could lead to malformed emails if the To field contains non-ASCII display names. I've recommended that the To header also be encoded to ensure all address headers are treated consistently.

Comment on lines 508 to 513
if let Some(from) = self.from {
headers.push_str(&format!("\r\nFrom: {}", sanitize_header_value(from)));
headers.push_str(&format!(
"\r\nFrom: {}",
encode_header_value(&sanitize_header_value(from))
));
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

While this change correctly applies RFC 2047 encoding to the From, Cc, and Bcc headers, the To header is not being encoded. This is inconsistent and could lead to malformed emails if the To field contains non-ASCII characters in display names (e.g., "日本語名前" <user@example.com>).

For correctness and consistency with other address headers, the To header value should also be passed through encode_header_value. The To header is currently only sanitized on line 485.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Gmail draft update: non-ASCII CC/From/BCC headers not RFC 2047 encoded (mojibake)

2 participants