bug(gmail): parse_message_headers uses case-sensitive match, drops CC/headers with non-canonical casing
Description
gws gmail +reply-all silently drops CC recipients when the original message's Cc header is stored with non-canonical casing (e.g., "CC" instead of "Cc").
Reproduction
- Have a Gmail thread where the latest message has CC recipients and the header name is
"CC"(all uppercase — common with Microsoft Exchange / Outlook) - Run:
gws gmail +reply-all --message-id <ID> --body 'test' --draft - Expected: Draft includes all original To + CC recipients
- Actual: Draft only includes To recipients + original sender. All CC recipients are silently dropped.
Root Cause
parse_message_headers in crates/google-workspace-cli/src/helpers/gmail/mod.rs (line 254) uses exact case-sensitive string matching:
match name {
"From" => ...
"Reply-To" => ...
"To" => ...
"Cc" => ... // ← only matches "Cc"
"Message-ID" | "Message-Id" => ... // ← already handles 2 variants
_ => {} // ← "CC" falls through silently
}
The Gmail API preserves original header casing from the sending MTA. Per RFC 5322 §1.2.2, header field names are case-insensitive, so "CC", "Cc", and "cc" are all valid.
Scope
This affects all headers in the match block, not just Cc. If any header arrives in non-canonical casing:
| Header | Impact if missed |
|---|---|
From |
Hard error — function returns Err("Message is missing From header") |
Message-ID |
Hard error — Err("Message is missing Message-ID header") |
To |
+reply-all misses To recipients |
CC |
+reply-all drops CC recipients (this bug) |
Reply-To |
Reply goes to wrong recipient |
References |
Threading breaks |
Internal Inconsistency
The same file already uses case-insensitive matching in get_part_header:
fn get_part_header<'a>(part: &'a Value, name: &str) -> Option<&'a str> {
...
.find(|h| n.eq_ignore_ascii_case(name)) // ← correct approach
...
}
Suggested Fix
Normalize name before matching:
match name.to_ascii_lowercase().as_str() {
"from" => ...
"reply-to" => ...
"to" => ...
"cc" => ...
"subject" => ...
"date" => ...
"message-id" => ...
"references" => ...
_ => {}
}
This aligns with the existing get_part_header pattern and the extract_header function (which also uses eq_ignore_ascii_case).
Related
- #569 — CC header ordering issue (different bug, fixed)
- PR #105 — Original
+reply-allimplementation - PR #634 (open) — Widens
parse_message_headerstopub(super)for reuse; this bug would propagate
Environment
- gws 0.22.3
- macOS (arm64)
- Original message sent from Microsoft Exchange (which emits
"CC"in uppercase)
Just ran into this exact bug in production. Used gws gmail +read to read a message from a Microsoft Exchange sender — the cc field came back as null despite three CC recipients being clearly visible in the Gmail web UI.
As a result, a reply sent via gws gmail +reply only went to the original sender, silently dropping all CC'd recipients. Had to send a follow-up FYI to loop everyone back in.
This is a real problem for anyone using gws as part of an automated or AI-assisted email workflow — there's no way to detect that CC recipients are missing, so replies silently exclude people from the conversation.
The suggested fix (case-insensitive matching) looks straightforward. Would love to see this prioritised — it's a data-loss-level bug that silently changes who receives replies.
(Closing #756 as a duplicate of this issue.)
Still reproduces on 0.22.5 (latest, Homebrew on macOS). Confirming with another real-world Microsoft Exchange / Outlook sender:
- Original message (from an Exchange MTA):
To: [email protected],Cc: [email protected], [email protected], <my own account>. gws gmail +reply-all --message-id <id> --body '…' --draftproduced a draft withTo: <original sender>andCc: [email protected]only — the originalTosurvived but the entire originalCc(b, c) was silently dropped. My own account was correctly removed as self.
Inspecting the draft headers (gws gmail users drafts get … format=metadata) before sending caught it; the workaround is to re-add the dropped addresses via --cc explicitly. This matches the root-cause analysis above: Exchange emits the header as CC, which the case-sensitive match misses. A case-insensitive comparison (eq_ignore_ascii_case) on the header name would fix it. Thanks for the detailed write-up.
Saw #923 got closed without a merge. I had the same casing problem in my own Gmail library until today, so here's a stopgap. It uses your gws login and only prints the headers unless you add --send:
gws auth export --unmasked > google.json
GOOGLE_TOKEN_FILE=google.json uv run https://raw.githubusercontent.com/r28ai/charter-recipes/main/gmail/reply_all.py <message-id>
(It runs on Charter, which I maintain.)