Skip to content
Merged
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/rfc2822-display-name-quoting.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@googleworkspace/cli": patch
---

test(gmail): add regression tests for RFC 2822 display name quoting
35 changes: 35 additions & 0 deletions src/helpers/gmail/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2675,6 +2675,41 @@ mod tests {
assert_eq!(named.to_string(), "Alice <alice@example.com>");
}

/// Regression test for PR #513: display names with RFC 2822 special characters
/// (commas, parens, colons, etc.) must be properly quoted in the To: header
/// so Gmail does not reject them with "Invalid To header".
#[test]
fn test_rfc2822_display_name_quoting_via_mail_builder() {
let test_cases = [
("Anderson, Rich (CORP)", "rich@example.com", "comma/parens"),
("Dr. Smith: Chief", "smith@example.com", "colon"),
("O'Brien & Co.", "ob@example.com", "dot/ampersand"),
];

for (name, email, description) in test_cases {
let m = Mailbox {
name: Some(name.to_string()),
email: email.to_string(),
};
let raw = mail_builder::MessageBuilder::new()
.to(to_mb_address(&m))
.subject("test")
.text_body("body")
.write_to_string()
.unwrap();
let to_line = raw
.lines()
.find(|l| l.starts_with("To:"))
.unwrap_or_else(|| panic!("No To: header for case: {description}"));

let quoted = format!("\"{name}\"");
assert!(
to_line.contains(&quoted) || to_line.contains("=?utf-8?"),
"Display name with {description} must be quoted: {to_line}"
);
}
Comment thread
jpoehnelt marked this conversation as resolved.
}
Comment thread
jpoehnelt marked this conversation as resolved.

#[test]
fn test_strip_angle_brackets() {
assert_eq!(strip_angle_brackets("<abc@example.com>"), "abc@example.com");
Expand Down
Loading