diff --git a/src/headers/writer.rs b/src/headers/writer.rs index 7d69504..a36e6ab 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; @@ -350,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==?=", + ) + ); + } }