Skip to content

fix: RFC 2047 encode non-ASCII email subjects in +send helper#322

Merged
jpoehnelt merged 5 commits intogoogleworkspace:mainfrom
jonameijers:fix/rfc2047-subject-encoding
Mar 9, 2026
Merged

fix: RFC 2047 encode non-ASCII email subjects in +send helper#322
jpoehnelt merged 5 commits intogoogleworkspace:mainfrom
jonameijers:fix/rfc2047-subject-encoding

Conversation

@jonameijers
Copy link
Contributor

@jonameijers jonameijers commented Mar 9, 2026

Fixes #266

Description

  • gmail +send writes the --subject value directly into the RFC 2822 Subject: header without encoding, causing non-ASCII characters (em dashes, CJK, accented characters) to render as garbled text (e.g. †instead of )
  • Add encode_header_value() that RFC 2047 base64-encodes the subject when it contains non-ASCII; ASCII subjects pass through unchanged
  • Uses standard Base64 (RFC 2045) and folds long subjects into multiple encoded-words at the 75-char limit
  • Chunks at character boundaries to avoid splitting multi-byte UTF-8 sequences across encoded-words
  • Add missing MIME-Version and Content-Type: text/plain; charset=utf-8 headers to the raw message
  • 6 new/updated tests covering ASCII subjects, non-ASCII short subjects, long subject folding, and multi-byte character boundary safety

Dry Run Output:

N/A — change is to internal MIME message construction, not API call shape

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 9, 2026

🦋 Changeset detected

Latest commit: fb5b675

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

@google-cla
Copy link

google-cla bot commented Mar 9, 2026

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@googleworkspace-bot googleworkspace-bot added the area: core Core CLI parsing, commands, error handling, utilities label Mar 9, 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 email subjects sent via the gmail +send helper would appear garbled. The solution involves properly encoding these subjects according to RFC 2047 and including essential MIME headers in the raw email message, significantly improving email compatibility and display across various clients.

Highlights

  • RFC 2047 Encoding for Subjects: Implemented RFC 2047 base64 encoding for email subjects containing non-ASCII characters in the +send helper, resolving issues with garbled subjects in clients like Gmail.
  • MIME Headers Added: Added MIME-Version: 1.0 and Content-Type: text/plain; charset=utf-8 headers to the raw email message construction for better email client compatibility.
  • New Encoding Helper Function: Introduced a new encode_header_value function to encapsulate the conditional RFC 2047 encoding logic, making the create_raw_message function cleaner.
  • Comprehensive Test Coverage: Added new unit tests to cover both ASCII and non-ASCII subject encoding scenarios, ensuring the new functionality works as expected.
Changelog
  • .changeset/fix-rfc2047-subject.md
    • Added a new changeset file documenting the fix for non-ASCII email subjects.
  • src/helpers/gmail/send.rs
    • Added encode_header_value function to conditionally RFC 2047 encode header values.
    • Modified create_raw_message to utilize encode_header_value for the subject and to include MIME-Version and Content-Type headers.
    • Updated test_create_raw_message to reflect the new MIME headers.
    • Added test_create_raw_message_non_ascii_subject to verify non-ASCII subject encoding.
    • Added test_encode_header_value_ascii and test_encode_header_value_non_ascii to test the new encoding function.
Activity
  • No specific review comments or discussions have been recorded yet for this pull request.
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 correctly identifies the need to RFC 2047 encode non-ASCII email subjects and adds the necessary MIME headers. However, the current implementation has two critical issues regarding RFC 2047 compliance: it uses an incorrect Base64 variant and does not handle the mandatory 75-character line length limit for encoded words, which can lead to malformed subjects. I've provided suggestions to address these issues and improve the tests.

@googleworkspace-bot
Copy link
Collaborator

/gemini review

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 important issue by RFC 2047 encoding non-ASCII email subjects and adding necessary MIME headers. However, the implementation of the encoding function has a critical flaw: it can split multi-byte UTF-8 characters, leading to corrupted subject lines. I've provided a detailed comment with a suggested fix to ensure chunking respects character boundaries. The rest of the changes, including the new tests, look good, though I'd recommend adding a test case for the issue I've identified.

@googleworkspace-bot
Copy link
Collaborator

/gemini review

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 correctly fixes an issue with non-ASCII email subjects by implementing RFC 2047 encoding. The changes include adding the necessary MIME headers and comprehensive tests for the new encoding logic. My main feedback is to consider using a dedicated library for MIME handling, such as mail-headers, instead of a custom implementation. This would improve long-term correctness and maintainability by relying on a specialized, well-tested crate for a complex standard, and would also simplify the code.

Fix garbled non-ASCII email subjects in gmail +send by RFC 2047 encoding the Subject header and adding MIME-Version/Content-Type headers.
@github-actions
Copy link
Contributor

github-actions bot commented Mar 9, 2026

/gemini review

@jpoehnelt jpoehnelt merged commit 08716f8 into googleworkspace:main Mar 9, 2026
27 checks passed
@codecov
Copy link

codecov bot commented Mar 9, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 59.36%. Comparing base (643fb7a) to head (fb5b675).
⚠️ Report is 8 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #322      +/-   ##
==========================================
+ Coverage   59.25%   59.36%   +0.11%     
==========================================
  Files          36       36              
  Lines       12993    13046      +53     
==========================================
+ Hits         7699     7745      +46     
- Misses       5294     5301       +7     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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.

docs: clarify --params/fields usage and RFC 2047 subject encoding for gmail drafts raw

3 participants