mirror of
https://github.com/chatmail/core.git
synced 2026-05-12 19:36:32 +03:00
Use ForcePlaintext as enum, not i32
This commit is contained in:
committed by
link2xt
parent
a7178f4f25
commit
6fcc589655
@@ -842,7 +842,13 @@ impl Chat {
|
|||||||
/* check if we want to encrypt this message. If yes and circumstances change
|
/* 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),
|
so that E2EE is no longer available at a later point (reset, changed settings),
|
||||||
we might not send the message out at all */
|
we might not send the message out at all */
|
||||||
if msg.param.get_int(Param::ForcePlaintext).unwrap_or_default() == 0 {
|
if msg
|
||||||
|
.param
|
||||||
|
.get_int(Param::ForcePlaintext)
|
||||||
|
.and_then::<ForcePlaintext, _>(num_traits::FromPrimitive::from_i32)
|
||||||
|
.unwrap_or_default()
|
||||||
|
== ForcePlaintext::Dont
|
||||||
|
{
|
||||||
let mut can_encrypt = true;
|
let mut can_encrypt = true;
|
||||||
let mut all_mutual = context.get_config_bool(Config::E2eeEnabled).await;
|
let mut all_mutual = context.get_config_bool(Config::E2eeEnabled).await;
|
||||||
|
|
||||||
|
|||||||
@@ -237,13 +237,14 @@ impl<'a, 'b> MimeFactory<'a, 'b> {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
let force_plaintext = self
|
let force_plaintext: ForcePlaintext = self
|
||||||
.msg
|
.msg
|
||||||
.param
|
.param
|
||||||
.get_int(Param::ForcePlaintext)
|
.get_int(Param::ForcePlaintext)
|
||||||
|
.and_then(num_traits::FromPrimitive::from_i32)
|
||||||
.unwrap_or_default();
|
.unwrap_or_default();
|
||||||
|
|
||||||
if force_plaintext == 0 {
|
if force_plaintext == ForcePlaintext::Dont {
|
||||||
return self
|
return self
|
||||||
.msg
|
.msg
|
||||||
.param
|
.param
|
||||||
@@ -271,19 +272,20 @@ impl<'a, 'b> MimeFactory<'a, 'b> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn should_force_plaintext(&self) -> i32 {
|
fn should_force_plaintext(&self) -> ForcePlaintext {
|
||||||
match &self.loaded {
|
match &self.loaded {
|
||||||
Loaded::Message { chat } => {
|
Loaded::Message { chat } => {
|
||||||
if chat.typ == Chattype::VerifiedGroup {
|
if chat.typ == Chattype::VerifiedGroup {
|
||||||
0
|
ForcePlaintext::Dont
|
||||||
} else {
|
} else {
|
||||||
self.msg
|
self.msg
|
||||||
.param
|
.param
|
||||||
.get_int(Param::ForcePlaintext)
|
.get_int(Param::ForcePlaintext)
|
||||||
|
.and_then(num_traits::FromPrimitive::from_i32)
|
||||||
.unwrap_or_default()
|
.unwrap_or_default()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Loaded::MDN { .. } => ForcePlaintext::NoAutocryptHeader as i32,
|
Loaded::MDN { .. } => ForcePlaintext::NoAutocryptHeader,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -499,7 +501,7 @@ impl<'a, 'b> MimeFactory<'a, 'b> {
|
|||||||
Loaded::MDN { .. } => self.render_mdn().await?,
|
Loaded::MDN { .. } => self.render_mdn().await?,
|
||||||
};
|
};
|
||||||
|
|
||||||
if force_plaintext != ForcePlaintext::NoAutocryptHeader as i32 {
|
if force_plaintext != ForcePlaintext::NoAutocryptHeader {
|
||||||
// unless determined otherwise we add the Autocrypt header
|
// unless determined otherwise we add the Autocrypt header
|
||||||
let aheader = encrypt_helper.get_aheader().to_string();
|
let aheader = encrypt_helper.get_aheader().to_string();
|
||||||
unprotected_headers.push(Header::new("Autocrypt".into(), aheader));
|
unprotected_headers.push(Header::new("Autocrypt".into(), aheader));
|
||||||
@@ -510,7 +512,7 @@ impl<'a, 'b> MimeFactory<'a, 'b> {
|
|||||||
let peerstates = self.peerstates_for_recipients().await?;
|
let peerstates = self.peerstates_for_recipients().await?;
|
||||||
let should_encrypt =
|
let should_encrypt =
|
||||||
encrypt_helper.should_encrypt(self.context, e2ee_guaranteed, &peerstates)?;
|
encrypt_helper.should_encrypt(self.context, e2ee_guaranteed, &peerstates)?;
|
||||||
let is_encrypted = should_encrypt && force_plaintext == 0;
|
let is_encrypted = should_encrypt && force_plaintext == ForcePlaintext::Dont;
|
||||||
|
|
||||||
let rfc724_mid = match self.loaded {
|
let rfc724_mid = match self.loaded {
|
||||||
Loaded::Message { .. } => self.msg.rfc724_mid.clone(),
|
Loaded::Message { .. } => self.msg.rfc724_mid.clone(),
|
||||||
|
|||||||
21
src/param.rs
21
src/param.rs
@@ -40,8 +40,7 @@ pub enum Param {
|
|||||||
/// 'c' nor 'e' are preset, the messages is only transport encrypted.
|
/// 'c' nor 'e' are preset, the messages is only transport encrypted.
|
||||||
ErroneousE2ee = b'e',
|
ErroneousE2ee = b'e',
|
||||||
|
|
||||||
/// For Messages: force unencrypted message, either `ForcePlaintext::AddAutocryptHeader` (1),
|
/// For Messages: force unencrypted message, a value from `ForcePlaintext` enum.
|
||||||
/// `ForcePlaintext::NoAutocryptHeader` (2) or 0.
|
|
||||||
ForcePlaintext = b'u',
|
ForcePlaintext = b'u',
|
||||||
|
|
||||||
/// For Messages
|
/// For Messages
|
||||||
@@ -132,10 +131,28 @@ pub enum Param {
|
|||||||
#[derive(PartialEq, Eq, Debug, Clone, Copy, FromPrimitive)]
|
#[derive(PartialEq, Eq, Debug, Clone, Copy, FromPrimitive)]
|
||||||
#[repr(u8)]
|
#[repr(u8)]
|
||||||
pub enum ForcePlaintext {
|
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,
|
AddAutocryptHeader = 1,
|
||||||
|
|
||||||
|
/// Force plaintext message without Autocrypt header
|
||||||
|
///
|
||||||
|
/// Used for MDNs.
|
||||||
NoAutocryptHeader = 2,
|
NoAutocryptHeader = 2,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Default for ForcePlaintext {
|
||||||
|
fn default() -> Self {
|
||||||
|
Self::Dont
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// An object for handling key=value parameter lists.
|
/// An object for handling key=value parameter lists.
|
||||||
///
|
///
|
||||||
/// The structure is serialized by calling `to_string()` on it.
|
/// The structure is serialized by calling `to_string()` on it.
|
||||||
|
|||||||
Reference in New Issue
Block a user