From 18197126670c189805e0e3ae1892de17617b9f47 Mon Sep 17 00:00:00 2001 From: holger krekel Date: Tue, 10 Dec 2019 18:51:54 +0100 Subject: [PATCH] make sure we send out <> around message-id's in references and in-reply-to --- src/mimefactory.rs | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/src/mimefactory.rs b/src/mimefactory.rs index 71ef17522..65956e841 100644 --- a/src/mimefactory.rs +++ b/src/mimefactory.rs @@ -152,7 +152,10 @@ impl<'a, 'b> MimeFactory<'a, 'b> { let in_reply_to: String = row.get(0)?; let references: String = row.get(1)?; - Ok((in_reply_to, references)) + Ok(( + render_rfc724_mid_list(&in_reply_to), + render_rfc724_mid_list(&references), + )) }, ); @@ -1045,12 +1048,21 @@ fn render_rfc724_mid(rfc724_mid: &str) -> String { let rfc724_mid = rfc724_mid.trim().to_string(); if rfc724_mid.chars().nth(0).unwrap_or_default() == '<' { - rfc724_mid.to_string() + rfc724_mid } else { - format!("<{}>", rfc724_mid).to_string() + format!("<{}>", rfc724_mid) } } +fn render_rfc724_mid_list(mid_list: &str) -> String { + mid_list + .trim() + .split_ascii_whitespace() + .map(render_rfc724_mid) + .collect::>() + .join(" ") +} + /* ****************************************************************************** * Encode/decode header words, RFC 2047 ******************************************************************************/ @@ -1107,4 +1119,14 @@ mod tests { "".to_string() ); } + + #[test] + fn test_render_rc724_mid_list() { + assert_eq!(render_rfc724_mid_list("123@q "), "<123@q>".to_string()); + assert_eq!(render_rfc724_mid_list(" 123@q "), "<123@q>".to_string()); + assert_eq!( + render_rfc724_mid_list("123@q 456@d "), + "<123@q> <456@d>".to_string() + ); + } }