From 522f3e257f9181f899f74e1f4cc77f7c56ebebdb Mon Sep 17 00:00:00 2001 From: Yassir Barchi Date: Wed, 27 Mar 2024 17:33:20 +0100 Subject: [PATCH 1/2] fix(headers): avoid double spaces in the headers it fixes https://github.com/lettre/lettre/issues/949 --- src/headers/writer.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/headers/writer.rs b/src/headers/writer.rs index 7d69504..0da376e 100644 --- a/src/headers/writer.rs +++ b/src/headers/writer.rs @@ -55,6 +55,7 @@ impl<'a> EmailWriter<'a> { /// Equivalent to calling `new_line()` and `space()` consecutively. pub(crate) fn new_line_and_space(&mut self) -> fmt::Result { + self.spaces = 0; self.writer.write_str("\r\n ")?; self.line_len = 1; self.optional_breakpoint = false; From d2122252f5b7540d2230839e715397056ff01cc1 Mon Sep 17 00:00:00 2001 From: Yassir Barchi Date: Wed, 27 Mar 2024 19:03:08 +0100 Subject: [PATCH 2/2] test: add a regression test --- src/headers/writer.rs | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/headers/writer.rs b/src/headers/writer.rs index 0da376e..a36e6ab 100644 --- a/src/headers/writer.rs +++ b/src/headers/writer.rs @@ -351,4 +351,24 @@ mod tests { ) ); } + + #[test] + fn double_spaces_issue_949() { + let mut s = "Subject: AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA ".to_string(); + let line_len = s.len(); + + { + let mut w = EmailWriter::new(&mut s, line_len, 0, false, true); + w.folding().write_str("BBBBBBBBBBBBB ").unwrap(); + crate::headers::rfc2047::encode("sélection", &mut w).unwrap(); + } + + assert_eq!( + s, + concat!( + "Subject: AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA BBBBBBBBBBBBB\r\n", + " =?utf-8?b?c8OpbGVjdGlvbg==?=", + ) + ); + } }