From 7de23f86b1557f1915e89b6333f3fc4f0a79ee82 Mon Sep 17 00:00:00 2001 From: Alexander Krotov Date: Mon, 8 Jun 2020 22:45:51 +0300 Subject: [PATCH] Do not reply to messages that can't be decrypted This commit fixes the test broken in previous commit. --- src/chat.rs | 40 ++++++++++++++++++++++++++++++---------- src/mimeparser.rs | 1 + 2 files changed, 31 insertions(+), 10 deletions(-) diff --git a/src/chat.rs b/src/chat.rs index abc3fed4e..c8fa0c411 100644 --- a/src/chat.rs +++ b/src/chat.rs @@ -422,15 +422,35 @@ impl ChatId { } async fn get_parent_mime_headers(self, context: &Context) -> Option<(String, String, String)> { - let collect = |row: &rusqlite::Row| Ok((row.get(0)?, row.get(1)?, row.get(2)?)); - self.parent_query( - context, - "rfc724_mid, mime_in_reply_to, mime_references", - collect, - ) - .await - .ok() - .flatten() + let collect = + |row: &rusqlite::Row| Ok((row.get(0)?, row.get(1)?, row.get(2)?, row.get(3)?)); + let (packed, rfc724_mid, mime_in_reply_to, mime_references): ( + String, + String, + String, + String, + ) = self + .parent_query( + context, + "param, rfc724_mid, mime_in_reply_to, mime_references", + collect, + ) + .await + .ok() + .flatten()?; + + let param = packed.parse::().ok()?; + if param.exists(Param::Error) { + // Do not reply to error messages. + // + // An error message could be a group chat message that we failed to decrypt and + // assigned to 1:1 chat. A reply to it will show up as a reply to group message + // on the other side. To avoid such situations, it is better not to reply to + // error messages at all. + None + } else { + Some((rfc724_mid, mime_in_reply_to, mime_references)) + } } async fn parent_is_encrypted(self, context: &Context) -> Result { @@ -439,7 +459,7 @@ impl ChatId { if let Some(ref packed) = packed { let param = packed.parse::()?; - Ok(param.exists(Param::GuaranteeE2ee)) + Ok(!param.exists(Param::Error) && param.exists(Param::GuaranteeE2ee)) } else { // No messages Ok(false) diff --git a/src/mimeparser.rs b/src/mimeparser.rs index 4a5c09bb4..17883e137 100644 --- a/src/mimeparser.rs +++ b/src/mimeparser.rs @@ -527,6 +527,7 @@ impl MimeMessage { part.typ = Viewtype::Text; part.msg_raw = Some(txt.clone()); part.msg = txt; + part.param.set(Param::Error, "Decryption failed"); self.parts.push(part);