From 3e09efaf0a631a00c9a30b015b2d1b1538045bd7 Mon Sep 17 00:00:00 2001 From: Alexander Krotov Date: Sun, 29 Sep 2019 23:17:21 +0300 Subject: [PATCH] Add mail_security and send_security fields to LoginParam --- src/configure/mod.rs | 26 +++++++++----------------- src/login_param.rs | 26 ++++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 17 deletions(-) diff --git a/src/configure/mod.rs b/src/configure/mod.rs index 991092941..858b121d0 100644 --- a/src/configure/mod.rs +++ b/src/configure/mod.rs @@ -296,26 +296,18 @@ pub unsafe fn dc_job_do_DC_JOB_CONFIGURE_IMAP(context: &Context) { param.server_flags &= !(DC_LP_AUTH_FLAGS as i32); param.server_flags |= DC_LP_AUTH_NORMAL as i32 } - if !dc_exactly_one_bit_set( - param.server_flags & DC_LP_IMAP_SOCKET_FLAGS as i32, - ) { - param.server_flags &= !(DC_LP_IMAP_SOCKET_FLAGS as i32); - param.server_flags |= if param.send_port == 143 { - DC_LP_IMAP_SOCKET_STARTTLS as i32 + if param.mail_security == 0 { + param.mail_security = if param.send_port == 143 { + 2 // StartTLS } else { - DC_LP_IMAP_SOCKET_SSL as i32 + 1 // SSL/TLS } } - if !dc_exactly_one_bit_set( - param.server_flags & (DC_LP_SMTP_SOCKET_FLAGS as i32), - ) { - param.server_flags &= !(DC_LP_SMTP_SOCKET_FLAGS as i32); - param.server_flags |= if param.send_port == 587 { - DC_LP_SMTP_SOCKET_STARTTLS as i32 - } else if param.send_port == 25 { - DC_LP_SMTP_SOCKET_PLAIN as i32 - } else { - DC_LP_SMTP_SOCKET_SSL as i32 + if param.send_security == 0 { + param.send_security = match param.send_port { + 587 => 2, // StartTLS + 25 => 3, // Plain + _ => 1, // SSL/TLS } } /* do we have a complete configuration? */ diff --git a/src/login_param.rs b/src/login_param.rs index 87ecd3886..4290d7b19 100644 --- a/src/login_param.rs +++ b/src/login_param.rs @@ -11,10 +11,12 @@ pub struct LoginParam { pub mail_user: String, pub mail_pw: String, pub mail_port: i32, + pub mail_security: i32, pub send_server: String, pub send_user: String, pub send_pw: String, pub send_port: i32, + pub send_security: i32, pub server_flags: i32, } @@ -63,16 +65,40 @@ impl LoginParam { let key = format!("{}server_flags", prefix); let server_flags = sql.get_config_int(context, key).unwrap_or_default(); + let mail_security = match ( + server_flags & DC_LP_IMAP_SOCKET_STARTTLS, + server_flags & DC_LP_IMAP_SOCKET_SSL, + server_flags & DC_LP_IMAP_SOCKET_PLAIN, + ) { + (1, 0, 0) => 2, // StartTLS + (0, 1, 0) => 1, // SSL/TLS + (0, 0, 1) => 3, // Plain + _ => 0, // Automatic + }; + + let send_security = match ( + server_flags & DC_LP_SMTP_SOCKET_FLAGS, + server_flags & DC_LP_SMTP_SOCKET_SSL, + server_flags & DC_LP_SMTP_SOCKET_PLAIN, + ) { + (1, 0, 0) => 2, // StartTLS + (0, 1, 0) => 1, // SSL/TLS + (0, 0, 1) => 3, // Plain + _ => 0, // Automatic + }; + LoginParam { addr: addr.to_string(), mail_server, mail_user, mail_pw, mail_port, + mail_security, send_server, send_user, send_pw, send_port, + send_security, server_flags, } }