Skip to content

fix(gmail): match message header names case-insensitively (#642)#847

Open
shigechika wants to merge 1 commit into
googleworkspace:mainfrom
shigechika:fix/gmail-header-case-insensitive
Open

fix(gmail): match message header names case-insensitively (#642)#847
shigechika wants to merge 1 commit into
googleworkspace:mainfrom
shigechika:fix/gmail-header-case-insensitive

Conversation

@shigechika

Copy link
Copy Markdown

Summary

Fixes #642.

parse_message_headers matched header field names with exact case:

match name {
    "From" => ...
    "Cc" => ...
    ...
}

Gmail preserves the sender's original header casing, so a message whose Cc
header arrives as "CC" (very common from Exchange/Outlook) — or "from"
lowercase from some MTAs — falls through the match and is silently dropped.
In practice this drops all CC recipients from gws gmail +reply-all.

Per RFC 5322 §1.2.2 header field names are case-insensitive. The sibling get_part_header already uses eq_ignore_ascii_case, so this just brings parse_message_headers in line.

Fix

Normalize the name to lowercase before matching:

match name.to_ascii_lowercase().as_str() {
    "from" => ...
    "cc" => ...
    ...
}

(The previous "Message-ID" | "Message-Id" arm collapses to a single
"message-id".)

Test

Adds test_parse_message_headers_case_insensitive, covering mixed-case
FROM / to / CC / Reply-TO / subject / MESSAGE-ID / References.

cargo build clean; cargo test helpers::gmail green (235 passed).

🤖 Generated with Claude Code

parse_message_headers used exact-case string matching, so headers whose field
names use non-canonical casing -- e.g. "CC" (common from Exchange/Outlook) or a
lowercase "from" from some MTAs -- fell through and were silently dropped. This
dropped CC recipients from +reply-all.

Per RFC 5322 1.2.2 header field names are case-insensitive, and the sibling
get_part_header already uses eq_ignore_ascii_case. Normalize the name to
lowercase before matching, and add a regression test covering mixed-case
FROM/to/CC/Reply-TO/subject/MESSAGE-ID/References.

Fixes googleworkspace#642.

Claude-Session: https://claude.ai/code/session_01EuRYoXhx7ozQWx19mAFLUS
@changeset-bot

changeset-bot Bot commented Jun 18, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 78e0ae1

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

@gemini-code-assist

Copy link
Copy Markdown
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 Gmail message headers were being silently ignored if their casing did not match the hardcoded strings in the parser. By normalizing header names to lowercase, the system now correctly handles various casing formats often produced by different MTAs and email clients like Outlook, ensuring that critical fields like CC are preserved during operations such as reply-all.

Highlights

  • Case-Insensitive Header Matching: Updated the parse_message_headers function to normalize header names to lowercase before matching, ensuring compliance with RFC 5322 and preventing headers from being silently dropped due to casing variations.
  • Regression Testing: Added a new test case test_parse_message_headers_case_insensitive to verify that mixed-case header names are correctly parsed.
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 the 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 counterproductive. 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.

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 the area: core Core CLI parsing, commands, error handling, utilities label Jun 18, 2026

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

Copy link
Copy Markdown
Contributor

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 fixes an issue where Gmail message headers were matched case-sensitively, causing headers with non-canonical casing (like "CC" or lowercase "from") to be silently dropped. The matching logic in parse_message_headers has been updated to normalize header names to lowercase before matching, and a corresponding unit test has been added to verify case-insensitive parsing. There are no review comments, so I have no feedback to provide.

@lucaspretti

Copy link
Copy Markdown

Hey @shigechika, thanks for picking this up. I submitted the same fix in #846 (a re-submission of #841), but the stale bot closed both before a maintainer could take a look.

Since the diff here is essentially identical, two small things from my version might be worth folding in:

  • a regression test (test_parse_original_message_case_insensitive_headers) that feeds Exchange-style casing (FROM, TO, CC, cc, message-id) and asserts no recipient or the message id gets dropped;
  • the old "Message-ID" | "Message-Id" arm collapsed into a single "message-id" case.

No ownership concerns on my end, just flagging so whichever PR lands keeps the test coverage. Glad to see this getting fixed either way.

@shigechika

Copy link
Copy Markdown
Author

Thanks @lucaspretti — sorry the stale bot got both of yours. Good news: both points you raised are already covered here:

  • the old "Message-ID" | "Message-Id" arm is collapsed into a single "message-id" case;
  • test_parse_message_headers_case_insensitive feeds mixed Exchange-style casing (FROM/to/CC/Reply-TO/MESSAGE-ID/References) and asserts none of them are dropped.

Genuinely happy for whichever PR lands — the important thing is that #642 gets fixed. Thanks for flagging the test coverage either way.

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.

bug(gmail): parse_message_headers uses case-sensitive match, drops CC/headers with non-canonical casing

4 participants