diff --git a/src/dc_receive_imf.rs b/src/dc_receive_imf.rs index 16ddba483..b4cb083f3 100644 --- a/src/dc_receive_imf.rs +++ b/src/dc_receive_imf.rs @@ -1623,6 +1623,7 @@ fn dc_create_incoming_rfc724_mid( #[cfg(test)] mod tests { use super::*; + use crate::message::Message; use crate::test_utils::dummy_context; #[test] @@ -1682,4 +1683,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, "unexistant@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, "unexistant@message.id")); + } }