diff --git a/src/contact.rs b/src/contact.rs index 6db5a0943..93c9d3f4e 100644 --- a/src/contact.rs +++ b/src/contact.rs @@ -1107,7 +1107,7 @@ pub fn normalize_name(full_name: impl AsRef) -> String { } let len = full_name.len(); - if len > 0 { + if len > 1 { let firstchar = full_name.as_bytes()[0]; let lastchar = full_name.as_bytes()[len - 1]; if firstchar == b'\'' && lastchar == b'\'' @@ -1216,6 +1216,10 @@ mod tests { fn test_normalize_name() { assert_eq!(&normalize_name("Doe, John"), "John Doe"); assert_eq!(&normalize_name(" hello world "), "hello world"); + assert_eq!(&normalize_name("<"), "<"); + assert_eq!(&normalize_name(">"), ">"); + assert_eq!(&normalize_name("'"), "'"); + assert_eq!(&normalize_name("\""), "\""); } #[test] diff --git a/src/dc_receive_imf.rs b/src/dc_receive_imf.rs index 36c5f6972..01590ef1b 100644 --- a/src/dc_receive_imf.rs +++ b/src/dc_receive_imf.rs @@ -1573,6 +1573,8 @@ async fn is_known_rfc724_mid_in_list(context: &Context, mid_list: &str) -> bool /// Check if a message is a reply to a known message (messenger or non-messenger). async fn is_known_rfc724_mid(context: &Context, rfc724_mid: &str) -> bool { + let rfc724_mid = rfc724_mid.trim_start_matches('<').trim_end_matches('>'); + context .sql .exists( @@ -1620,6 +1622,8 @@ pub(crate) async fn is_msgrmsg_rfc724_mid_in_list(context: &Context, mid_list: & /// Check if a message is a reply to any messenger message. async fn is_msgrmsg_rfc724_mid(context: &Context, rfc724_mid: &str) -> bool { + let rfc724_mid = rfc724_mid.trim_start_matches('<').trim_end_matches('>'); + context .sql .exists( @@ -1711,6 +1715,7 @@ fn dc_create_incoming_rfc724_mid( #[cfg(test)] mod tests { use super::*; + use crate::message::Message; use crate::test_utils::dummy_context; #[test] @@ -1774,4 +1779,38 @@ mod tests { Some("123-45-9@stub".into()) ); } + + #[test] + fn test_is_known_rfc724_mid() { + let t = dummy_context(); + let mut msg = Message::new(Viewtype::Text); + msg.text = Some("first message".to_string()); + let msg_id = chat::add_device_msg(&t.ctx, None, Some(&mut msg)).unwrap(); + let msg = Message::load_from_db(&t.ctx, msg_id).unwrap(); + + // Message-IDs may or may not be surrounded by angle brackets + assert!(is_known_rfc724_mid( + &t.ctx, + format!("<{}>", msg.rfc724_mid).as_str() + )); + assert!(is_known_rfc724_mid(&t.ctx, &msg.rfc724_mid)); + assert!(!is_known_rfc724_mid(&t.ctx, "nonexistant@message.id")); + } + + #[test] + fn test_is_msgrmsg_rfc724_mid() { + let t = dummy_context(); + let mut msg = Message::new(Viewtype::Text); + msg.text = Some("first message".to_string()); + let msg_id = chat::add_device_msg(&t.ctx, None, Some(&mut msg)).unwrap(); + let msg = Message::load_from_db(&t.ctx, msg_id).unwrap(); + + // Message-IDs may or may not be surrounded by angle brackets + assert!(is_msgrmsg_rfc724_mid( + &t.ctx, + format!("<{}>", msg.rfc724_mid).as_str() + )); + assert!(is_msgrmsg_rfc724_mid(&t.ctx, &msg.rfc724_mid)); + assert!(!is_msgrmsg_rfc724_mid(&t.ctx, "nonexistant@message.id")); + } }