diff --git a/src/chat/chat_tests.rs b/src/chat/chat_tests.rs index 7f6c60959..ffd393243 100644 --- a/src/chat/chat_tests.rs +++ b/src/chat/chat_tests.rs @@ -2792,7 +2792,7 @@ async fn test_broadcast_members_cant_see_each_other() -> Result<()> { assert_eq!(parsed.decoded_data_contains("bob@example.net"), false); let parsed_by_bob = bob.parse_msg(&vc_pubkey).await; - assert!(parsed_by_bob.decrypting_failed); + assert!(parsed_by_bob.decryption_error.is_some()); charlie.recv_msg_trash(&vc_pubkey).await; } @@ -2821,7 +2821,7 @@ async fn test_broadcast_members_cant_see_each_other() -> Result<()> { assert_eq!(parsed.decoded_data_contains("bob@example.net"), false); let parsed_by_bob = bob.parse_msg(&member_added).await; - assert!(parsed_by_bob.decrypting_failed); + assert!(parsed_by_bob.decryption_error.is_some()); let rcvd = charlie.recv_msg(&member_added).await; assert_eq!(rcvd.param.get_cmd(), SystemMessage::MemberAddedToGroup); @@ -2836,7 +2836,7 @@ async fn test_broadcast_members_cant_see_each_other() -> Result<()> { assert_eq!(parsed.decoded_data_contains("bob@example.net"), false); let parsed_by_bob = bob.parse_msg(&hi_msg).await; - assert_eq!(parsed_by_bob.decrypting_failed, false); + assert!(parsed_by_bob.decryption_error.is_none()); } tcm.section("Alice removes Charlie. Bob must not see it."); @@ -2853,7 +2853,7 @@ async fn test_broadcast_members_cant_see_each_other() -> Result<()> { assert_eq!(parsed.decoded_data_contains("bob@example.net"), false); let parsed_by_bob = bob.parse_msg(&member_removed).await; - assert!(parsed_by_bob.decrypting_failed); + assert!(parsed_by_bob.decryption_error.is_some()); let rcvd = charlie.recv_msg(&member_removed).await; assert_eq!(rcvd.param.get_cmd(), SystemMessage::MemberRemovedFromGroup); diff --git a/src/mimeparser.rs b/src/mimeparser.rs index 63c36ae8e..7165e3c67 100644 --- a/src/mimeparser.rs +++ b/src/mimeparser.rs @@ -86,7 +86,9 @@ pub(crate) struct MimeMessage { /// messages to this address to post them to the list. pub list_post: Option, pub chat_disposition_notification_to: Option, - pub decrypting_failed: bool, + + /// Decryption error if decryption of the message has failed. + pub decryption_error: Option, /// Valid signature fingerprint if a message is an /// Autocrypt encrypted and signed message and corresponding intended recipient fingerprints @@ -664,7 +666,7 @@ impl MimeMessage { from, incoming, chat_disposition_notification_to, - decrypting_failed: mail.is_err(), + decryption_error: mail.err().map(|err| format!("{err:#}")), // only non-empty if it was a valid autocrypt message signature, @@ -905,7 +907,7 @@ impl MimeMessage { && let Some(ref subject) = self.get_subject() { let mut prepend_subject = true; - if !self.decrypting_failed { + if self.decryption_error.is_none() { let colon = subject.find(':'); if colon == Some(2) || colon == Some(3) @@ -946,7 +948,7 @@ impl MimeMessage { self.parse_attachments(); // See if an MDN is requested from the other side - if !self.decrypting_failed + if self.decryption_error.is_none() && !self.parts.is_empty() && let Some(ref dn_to) = self.chat_disposition_notification_to { @@ -1078,7 +1080,7 @@ impl MimeMessage { #[cfg(test)] /// Returns whether the decrypted data contains the given `&str`. pub(crate) fn decoded_data_contains(&self, s: &str) -> bool { - assert!(!self.decrypting_failed); + assert!(self.decryption_error.is_none()); let decoded_str = str::from_utf8(&self.decoded_data).unwrap(); decoded_str.contains(s) } diff --git a/src/receive_imf.rs b/src/receive_imf.rs index 55c98da76..a5fca4e74 100644 --- a/src/receive_imf.rs +++ b/src/receive_imf.rs @@ -727,7 +727,7 @@ pub(crate) async fn receive_imf_inner( let show_emails = ShowEmails::from_i32(context.get_config_int(Config::ShowEmails).await?) .unwrap_or_default(); - let allow_creation = if mime_parser.decrypting_failed { + let allow_creation = if mime_parser.decryption_error.is_some() { false } else if is_dc_message == MessengerMessage::No && !context.get_config_bool(Config::IsChatmail).await? @@ -1211,14 +1211,18 @@ async fn decide_chat_assignment( { info!(context, "Call state changed (TRASH)."); true - } else if mime_parser.decrypting_failed && !mime_parser.incoming { + } else if let Some(ref decryption_error) = mime_parser.decryption_error + && !mime_parser.incoming + { // Outgoing undecryptable message. let last_time = context .get_config_i64(Config::LastCantDecryptOutgoingMsgs) .await?; let now = tools::time(); let update_config = if last_time.saturating_add(24 * 60 * 60) <= now { - let txt = "⚠️ It seems you are using Delta Chat on multiple devices that cannot decrypt each other's outgoing messages. To fix this, on the older device use \"Settings / Add Second Device\" and follow the instructions."; + let txt = format!( + "⚠️ It seems you are using Delta Chat on multiple devices that cannot decrypt each other's outgoing messages. To fix this, on the older device use \"Settings / Add Second Device\" and follow the instructions. (Error: {decryption_error}, {rfc724_mid})." + ); let mut msg = Message::new_text(txt.to_string()); chat::add_device_msg(context, None, Some(&mut msg)) .await @@ -2290,7 +2294,7 @@ RETURNING id if trash { 0 } else { ephemeral_timestamp }, if trash { DownloadState::Done - } else if mime_parser.decrypting_failed { + } else if mime_parser.decryption_error.is_some() { DownloadState::Undecipherable } else if let PreMessageMode::Pre {..} = mime_parser.pre_message { DownloadState::Available @@ -2703,7 +2707,7 @@ async fn lookup_or_create_adhoc_group( allow_creation: bool, create_blocked: Blocked, ) -> Result> { - if mime_parser.decrypting_failed { + if mime_parser.decryption_error.is_some() { warn!( context, "Not creating ad-hoc group for message that cannot be decrypted." @@ -2925,7 +2929,7 @@ async fn create_group( if let Some(chat_id) = chat_id { Ok(Some((chat_id, chat_id_blocked))) - } else if mime_parser.decrypting_failed { + } else if mime_parser.decryption_error.is_some() { // It is possible that the message was sent to a valid, // yet unknown group, which was rejected because // Chat-Group-Name, which is in the encrypted part, was diff --git a/src/receive_imf/receive_imf_tests.rs b/src/receive_imf/receive_imf_tests.rs index c0234063c..935c6b12a 100644 --- a/src/receive_imf/receive_imf_tests.rs +++ b/src/receive_imf/receive_imf_tests.rs @@ -3327,7 +3327,7 @@ async fn test_outgoing_undecryptable() -> Result<()> { assert!( dev_msg .text - .contains("⚠️ It seems you are using Delta Chat on multiple devices that cannot decrypt each other's outgoing messages. To fix this, on the older device use \"Settings / Add Second Device\" and follow the instructions.") + .starts_with("⚠️ It seems you are using Delta Chat on multiple devices that cannot decrypt each other's outgoing messages. To fix this, on the older device use \"Settings / Add Second Device\" and follow the instructions. (Error:") ); let raw = include_bytes!("../../test-data/message/thunderbird_encrypted_signed.eml"); diff --git a/src/tests/pre_messages/sending.rs b/src/tests/pre_messages/sending.rs index 063711230..4f5edfeb5 100644 --- a/src/tests/pre_messages/sending.rs +++ b/src/tests/pre_messages/sending.rs @@ -79,7 +79,7 @@ async fn test_sending_pre_message() -> Result<()> { ); let decrypted_post_message = bob.parse_msg(post_message).await; - assert_eq!(decrypted_post_message.decrypting_failed, false); + assert!(decrypted_post_message.decryption_error.is_none()); assert_eq!( decrypted_post_message.header_exists(HeaderDef::ChatPostMessageId), false