diff --git a/src/chat.rs b/src/chat.rs index b168dafeb..97a435d7e 100644 --- a/src/chat.rs +++ b/src/chat.rs @@ -2092,28 +2092,31 @@ impl Chat { EphemeralTimer::Enabled { duration } => time().saturating_add(duration.into()), }; + let (msg_text, was_truncated) = truncate_msg_text(context, msg.text.clone()).await?; let new_mime_headers = if msg.has_html() { - let html = if msg.param.exists(Param::Forwarded) { + if msg.param.exists(Param::Forwarded) { msg.get_id().get_html(context).await? } else { msg.param.get(Param::SendHtml).map(|s| s.to_string()) - }; - match html { - Some(html) => Some(tokio::task::block_in_place(move || { - buf_compress(new_html_mimepart(html).build().as_string().as_bytes()) - })?), - None => None, } } else { None }; + let new_mime_headers = new_mime_headers.or_else(|| match was_truncated { + true => Some(msg.text.clone()), + false => None, + }); + let new_mime_headers = match new_mime_headers { + Some(h) => Some(tokio::task::block_in_place(move || { + buf_compress(new_html_mimepart(h).build().as_string().as_bytes()) + })?), + None => None, + }; msg.chat_id = self.id; msg.from_id = ContactId::SELF; msg.rfc724_mid = new_rfc724_mid; msg.timestamp_sort = timestamp; - let (msg_text, was_truncated) = truncate_msg_text(context, msg.text.clone()).await?; - let mime_modified = new_mime_headers.is_some() | was_truncated; // add message to the database if let Some(update_msg_id) = update_msg_id { @@ -2142,7 +2145,7 @@ impl Chat { msg.hidden, msg.in_reply_to.as_deref().unwrap_or_default(), new_references, - mime_modified, + new_mime_headers.is_some(), new_mime_headers.unwrap_or_default(), location_id as i32, ephemeral_timer, @@ -2193,7 +2196,7 @@ impl Chat { msg.hidden, msg.in_reply_to.as_deref().unwrap_or_default(), new_references, - mime_modified, + new_mime_headers.is_some(), new_mime_headers.unwrap_or_default(), location_id as i32, ephemeral_timer, diff --git a/src/mimeparser.rs b/src/mimeparser.rs index a9cd67326..8fbb98eda 100644 --- a/src/mimeparser.rs +++ b/src/mimeparser.rs @@ -3598,11 +3598,25 @@ On 2020-10-25, Bob wrote: assert!(mimemsg.parts[0].msg.len() <= DC_DESIRED_TEXT_LEN + DC_ELLIPSIS.len()); } - { + for draft in [false, true] { let chat = t.get_self_chat().await; - t.send_text(chat.id, &long_txt).await; + let mut msg = Message::new(Viewtype::Text); + msg.set_text(long_txt.clone()); + if draft { + chat.id.set_draft(&t, Some(&mut msg)).await?; + } + t.send_msg(chat.id, &mut msg).await; let msg = t.get_last_msg_in(chat.id).await; assert!(msg.has_html()); + assert_eq!( + msg.id + .get_html(&t) + .await? + .unwrap() + .matches("just repeated") + .count(), + REPEAT_CNT + ); assert!( msg.text.matches("just repeated").count() <= DC_DESIRED_TEXT_LEN / REPEAT_TXT.len() ); @@ -3610,7 +3624,6 @@ On 2020-10-25, Bob wrote: } t.set_config(Config::Bot, Some("1")).await?; - { let mimemsg = MimeMessage::from_bytes(&t, long_txt.as_ref(), None).await?; assert!(!mimemsg.is_mime_modified);