Skip to content

fix(gmail): bring +forward behavior in line with Gmail web UI#353

Merged
jpoehnelt merged 1 commit intogoogleworkspace:mainfrom
malob:fix/gmail-forward-threading
Mar 9, 2026
Merged

fix(gmail): bring +forward behavior in line with Gmail web UI#353
jpoehnelt merged 1 commit intogoogleworkspace:mainfrom
malob:fix/gmail-forward-threading

Conversation

@malob
Copy link
Contributor

@malob malob commented Mar 9, 2026

Description

The +forward helper (added in #105) sends forwards as new threads, which doesn't match Gmail's web UI behavior. When you forward from Gmail, the forward stays in the sender's original conversation thread. This PR fixes that and cleans up the forwarded message formatting.

Threading fix:

  • Pass the original threadId to send_raw_email (matching what +reply already does)
  • Add In-Reply-To and References headers for RFC 5322 compliance — required by the Gmail API for thread placement alongside threadId

Formatting fixes:

  • Add blank line between the forwarded message metadata block and body (was missing, causing the body to run into the To:/Cc: line)
  • Remove spurious closing ---------- delimiter that Gmail doesn't produce

SKILL.md:

  • Remove tip that said forwards are sent as new messages

Related: #88

Dry Run Output:

$ gws gmail +forward --message-id 18f1a2b3c4d --to dave@example.com --body 'FYI see below' --dry-run
{
  "body": {
    "raw": "VG86IGRhdmVAZXhhbXBsZS5jb20NClN1YmplY3Q6...<truncated>",
    "threadId": "thread-18f1a2b3c4d"
  },
  "dry_run": true,
  "is_multipart_upload": false,
  "method": "POST",
  "query_params": {},
  "url": "https://gmail.googleapis.com/gmail/v1/users/me/messages/send"
}

Decoded raw (base64 → plaintext):

To: dave@example.com
Subject: Fwd: Original subject
In-Reply-To: <18f1a2b3c4d@example.com>
References: <18f1a2b3c4d@example.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8

FYI see below

---------- Forwarded message ---------
From: sender@example.com
Date: Thu, 1 Jan 2026 00:00:00 +0000
Subject: Original subject
To: you@example.com

Original message body

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.

- Pass original threadId to keep forward in sender's thread
- Add In-Reply-To and References headers for RFC 5322 compliance
- Add blank line between forwarded message metadata and body
- Remove spurious closing delimiter from forwarded message block
- Update SKILL.md to remove outdated threading tip
- Add test for References chain construction

Closes googleworkspace#88
@changeset-bot
Copy link

changeset-bot bot commented Mar 9, 2026

🦋 Changeset detected

Latest commit: 11e3901

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 area: skills area: core Core CLI parsing, commands, error handling, utilities labels Mar 9, 2026
@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.

@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 refines the +forward command to mirror Gmail's native forwarding behavior. The primary goal is to ensure that forwarded emails remain within their original conversation threads and are formatted consistently with the web UI, enhancing user experience and message organization.

Highlights

  • Threading Alignment: The +forward functionality now aligns with Gmail's web UI by keeping forwarded messages within the sender's original conversation thread, rather than creating new ones.
  • RFC 5322 Compliance: Implemented In-Reply-To and References headers in forwarded emails, which are crucial for correct thread placement by the Gmail API.
  • Formatting Improvements: Cleaned up forwarded message formatting by adding a blank line between the forwarded message metadata block and its body, and by removing a spurious closing delimiter.
  • Documentation Update: Updated the SKILL.md documentation to remove an outdated tip regarding forwards being sent as new messages.
Changelog
  • .changeset/fix-forward-threading.md
    • Added a new changeset file documenting the +forward behavior fix.
  • skills/gws-gmail-forward/SKILL.md
    • Removed the tip indicating that forwards are sent as new messages, reflecting the updated behavior.
  • src/helpers/gmail/forward.rs
    • Modified handle_forward to pass the original message's threadId to send_raw_email.
    • Updated create_forward_raw_message to include In-Reply-To and References headers for RFC 5322 compliance, ensuring proper threading.
    • Adjusted format_forwarded_message to add a blank line between the forwarded message metadata and its body.
    • Removed the unnecessary closing ---------- delimiter from forwarded messages.
    • Expanded test cases to verify the presence of new headers and the corrected formatting, including a new test for References header chaining.
Activity
  • No human activity has been recorded on 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

The pull request updates the Gmail +forward functionality to align with Gmail's web UI by ensuring forwarded messages remain in the original thread, adding a blank line between the forwarded message metadata and body, and removing the closing delimiter. However, a security vulnerability was identified in the create_forward_raw_message function, where unsanitized user inputs and message metadata are directly used in email headers, leading to potential Email Header Injection and an invalid MIME-Version header due to incorrect formatting.

@jpoehnelt jpoehnelt merged commit 5e7d120 into googleworkspace:main Mar 9, 2026
38 of 40 checks passed
@malob malob deleted the fix/gmail-forward-threading branch March 9, 2026 23:47
@codecov
Copy link

codecov bot commented Mar 10, 2026

Codecov Report

❌ Patch coverage is 79.48718% with 8 lines in your changes missing coverage. Please review.
✅ Project coverage is 61.77%. Comparing base (cfa0984) to head (11e3901).
⚠️ Report is 4 commits behind head on main.

Files with missing lines Patch % Lines
src/helpers/gmail/forward.rs 79.48% 8 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #353      +/-   ##
==========================================
+ Coverage   61.72%   61.77%   +0.04%     
==========================================
  Files          38       38              
  Lines       14603    14640      +37     
==========================================
+ Hits         9014     9044      +30     
- Misses       5589     5596       +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 area: skills

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants