mirror of
https://github.com/chatmail/core.git
synced 2026-05-08 09:26:29 +03:00
feat: Don't allow to edit unencrypted messages
There's no valid UI scenario for this.
This commit is contained in:
@@ -2904,6 +2904,10 @@ pub async fn send_edit_request(context: &Context, msg_id: MsgId, new_text: Strin
|
|||||||
original_msg.from_id == ContactId::SELF,
|
original_msg.from_id == ContactId::SELF,
|
||||||
"Can edit only own messages"
|
"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.is_info(), "Cannot edit info messages");
|
||||||
ensure!(!original_msg.has_html(), "Cannot edit HTML messages");
|
ensure!(!original_msg.has_html(), "Cannot edit HTML messages");
|
||||||
ensure!(original_msg.viewtype != Viewtype::Call, "Cannot edit calls");
|
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
|
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
|
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
|
edit_msg
|
||||||
.param
|
.param
|
||||||
.set(Param::TextEditFor, original_msg.rfc724_mid);
|
.set(Param::TextEditFor, original_msg.rfc724_mid);
|
||||||
|
|||||||
@@ -1,11 +1,10 @@
|
|||||||
use mailparse::ParsedMail;
|
use mailparse::ParsedMail;
|
||||||
use std::mem;
|
|
||||||
|
|
||||||
use super::*;
|
use super::*;
|
||||||
use crate::{
|
use crate::{
|
||||||
chat,
|
chat,
|
||||||
chatlist::Chatlist,
|
chatlist::Chatlist,
|
||||||
constants::{self, Blocked, DC_DESIRED_TEXT_LEN, DC_ELLIPSIS},
|
constants::{Blocked, DC_DESIRED_TEXT_LEN, DC_ELLIPSIS},
|
||||||
message::{MessageState, MessengerMessage},
|
message::{MessageState, MessengerMessage},
|
||||||
receive_imf::receive_imf,
|
receive_imf::receive_imf,
|
||||||
test_utils::{TestContext, TestContextManager},
|
test_utils::{TestContext, TestContextManager},
|
||||||
@@ -1964,23 +1963,16 @@ async fn test_chat_edit_imf_header() -> Result<()> {
|
|||||||
let alice_msg = sent1.load_from_db().await;
|
let alice_msg = sent1.load_from_db().await;
|
||||||
assert_eq!(alice_chat.id.get_msg_cnt(alice).await?, 1);
|
assert_eq!(alice_chat.id.get_msg_cnt(alice).await?, 1);
|
||||||
|
|
||||||
chat::send_edit_request(alice, alice_msg.id, "bar".to_string()).await?;
|
// Cannot edit unencrypted messages.
|
||||||
let mut sent2 = alice.pop_sent_msg().await;
|
let res = chat::send_edit_request(alice, alice_msg.id, "bar".to_string()).await;
|
||||||
let mut s0 = String::new();
|
assert!(res.is_err());
|
||||||
let mut s1 = String::new();
|
|
||||||
for l in sent2.payload.lines() {
|
let mut sent2 = alice.send_text(alice_chat.id, "bar").await;
|
||||||
if l.starts_with("Chat-Edit:") {
|
sent2.payload = sent2.payload.replacen(
|
||||||
s1 += l;
|
"Message-ID:",
|
||||||
s1 += "\n";
|
&format!("Chat-Edit: <{}>\nMessage-ID:", alice_msg.rfc724_mid),
|
||||||
continue;
|
1,
|
||||||
}
|
);
|
||||||
s0 += l;
|
|
||||||
s0 += "\n";
|
|
||||||
if l.starts_with("Message-ID:") && s1.is_empty() {
|
|
||||||
s1 = mem::take(&mut s0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
sent2.payload = s1 + &s0;
|
|
||||||
|
|
||||||
// Bob receives both messages, the edit request with "Chat-Edit" in IMF headers is
|
// Bob receives both messages, the edit request with "Chat-Edit" in IMF headers is
|
||||||
// received as text message.
|
// 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.text, "foo");
|
||||||
assert_eq!(bob_msg.chat_id.get_msg_cnt(bob).await?, 1);
|
assert_eq!(bob_msg.chat_id.get_msg_cnt(bob).await?, 1);
|
||||||
let bob_msg = bob.recv_msg(&sent2).await;
|
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);
|
assert_eq!(bob_msg.chat_id.get_msg_cnt(bob).await?, 2);
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|||||||
Reference in New Issue
Block a user