refactor: add Encryption.is_encrypted()

This commit is contained in:
link2xt
2026-08-25 19:05:28 +00:00
committed by l
parent 81ca5aa1ca
commit 5be489790f

View File

@@ -96,6 +96,16 @@ enum Encryption {
Symmetric { shared_secret: String }, Symmetric { shared_secret: String },
} }
impl Encryption {
pub fn is_encrypted(&self) -> bool {
match self {
Self::No => false,
Self::Asymmetric { .. } => true,
Self::Symmetric { .. } => true,
}
}
}
/// Helper to construct mime messages. /// Helper to construct mime messages.
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub struct MimeFactory { pub struct MimeFactory {
@@ -281,7 +291,7 @@ pub(crate) fn render_queued_mail(
let mut inner_headers: Vec<u8> = Vec::new(); let mut inner_headers: Vec<u8> = Vec::new();
let mut outer_headers: Vec<u8> = Vec::new(); let mut outer_headers: Vec<u8> = Vec::new();
let is_encrypted = !matches!(encryption, Encryption::No); let is_encrypted = encryption.is_encrypted();
fn add_header( fn add_header(
name: &[u8], name: &[u8],
@@ -848,8 +858,8 @@ impl MimeFactory {
// We don't display avatars for address-contacts, so sending avatars w/o encryption is not // We don't display avatars for address-contacts, so sending avatars w/o encryption is not
// useful and causes e.g. Outlook to reject a message with a big header, see // useful and causes e.g. Outlook to reject a message with a big header, see
// https://support.delta.chat/t/invalid-mime-content-single-text-value-size-32822-exceeded-allowed-maximum-32768-for-the-chat-user-avatar-header/4067. // https://support.delta.chat/t/invalid-mime-content-single-text-value-size-32822-exceeded-allowed-maximum-32768-for-the-chat-user-avatar-header/4067.
let attach_selfavatar = Self::should_attach_selfavatar(context, &msg).await let attach_selfavatar =
&& !matches!(encryption, Encryption::No); Self::should_attach_selfavatar(context, &msg).await && encryption.is_encrypted();
ensure_and_debug_assert!( ensure_and_debug_assert!(
member_timestamps.is_empty() member_timestamps.is_empty()
@@ -2277,10 +2287,7 @@ impl MimeFactory {
} }
pub fn will_be_encrypted(&self) -> bool { pub fn will_be_encrypted(&self) -> bool {
match self.encryption { self.encryption.is_encrypted()
Encryption::No => false,
Encryption::Asymmetric { .. } | Encryption::Symmetric { .. } => true,
}
} }
pub fn set_as_post_message(&mut self) { pub fn set_as_post_message(&mut self) {