From 79a08f96c526f1626b7b8f7212a0dfdf65401444 Mon Sep 17 00:00:00 2001 From: "B. Petersen" Date: Thu, 24 Oct 2019 00:16:10 +0200 Subject: [PATCH] make ShowEmails an enum, use constant for trash --- src/constants.rs | 19 ++++++++++++++----- src/dc_receive_imf.rs | 13 ++++++++----- 2 files changed, 22 insertions(+), 10 deletions(-) diff --git a/src/constants.rs b/src/constants.rs index fb1c486d7..b2a4ed7af 100644 --- a/src/constants.rs +++ b/src/constants.rs @@ -44,6 +44,20 @@ impl Default for Blocked { } } +#[derive(Debug, Display, Clone, Copy, PartialEq, Eq, FromPrimitive, ToPrimitive, FromSql, ToSql)] +#[repr(u8)] +pub enum ShowEmails { + Off = 0, + AcceptedContacts = 1, + All = 2, +} + +impl Default for ShowEmails { + fn default() -> Self { + ShowEmails::Off + } +} + pub const DC_IMAP_SEEN: u32 = 0x1; pub const DC_HANDSHAKE_CONTINUE_NORMAL_PROCESSING: i32 = 0x01; @@ -251,11 +265,6 @@ const DC_ERROR_SEE_STRING: usize = 0; // deprecated; const DC_ERROR_SELF_NOT_IN_GROUP: usize = 1; // deprecated; const DC_STR_SELFNOTINGRP: usize = 21; // deprecated; -/// Values for dc_get|set_config("show_emails") -const DC_SHOW_EMAILS_OFF: usize = 0; -const DC_SHOW_EMAILS_ACCEPTED_CONTACTS: usize = 1; -const DC_SHOW_EMAILS_ALL: usize = 2; - // TODO: Strings need some doumentation about used placeholders. // These constants are used to set stock translation strings diff --git a/src/dc_receive_imf.rs b/src/dc_receive_imf.rs index 7db594ae7..87c9af317 100644 --- a/src/dc_receive_imf.rs +++ b/src/dc_receive_imf.rs @@ -10,6 +10,8 @@ use mmime::mailmime::*; use mmime::other::*; use sha2::{Digest, Sha256}; +use num_traits::FromPrimitive; + use crate::blob::BlobObject; use crate::chat::{self, Chat}; use crate::config::Config; @@ -368,11 +370,12 @@ unsafe fn add_parts( // maybe this can be optimized later, by checking the state before the message body is downloaded let mut allow_creation = 1; if mime_parser.is_system_message != SystemMessage::AutocryptSetupMessage && msgrmsg == 0 { - let show_emails = context.get_config_int(Config::ShowEmails); - if show_emails == 0 { - *chat_id = 3; + let show_emails = + ShowEmails::from_i32(context.get_config_int(Config::ShowEmails)).unwrap_or_default(); + if show_emails == ShowEmails::Off { + *chat_id = DC_CHAT_ID_TRASH; allow_creation = 0 - } else if show_emails == 1 { + } else if show_emails == ShowEmails::AcceptedContacts { allow_creation = 0 } } @@ -440,7 +443,7 @@ unsafe fn add_parts( if *chat_id == 0 { // check if the message belongs to a mailing list if mime_parser.is_mailinglist_message() { - *chat_id = 3; + *chat_id = DC_CHAT_ID_TRASH; info!(context, "Message belongs to a mailing list and is ignored.",); } }