fixes #661 and also contains a cleanup of config access (only for e2ee and mdns)

This commit is contained in:
holger krekel
2019-10-02 20:30:41 +02:00
parent 92438737c9
commit 5c1b9c83f7
7 changed files with 17 additions and 45 deletions

View File

@@ -299,11 +299,7 @@ impl Chat {
so that E2EE is no longer available at a later point (reset, changed settings),
we do not send the message out at all */
do_guarantee_e2ee = false;
e2ee_enabled = context
.sql
.get_config_int(context, "e2ee_enabled")
.unwrap_or_else(|| 1)
== 1;
e2ee_enabled = context.get_config_bool(Config::E2eeEnabled);
if e2ee_enabled && msg.param.get_int(Param::ForcePlaintext).unwrap_or_default() == 0 {
let mut can_encrypt = 1;
let mut all_mutual = 1;

View File

@@ -25,7 +25,6 @@ impl Default for MoveState {
// some defaults
const DC_E2EE_DEFAULT_ENABLED: i32 = 1;
pub const DC_MDNS_DEFAULT_ENABLED: i32 = 1;
const DC_INBOX_WATCH_DEFAULT: i32 = 1;
const DC_SENTBOX_WATCH_DEFAULT: i32 = 1;
const DC_MVBOX_WATCH_DEFAULT: i32 = 1;

View File

@@ -13,6 +13,7 @@ use mmime::other::*;
use sha2::{Digest, Sha256};
use crate::chat::{self, Chat};
use crate::config::Config;
use crate::constants::*;
use crate::contact::*;
use crate::context::Context;
@@ -371,10 +372,7 @@ 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
.sql
.get_config_int(context, "show_emails")
.unwrap_or_default();
let show_emails = context.get_config_int(Config::ShowEmails);
if show_emails == 0 {
*chat_id = 3;
allow_creation = 0
@@ -737,10 +735,7 @@ unsafe fn handle_reports(
server_folder: impl AsRef<str>,
server_uid: u32,
) {
let mdns_enabled = context
.sql
.get_config_int(context, "mdns_enabled")
.unwrap_or_else(|| DC_MDNS_DEFAULT_ENABLED);
let mdns_enabled = context.get_config_bool(Config::MdnsEnabled);
for report_root in &mime_parser.reports {
let report_root = *report_root;
@@ -759,7 +754,7 @@ unsafe fn handle_reports(
&& (*(*report_root).mm_data.mm_multipart.mm_mp_list).count >= 2
{
// to get a clear functionality, do not show incoming MDNs if the options is disabled
if 0 != mdns_enabled {
if mdns_enabled {
let report_data = (if !if !(*(*report_root).mm_data.mm_multipart.mm_mp_list)
.first
.is_null()

View File

@@ -46,12 +46,8 @@ pub struct EncryptHelper {
impl EncryptHelper {
pub fn new(context: &Context) -> Result<EncryptHelper> {
let prefer_encrypt = context
.sql
.get_config_int(&context, "e2ee_enabled")
.and_then(EncryptPreference::from_i32)
.unwrap_or_default();
let prefer_encrypt =
EncryptPreference::from_i32(context.get_config_int(Config::E2eeEnabled)).unwrap();
let addr = match context.get_config(Config::ConfiguredAddr) {
None => {
bail!("addr not configured!");

View File

@@ -195,13 +195,9 @@ pub fn render_setup_file(context: &Context, passphrase: &str) -> Result<String>
let self_addr = e2ee::ensure_secret_key_exists(context)?;
let private_key = Key::from_self_private(context, self_addr, &context.sql)
.ok_or(format_err!("Failed to get private key."))?;
let ac_headers = match context
.sql
.get_config_int(context, Config::E2eeEnabled)
.unwrap_or(1)
{
0 => None,
_ => Some(("Autocrypt-Prefer-Encrypt", "mutual")),
let ac_headers = match context.get_config_bool(Config::E2eeEnabled) {
false => None,
true => Some(("Autocrypt-Prefer-Encrypt", "mutual")),
};
let private_key_asc = private_key.to_asc(ac_headers);
let encr = dc_pgp_symm_encrypt(&passphrase, private_key_asc.as_bytes())?;

View File

@@ -318,10 +318,7 @@ impl Job {
}
_ => {
if 0 != msg.param.get_int(Param::WantsMdn).unwrap_or_default()
&& 0 != context
.sql
.get_config_int(context, "mdns_enabled")
.unwrap_or_else(|| 1)
&& context.get_config_bool(Config::MdnsEnabled)
{
let folder = msg.server_folder.as_ref().unwrap();

View File

@@ -13,6 +13,7 @@ use mmime::mmapstring::*;
use mmime::other::*;
use crate::chat::{self, Chat};
use crate::config::Config;
use crate::constants::*;
use crate::contact::*;
use crate::context::{get_version_str, Context};
@@ -106,15 +107,10 @@ impl<'a> MimeFactory<'a> {
}
pub fn load_mdn(context: &'a Context, msg_id: u32) -> Result<MimeFactory, Error> {
if 0 == context
.sql
.get_config_int(context, "mdns_enabled")
.unwrap_or_else(|| 1)
{
// MDNs not enabled - check this is late, in the job. the use may have changed its
// choice while offline ...
bail!("MDNs disabled ")
if !context.get_config_bool(Config::MdnsEnabled) {
// MDNs not enabled - check this is late, in the job. the
// user may have changed its choice while offline ...
bail!("MDNs meanwhile disabled")
}
let msg = Message::load_from_db(context, msg_id)?;
@@ -727,10 +723,7 @@ impl<'a> MimeFactory<'a> {
}
if command != SystemMessage::AutocryptSetupMessage
&& command != SystemMessage::SecurejoinMessage
&& 0 != context
.sql
.get_config_int(context, "mdns_enabled")
.unwrap_or_else(|| 1)
&& context.get_config_bool(Config::MdnsEnabled)
{
factory.req_mdn = true;
}