diff --git a/src/chat.rs b/src/chat.rs index 01e324a10..7dac298e0 100644 --- a/src/chat.rs +++ b/src/chat.rs @@ -842,12 +842,10 @@ impl Chat { /* check if we want to encrypt this message. If yes and circumstances change so that E2EE is no longer available at a later point (reset, changed settings), we might not send the message out at all */ - if msg + if !msg .param - .get_int(Param::ForcePlaintext) - .and_then::(num_traits::FromPrimitive::from_i32) + .get_bool(Param::ForcePlaintext) .unwrap_or_default() - == ForcePlaintext::Dont { let mut can_encrypt = true; let mut all_mutual = context.get_config_bool(Config::E2eeEnabled).await; diff --git a/src/imex.rs b/src/imex.rs index 1b8ea2510..50805707e 100644 --- a/src/imex.rs +++ b/src/imex.rs @@ -220,10 +220,8 @@ async fn do_initiate_key_transfer(context: &Context) -> Result { msg.param .set(Param::MimeType, "application/autocrypt-setup"); msg.param.set_cmd(SystemMessage::AutocryptSetupMessage); - msg.param.set_int( - Param::ForcePlaintext, - ForcePlaintext::NoAutocryptHeader as i32, - ); + msg.param.set_int(Param::ForcePlaintext, 1); + msg.param.set_int(Param::SkipAutocrypt, 1); let msg_id = chat::send_msg(context, chat_id, &mut msg).await?; info!(context, "Wait for setup message being sent ...",); diff --git a/src/mimefactory.rs b/src/mimefactory.rs index 0e807f6f8..737201720 100644 --- a/src/mimefactory.rs +++ b/src/mimefactory.rs @@ -237,23 +237,16 @@ impl<'a, 'b> MimeFactory<'a, 'b> { return true; } - let force_plaintext: ForcePlaintext = self + !self .msg .param - .get_int(Param::ForcePlaintext) - .and_then(num_traits::FromPrimitive::from_i32) - .unwrap_or_default(); - - if force_plaintext == ForcePlaintext::Dont { - return self + .get_bool(Param::ForcePlaintext) + .unwrap_or_default() + && self .msg .param - .get_int(Param::GuaranteeE2ee) + .get_bool(Param::GuaranteeE2ee) .unwrap_or_default() - != 0; - } - - false } Loaded::MDN { .. } => false, } @@ -272,20 +265,30 @@ impl<'a, 'b> MimeFactory<'a, 'b> { } } - fn should_force_plaintext(&self) -> ForcePlaintext { + fn should_force_plaintext(&self) -> bool { match &self.loaded { Loaded::Message { chat } => { if chat.typ == Chattype::VerifiedGroup { - ForcePlaintext::Dont + false } else { self.msg .param - .get_int(Param::ForcePlaintext) - .and_then(num_traits::FromPrimitive::from_i32) + .get_bool(Param::ForcePlaintext) .unwrap_or_default() } } - Loaded::MDN { .. } => ForcePlaintext::NoAutocryptHeader, + Loaded::MDN { .. } => true, + } + } + + fn should_skip_autocrypt(&self) -> bool { + match &self.loaded { + Loaded::Message { .. } => self + .msg + .param + .get_bool(Param::SkipAutocrypt) + .unwrap_or_default(), + Loaded::MDN { .. } => true, } } @@ -478,6 +481,7 @@ impl<'a, 'b> MimeFactory<'a, 'b> { let min_verified = self.min_verified(); let grpimage = self.grpimage(); let force_plaintext = self.should_force_plaintext(); + let skip_autocrypt = self.should_skip_autocrypt(); let subject_str = self.subject_str().await; let e2ee_guaranteed = self.is_e2ee_guaranteed(); let encrypt_helper = EncryptHelper::new(self.context).await?; @@ -501,7 +505,7 @@ impl<'a, 'b> MimeFactory<'a, 'b> { Loaded::MDN { .. } => self.render_mdn().await?, }; - if force_plaintext != ForcePlaintext::NoAutocryptHeader { + if !skip_autocrypt { // unless determined otherwise we add the Autocrypt header let aheader = encrypt_helper.get_aheader().to_string(); unprotected_headers.push(Header::new("Autocrypt".into(), aheader)); @@ -512,7 +516,7 @@ impl<'a, 'b> MimeFactory<'a, 'b> { let peerstates = self.peerstates_for_recipients().await?; let should_encrypt = encrypt_helper.should_encrypt(self.context, e2ee_guaranteed, &peerstates)?; - let is_encrypted = should_encrypt && force_plaintext == ForcePlaintext::Dont; + let is_encrypted = should_encrypt && !force_plaintext; let rfc724_mid = match self.loaded { Loaded::Message { .. } => self.msg.rfc724_mid.clone(), diff --git a/src/param.rs b/src/param.rs index 8dacb0403..3114d7f9d 100644 --- a/src/param.rs +++ b/src/param.rs @@ -43,6 +43,9 @@ pub enum Param { /// For Messages: force unencrypted message, a value from `ForcePlaintext` enum. ForcePlaintext = b'u', + /// For Messages: do not include Autocrypt header. + SkipAutocrypt = b'o', + /// For Messages WantsMdn = b'r', @@ -127,32 +130,6 @@ pub enum Param { MsgId = b'I', } -/// Possible values for `Param::ForcePlaintext`. -#[derive(PartialEq, Eq, Debug, Clone, Copy, FromPrimitive)] -#[repr(u8)] -pub enum ForcePlaintext { - /// Do not force plaintext - Dont = 0, - - /// Force plaintext message with Autocrypt header - /// - /// Used for `vc-request` and `vg-request` messages in - /// Verified Contact Protocol and - /// Verified Group Protocol. - AddAutocryptHeader = 1, - - /// Force plaintext message without Autocrypt header - /// - /// Used for MDNs. - NoAutocryptHeader = 2, -} - -impl Default for ForcePlaintext { - fn default() -> Self { - Self::Dont - } -} - /// An object for handling key=value parameter lists. /// /// The structure is serialized by calling `to_string()` on it. diff --git a/src/securejoin.rs b/src/securejoin.rs index 33409eae8..a45f04349 100644 --- a/src/securejoin.rs +++ b/src/securejoin.rs @@ -409,10 +409,7 @@ async fn send_handshake_msg( msg.param.set(Param::Arg4, grpid.as_ref()); } if step == "vg-request" || step == "vc-request" { - msg.param.set_int( - Param::ForcePlaintext, - ForcePlaintext::AddAutocryptHeader as i32, - ); + msg.param.set_int(Param::ForcePlaintext, 1); } else { msg.param.set_int(Param::GuaranteeE2ee, 1); }