Compare commits

...

1 Commits

Author SHA1 Message Date
iequidoo
ca7d4455bb feat: Don't allow to edit unencrypted messages
There's no valid UI scenario for this.
2025-12-05 17:48:12 -03:00
2 changed files with 17 additions and 23 deletions

View File

@@ -2904,6 +2904,10 @@ pub async fn send_edit_request(context: &Context, msg_id: MsgId, new_text: Strin
original_msg.from_id == ContactId::SELF,
"Can edit only own messages"
);
ensure!(
original_msg.get_showpadlock(),
"Cannot edit unencrypted messages"
);
ensure!(!original_msg.is_info(), "Cannot edit info messages");
ensure!(!original_msg.has_html(), "Cannot edit HTML messages");
ensure!(original_msg.viewtype != Viewtype::Call, "Cannot edit calls");
@@ -2921,9 +2925,7 @@ pub async fn send_edit_request(context: &Context, msg_id: MsgId, new_text: Strin
let mut edit_msg = Message::new_text(EDITED_PREFIX.to_owned() + &new_text); // prefix only set for nicer display in Non-Delta-MUAs
edit_msg.set_quote(context, Some(&original_msg)).await?; // quote only set for nicer display in Non-Delta-MUAs
if original_msg.get_showpadlock() {
edit_msg.param.set_int(Param::GuaranteeE2ee, 1);
}
edit_msg.param.set_int(Param::GuaranteeE2ee, 1);
edit_msg
.param
.set(Param::TextEditFor, original_msg.rfc724_mid);

View File

@@ -1,11 +1,10 @@
use mailparse::ParsedMail;
use std::mem;
use super::*;
use crate::{
chat,
chatlist::Chatlist,
constants::{self, Blocked, DC_DESIRED_TEXT_LEN, DC_ELLIPSIS},
constants::{Blocked, DC_DESIRED_TEXT_LEN, DC_ELLIPSIS},
message::{MessageState, MessengerMessage},
receive_imf::receive_imf,
test_utils::{TestContext, TestContextManager},
@@ -1964,23 +1963,16 @@ async fn test_chat_edit_imf_header() -> Result<()> {
let alice_msg = sent1.load_from_db().await;
assert_eq!(alice_chat.id.get_msg_cnt(alice).await?, 1);
chat::send_edit_request(alice, alice_msg.id, "bar".to_string()).await?;
let mut sent2 = alice.pop_sent_msg().await;
let mut s0 = String::new();
let mut s1 = String::new();
for l in sent2.payload.lines() {
if l.starts_with("Chat-Edit:") {
s1 += l;
s1 += "\n";
continue;
}
s0 += l;
s0 += "\n";
if l.starts_with("Message-ID:") && s1.is_empty() {
s1 = mem::take(&mut s0);
}
}
sent2.payload = s1 + &s0;
// Cannot edit unencrypted messages.
let res = chat::send_edit_request(alice, alice_msg.id, "bar".to_string()).await;
assert!(res.is_err());
let mut sent2 = alice.send_text(alice_chat.id, "bar").await;
sent2.payload = sent2.payload.replacen(
"Message-ID:",
&format!("Chat-Edit: <{}>\nMessage-ID:", alice_msg.rfc724_mid),
1,
);
// Bob receives both messages, the edit request with "Chat-Edit" in IMF headers is
// received as text message.
@@ -1988,7 +1980,7 @@ async fn test_chat_edit_imf_header() -> Result<()> {
assert_eq!(bob_msg.text, "foo");
assert_eq!(bob_msg.chat_id.get_msg_cnt(bob).await?, 1);
let bob_msg = bob.recv_msg(&sent2).await;
assert_eq!(bob_msg.text, constants::EDITED_PREFIX.to_string() + "bar");
assert_eq!(bob_msg.text, "bar");
assert_eq!(bob_msg.chat_id.get_msg_cnt(bob).await?, 2);
Ok(())