mime-modified set; simplify is always regarded as lossy.
"## ); } #[async_std::test] async fn test_htmlparse_alt_html() { let t = TestContext::new().await; let raw = include_bytes!("../test-data/message/text_alt_html.eml"); let parser = HtmlMsgParser::from_bytes(&t.ctx, raw).await.unwrap(); assert_eq!( parser.html.replace("\r", ""), // see comment in test_htmlparse_html() r##"mime-modified set; simplify is always regarded as lossy.
"## ); } #[async_std::test] async fn test_htmlparse_alt_plain_html() { let t = TestContext::new().await; let raw = include_bytes!("../test-data/message/text_alt_plain_html.eml"); let parser = HtmlMsgParser::from_bytes(&t.ctx, raw).await.unwrap(); assert_eq!( parser.html.replace("\r", ""), // see comment in test_htmlparse_html() r##"this is html
"## ); } #[async_std::test] async fn test_htmlparse_apple_cid_jpg() { // load raw mime html-data with related image-part (cid:) // and make sure, Content-Id has angle-brackets that are removed correctly. let t = TestContext::new().await; let raw = include_bytes!("../test-data/message/apple_cid_jpg.eml"); let test = String::from_utf8_lossy(raw); assert!(test .find("Content-Id: <8AE052EF-BC90-486F-BB78-58D3590308EC@fritz.box>") .is_some()); assert!(test .find("cid:8AE052EF-BC90-486F-BB78-58D3590308EC@fritz.box") .is_some()); assert!(test.find("data:").is_none()); // parsing converts cid: to data: let parser = HtmlMsgParser::from_bytes(&t.ctx, raw).await.unwrap(); assert!(parser.html.find("").is_some()); assert!(parser.html.find("Content-Id:").is_none()); assert!(parser .html .find("data:image/jpeg;base64,/9j/4AAQ") .is_some()); assert!(parser.html.find("cid:").is_none()); } #[async_std::test] async fn test_get_html_empty() { let t = TestContext::new().await; let msg_id = MsgId::new_unset(); assert!(msg_id.get_html(&t).await.is_none()) } #[async_std::test] async fn test_html_forwarding() { // alice receives a non-delta html-message let alice = TestContext::new_alice().await; alice.set_config(Config::ShowEmails, Some("2")).await.ok(); let chat = alice .create_chat_with_contact("", "sender@testrun.org") .await; let raw = include_bytes!("../test-data/message/text_alt_plain_html.eml"); dc_receive_imf(&alice, raw, "INBOX", 1, false) .await .unwrap(); let msg = alice.get_last_msg_in(chat.get_id()).await; assert_ne!(msg.get_from_id(), DC_CONTACT_ID_SELF); assert_eq!(msg.is_dc_message, MessengerMessage::No); assert!(!msg.is_forwarded()); assert!(msg.get_text().unwrap().find("this is plain").is_some()); assert!(msg.has_html()); let html = msg.get_id().get_html(&alice).await.unwrap(); assert!(html.find("this is html").is_some()); // alice: create chat with bob and forward received html-message there let chat = alice.create_chat_with_contact("", "bob@example.net").await; forward_msgs(&alice, &[msg.get_id()], chat.get_id()) .await .unwrap(); let msg = alice.get_last_msg_in(chat.get_id()).await; assert_eq!(msg.get_from_id(), DC_CONTACT_ID_SELF); assert_eq!(msg.is_dc_message, MessengerMessage::Yes); assert!(msg.is_forwarded()); assert!(msg.get_text().unwrap().find("this is plain").is_some()); assert!(msg.has_html()); let html = msg.get_id().get_html(&alice).await.unwrap(); assert!(html.find("this is html").is_some()); // bob: check that bob also got the html-part of the forwarded message let bob = TestContext::new_bob().await; let chat = bob.create_chat_with_contact("", "alice@example.com").await; bob.recv_msg(&alice.pop_sent_msg().await).await; let msg = bob.get_last_msg_in(chat.get_id()).await; assert_ne!(msg.get_from_id(), DC_CONTACT_ID_SELF); assert_eq!(msg.is_dc_message, MessengerMessage::Yes); assert!(msg.is_forwarded()); assert!(msg.get_text().unwrap().find("this is plain").is_some()); assert!(msg.has_html()); let html = msg.get_id().get_html(&bob).await.unwrap(); assert!(html.find("this is html").is_some()); } #[async_std::test] async fn test_html_forwarding_encrypted() { // Alice receives a non-delta html-message // (`ShowEmails=1` lets Alice actually receive non-delta messages for known contacts, // the contact is marked as known by creating a chat using `chat_with_contact()`) let alice = TestContext::new_alice().await; alice.set_config(Config::ShowEmails, Some("1")).await.ok(); let chat = alice .create_chat_with_contact("", "sender@testrun.org") .await; let raw = include_bytes!("../test-data/message/text_alt_plain_html.eml"); dc_receive_imf(&alice, raw, "INBOX", 1, false) .await .unwrap(); let msg = alice.get_last_msg_in(chat.get_id()).await; // forward the message to saved-messages, // this will encrypt the message as new_alice() has set up keys let chat = alice.get_self_chat().await; forward_msgs(&alice, &[msg.get_id()], chat.get_id()) .await .unwrap(); let msg = alice.pop_sent_msg().await; // receive the message on another device let alice = TestContext::new_alice().await; assert_eq!(alice.get_config_int(Config::ShowEmails).await, 0); // set to "1" above, make sure it is another db alice.recv_msg(&msg).await; let chat = alice.get_self_chat().await; let msg = alice.get_last_msg_in(chat.get_id()).await; assert_eq!(msg.get_from_id(), DC_CONTACT_ID_SELF); assert_eq!(msg.is_dc_message, MessengerMessage::Yes); assert!(msg.get_showpadlock()); assert!(msg.is_forwarded()); assert!(msg.get_text().unwrap().find("this is plain").is_some()); assert!(msg.has_html()); let html = msg.get_id().get_html(&alice).await.unwrap(); assert!(html.find("this is html").is_some()); } #[async_std::test] async fn test_set_html() { let alice = TestContext::new_alice().await; let bob = TestContext::new_bob().await; // alice sends a message with html-part to bob let chat_id = alice.create_chat(&bob).await.id; let mut msg = Message::new(Viewtype::Text); msg.set_text(Some("plain text".to_string())); msg.set_html(Some("html text".to_string())); assert!(msg.mime_modified); chat::send_msg(&alice, chat_id, &mut msg).await.unwrap(); // check the message is written correctly to alice's db let msg = alice.get_last_msg_in(chat_id).await; assert_eq!(msg.get_text(), Some("plain text".to_string())); assert!(!msg.is_forwarded()); assert!(msg.mime_modified); let html = msg.get_id().get_html(&alice).await.unwrap(); assert!(html.find("html text").is_some()); // let bob receive the message let chat_id = bob.create_chat(&alice).await.id; bob.recv_msg(&alice.pop_sent_msg().await).await; let msg = bob.get_last_msg_in(chat_id).await; assert_eq!(msg.get_text(), Some("plain text".to_string())); assert!(!msg.is_forwarded()); assert!(msg.mime_modified); let html = msg.get_id().get_html(&bob).await.unwrap(); assert!(html.find("html text").is_some()); } }