Skip to content

Commit 4928d9b

Browse files
committed
fix(gmail): RFC 2047 encode draft address headers
1 parent 4b827cd commit 4928d9b

File tree

2 files changed

+38
-3
lines changed

2 files changed

+38
-3
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@googleworkspace/cli": patch
3+
---
4+
5+
fix(gmail): RFC 2047 encode non-ASCII draft From/Cc/Bcc headers

src/helpers/gmail/mod.rs

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -506,17 +506,26 @@ impl MessageBuilder<'_> {
506506
));
507507

508508
if let Some(from) = self.from {
509-
headers.push_str(&format!("\r\nFrom: {}", sanitize_header_value(from)));
509+
headers.push_str(&format!(
510+
"\r\nFrom: {}",
511+
encode_header_value(&sanitize_header_value(from))
512+
));
510513
}
511514

512515
if let Some(cc) = self.cc {
513-
headers.push_str(&format!("\r\nCc: {}", sanitize_header_value(cc)));
516+
headers.push_str(&format!(
517+
"\r\nCc: {}",
518+
encode_header_value(&sanitize_header_value(cc))
519+
));
514520
}
515521

516522
// The Gmail API reads the Bcc header to route to those recipients,
517523
// then strips it before delivery.
518524
if let Some(bcc) = self.bcc {
519-
headers.push_str(&format!("\r\nBcc: {}", sanitize_header_value(bcc)));
525+
headers.push_str(&format!(
526+
"\r\nBcc: {}",
527+
encode_header_value(&sanitize_header_value(bcc))
528+
));
520529
}
521530

522531
format!("{}\r\n\r\n{}", headers, body)
@@ -1316,6 +1325,27 @@ mod tests {
13161325
assert!(!raw.contains("Solar — Quote Request"));
13171326
}
13181327

1328+
#[test]
1329+
fn test_message_builder_encodes_non_ascii_optional_headers() {
1330+
let raw = MessageBuilder {
1331+
1332+
subject: "Hello",
1333+
from: Some("\"日本語名前\" <[email protected]>"),
1334+
cc: Some("\"日本語名前\" <[email protected]>"),
1335+
bcc: Some("\"日本語名前\" <[email protected]>"),
1336+
threading: None,
1337+
html: false,
1338+
}
1339+
.build("Body");
1340+
1341+
assert!(raw.contains("From: =?UTF-8?B?"));
1342+
assert!(raw.contains("Cc: =?UTF-8?B?"));
1343+
assert!(raw.contains("Bcc: =?UTF-8?B?"));
1344+
assert!(!raw.contains("From: \"日本語名前\" <[email protected]>"));
1345+
assert!(!raw.contains("Cc: \"日本語名前\" <[email protected]>"));
1346+
assert!(!raw.contains("Bcc: \"日本語名前\" <[email protected]>"));
1347+
}
1348+
13191349
#[test]
13201350
fn test_message_builder_sanitizes_crlf_injection() {
13211351
let raw = MessageBuilder {

0 commit comments

Comments
 (0)