Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/gmail-header-case.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@googleworkspace/cli": patch
---

Match Gmail message header names case-insensitively, so `CC` from Exchange/Outlook senders is no longer dropped by `gmail +reply-all` and `gmail +read`
65 changes: 56 additions & 9 deletions crates/google-workspace-cli/src/helpers/gmail/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -258,15 +258,18 @@ fn parse_message_headers(headers: &[Value]) -> ParsedMessageHeaders {
let name = header.get("name").and_then(|v| v.as_str()).unwrap_or("");
let value = header.get("value").and_then(|v| v.as_str()).unwrap_or("");

match name {
"From" => parsed.from = value.to_string(),
"Reply-To" => append_address_list_header_value(&mut parsed.reply_to, value),
"To" => append_address_list_header_value(&mut parsed.to, value),
"Cc" => append_address_list_header_value(&mut parsed.cc, value),
"Subject" => parsed.subject = value.to_string(),
"Date" => parsed.date = value.to_string(),
"Message-ID" | "Message-Id" => parsed.message_id = value.to_string(),
"References" => append_header_value(&mut parsed.references, value),
// Header names are case-insensitive, and the API hands through whatever casing
// the sending MTA used. Exchange/Outlook emit "CC"/"MESSAGE-ID", which used to
// fall through the match below and get dropped.
match name.to_ascii_lowercase().as_str() {
"from" => parsed.from = value.to_string(),
"reply-to" => append_address_list_header_value(&mut parsed.reply_to, value),
"to" => append_address_list_header_value(&mut parsed.to, value),
"cc" => append_address_list_header_value(&mut parsed.cc, value),
"subject" => parsed.subject = value.to_string(),
"date" => parsed.date = value.to_string(),
"message-id" => parsed.message_id = value.to_string(),
"references" => append_header_value(&mut parsed.references, value),
_ => {}
}
}
Expand Down Expand Up @@ -2427,6 +2430,50 @@ mod tests {
assert_eq!(original.body_html.as_deref(), Some("<p>HTML only</p>"));
}

#[test]
fn test_parse_original_message_accepts_non_canonical_header_casing() {
// Exchange/Outlook style casing: the old case-sensitive match dropped CC and
// blew up on the missing From header.
let msg = json!({
"threadId": "thread-789",
"snippet": "",
"payload": {
"mimeType": "text/plain",
"headers": [
{ "name": "FROM", "value": "alice@example.com" },
{ "name": "TO", "value": "bob@example.com" },
{ "name": "cc", "value": "carol@example.com" },
{ "name": "CC", "value": "dave@example.com" },
{ "name": "Subject", "value": "Hello" },
{ "name": "DATE", "value": "Fri, 6 Mar 2026 12:00:00 +0000" },
{ "name": "message-id", "value": "<msg@example.com>" },
{ "name": "REPLY-TO", "value": "team@example.com" },
{ "name": "references", "value": "<ref-1@example.com>" }
],
"body": {
"data": URL_SAFE.encode("hi")
}
}
});

let original = parse_original_message(&msg).unwrap();

assert_eq!(original.from.email, "alice@example.com");
assert_eq!(original.to.len(), 1);
assert_eq!(original.to[0].email, "bob@example.com");
let cc = original.cc.unwrap();
assert_eq!(cc.len(), 2);
assert_eq!(cc[0].email, "carol@example.com");
assert_eq!(cc[1].email, "dave@example.com");
assert_eq!(original.reply_to.unwrap()[0].email, "team@example.com");
assert_eq!(original.message_id, "msg@example.com");
assert_eq!(original.references, vec!["ref-1@example.com"]);
assert_eq!(
original.date.as_deref(),
Some("Fri, 6 Mar 2026 12:00:00 +0000")
);
}

#[test]
fn test_parse_original_message_multipart_alternative() {
let msg = json!({
Expand Down
Loading