reorganize dc_job_do_DC_JOB_CONFIGURE_IMAP

This commit is contained in:
Simon Laux
2019-08-14 03:12:48 +02:00
committed by holger krekel
parent 906b901e3d
commit 66ab6874f8

View File

@@ -1,6 +1,7 @@
use percent_encoding::{utf8_percent_encode, NON_ALPHANUMERIC}; use percent_encoding::{utf8_percent_encode, NON_ALPHANUMERIC};
use crate::constants::Event; use crate::constants::Event;
use crate::constants::DC_CREATE_MVBOX;
use crate::context::Context; use crate::context::Context;
use crate::dc_loginparam::*; use crate::dc_loginparam::*;
use crate::dc_tools::*; use crate::dc_tools::*;
@@ -73,13 +74,12 @@ unsafe fn dc_has_ongoing(context: &Context) -> libc::c_int {
// the other dc_job_do_DC_JOB_*() functions are declared static in the c-file // the other dc_job_do_DC_JOB_*() functions are declared static in the c-file
#[allow(non_snake_case, unused_must_use)] #[allow(non_snake_case, unused_must_use)]
pub unsafe fn dc_job_do_DC_JOB_CONFIGURE_IMAP(context: &Context, _job: &Job) { pub unsafe fn dc_job_do_DC_JOB_CONFIGURE_IMAP(context: &Context, _job: &Job) {
let flags: libc::c_int;
let mut success = false; let mut success = false;
let mut imap_connected_here = false; let mut imap_connected_here = false;
let mut smtp_connected_here = false; let mut smtp_connected_here = false;
let mut ongoing_allocated_here = false; let mut ongoing_allocated_here = false;
let mut param_autoconfig = None; let mut param_autoconfig: Option<dc_loginparam_t> = None;
if !(0 == dc_alloc_ongoing(context)) { if !(0 == dc_alloc_ongoing(context)) {
ongoing_allocated_here = true; ongoing_allocated_here = true;
if !context.sql.is_open() { if !context.sql.is_open() {
@@ -104,21 +104,47 @@ pub unsafe fn dc_job_do_DC_JOB_CONFIGURE_IMAP(context: &Context, _job: &Job) {
let s_a = context.running_state.clone(); let s_a = context.running_state.clone();
let s = s_a.read().unwrap(); let s = s_a.read().unwrap();
if !s.shall_stop_ongoing { // Variables that are shared between steps:
progress!(context, 1); let mut param: dc_loginparam_t = dc_loginparam_read(context, &context.sql, "");
// need all vars here to be mutable because rust thinks the same step could be called multiple times
// and also initilize, because otherwise rust thinks it's used while unitilized, even if thats not the case as the loop goes only forward
let mut param_domain = "undefined.undefined".to_owned();
let mut param_addr_urlencoded: String =
"Internal Error: this value should never be used".to_owned();
let mut keep_flags = std::i32::MAX;
let mut param = dc_loginparam_read(context, &context.sql, ""); const STEP_3_INDEX: u8 = 13;
if param.addr.is_empty() { let mut step_counter: u8 = 0;
error!(context, 0, "Please enter an email address.",); loop {
} else { step_counter = step_counter + 1;
let ok_to_continue0;
if 0 != param.server_flags & 0x2 { if s.shall_stop_ongoing {
// the used oauth2 addr may differ, check this. // if step_counter == 3 {
// if dc_get_oauth2_addr() is not available in the oauth2 implementation, // // Skip Autoconfig? (ok_to_continue 7)
// just use the given one. // // But wouldn't it need to reset s.shall_stop_ongoing then, too?
if s.shall_stop_ongoing { // // It needs to run sth. but fail afterwards anyway, I'm still not sure about this, because the C code doesn't work like this so I guess we should ignore it
ok_to_continue0 = false; // step_counter = STEP_3_INDEX;
} else { // } else {
// break;
// }
break;
}
let success = match step_counter {
// Read login parameters from the database
1 => {
progress!(context, 1);
if param.addr.is_empty() {
error!(context, 0, "Please enter an email address.",);
}
!param.addr.is_empty()
}
// Step 1: Load the parameters and check email-address and password
2 => {
if 0 != param.server_flags & 0x2 {
// the used oauth2 addr may differ, check this.
// if dc_get_oauth2_addr() is not available in the oauth2 implementation,
// just use the given one.
progress!(context, 10); progress!(context, 10);
if let Some(oauth2_addr) = if let Some(oauth2_addr) =
dc_get_oauth2_addr(context, &param.addr, &param.mail_pw) dc_get_oauth2_addr(context, &param.addr, &param.mail_pw)
@@ -130,478 +156,418 @@ pub unsafe fn dc_job_do_DC_JOB_CONFIGURE_IMAP(context: &Context, _job: &Job) {
.set_config(context, "addr", Some(param.addr.as_str())) .set_config(context, "addr", Some(param.addr.as_str()))
.ok(); .ok();
} }
if s.shall_stop_ongoing { progress!(context, 20);
ok_to_continue0 = false;
} else {
progress!(context, 20);
ok_to_continue0 = true;
}
} }
} else { true // no oauth? - just continue it's no error
ok_to_continue0 = true;
} }
if ok_to_continue0 { 3 => {
let mut ok_to_continue7 = false;
if let Ok(parsed) = param.addr.parse() { if let Ok(parsed) = param.addr.parse() {
let parsed: EmailAddress = parsed; let parsed: EmailAddress = parsed;
let param_domain = parsed.domain; param_domain = parsed.domain;
let param_addr_urlencoded = param_addr_urlencoded =
utf8_percent_encode(&param.addr, NON_ALPHANUMERIC).to_string(); utf8_percent_encode(&param.addr, NON_ALPHANUMERIC).to_string();
true
if !s.shall_stop_ongoing { } else {
progress!(context, 200); error!(context, 0, "Bad email-address.");
/* 2. Autoconfig false
**************************************************************************/ }
if param.mail_server.is_empty() }
&& param.mail_port == 0 // Step 2: Autoconfig
&& param.send_server.is_empty() 4 => {
&& param.send_port == 0 progress!(context, 200);
&& param.send_user.is_empty() if param.mail_server.is_empty()
&& param.server_flags & !0x2 == 0 && param.mail_port == 0
{ /*&&param.mail_user.is_empty() -- the user can enter a loginname which is used by autoconfig then */
let ok_to_continue1; && param.send_server.is_empty()
/*&&param->mail_user ==NULL -- the user can enter a loginname which is used by autoconfig then */ && param.send_port == 0
/*&&param->send_pw ==NULL -- the password cannot be auto-configured and is no criterion for autoconfig or not */ && param.send_user.is_empty()
/* flags but OAuth2 avoid autoconfig */ /*&&param.send_pw.is_empty() -- the password cannot be auto-configured and is no criterion for autoconfig or not */
let keep_flags = param.server_flags & 0x2; && param.server_flags & !0x2 == 0
/* A. Search configurations from the domain used in the email-address, prefer encrypted */ {
if param_autoconfig.is_none() { keep_flags = param.server_flags & 0x2;
let url = format!( } else {
"https://autoconfig.{}/mail/config-v1.1.xml?emailaddress={}", // Autoconfig is not needed so skip it.
step_counter = STEP_3_INDEX - 1;
}
true
}
/* A. Search configurations from the domain used in the email-address, prefer encrypted */
5 => {
if param_autoconfig.is_none() {
let url = format!(
"https://autoconfig.{}/mail/config-v1.1.xml?emailaddress={}",
param_domain, param_addr_urlencoded
);
param_autoconfig = moz_autoconfigure(context, &url, &param);
}
true
}
6 => {
progress!(context, 300);
if param_autoconfig.is_none() {
// the doc does not mention `emailaddress=`, however, Thunderbird adds it, see https://releases.mozilla.org/pub/thunderbird/ , which makes some sense
let url = format!(
"https://{}/.well-known/autoconfig/mail/config-v1.1.xml?emailaddress={}",
param_domain, param_domain,
param_addr_urlencoded param_addr_urlencoded
); );
param_autoconfig = moz_autoconfigure(context, &url, &param); param_autoconfig = moz_autoconfigure(context, &url, &param);
if s.shall_stop_ongoing { }
ok_to_continue1 = false; true
} else { }
progress!(context, 300); /* Outlook section start ------------- */
ok_to_continue1 = true; /* Outlook uses always SSL but different domains (this comment describes the next two steps) */
} 7 => {
} else { progress!(context, 310);
ok_to_continue1 = true; if param_autoconfig.is_none() {
} let url = format!(
if ok_to_continue1 { "https://{}{}/autodiscover/autodiscover.xml",
let ok_to_continue2; "", param_domain
if param_autoconfig.is_none() { );
// the doc does not mention `emailaddress=`, however, Thunderbird adds it, see https://releases.mozilla.org/pub/thunderbird/ , which makes some sense param_autoconfig = outlk_autodiscover(context, &url, &param);
let url = format!( }
"https://{}/.well-known/autoconfig/mail/config-v1.1.xml?emailaddress={}", true
param_domain, }
param_addr_urlencoded 8 => {
); progress!(context, 320);
param_autoconfig = if param_autoconfig.is_none() {
moz_autoconfigure(context, &url, &param); let url = format!(
if s.shall_stop_ongoing { "https://{}{}/autodiscover/autodiscover.xml",
ok_to_continue2 = false; "autodiscover.", param_domain
} else { );
progress!(context, 310); param_autoconfig = outlk_autodiscover(context, &url, &param);
ok_to_continue2 = true; }
} true
} else { }
ok_to_continue2 = true; /* ----------- Outlook section end */
} 9 => {
if ok_to_continue2 { progress!(context, 330);
let mut i: libc::c_int = 0; if param_autoconfig.is_none() {
let ok_to_continue3; let url = format!(
loop { "http://autoconfig.{}/mail/config-v1.1.xml?emailaddress={}",
if !(i <= 1) { param_domain, param_addr_urlencoded
ok_to_continue3 = true; );
break; param_autoconfig = moz_autoconfigure(context, &url, &param);
} }
if param_autoconfig.is_none() { true
/* Outlook uses always SSL but different domains */ }
let url = format!( 10 => {
"https://{}{}/autodiscover/autodiscover.xml", progress!(context, 340);
if i == 0 { if param_autoconfig.is_none() {
"" // do not transfer the email-address unencrypted
} else { let url = format!(
"autodiscover." "http://{}/.well-known/autoconfig/mail/config-v1.1.xml",
}, param_domain
param_domain );
); param_autoconfig = moz_autoconfigure(context, &url, &param);
param_autoconfig = }
outlk_autodiscover(context, &url, &param); true
}
if s.shall_stop_ongoing { /* B. If we have no configuration yet, search configuration in Thunderbird's centeral database */
ok_to_continue3 = false; 11 => {
break; progress!(context, 350);
} if param_autoconfig.is_none() {
progress!(context, 320 + i * 10); /* always SSL for Thunderbird's database */
} let url =
i += 1 format!("https://autoconfig.thunderbird.net/v1.1/{}", param_domain);
} param_autoconfig = moz_autoconfigure(context, &url, &param);
if ok_to_continue3 { }
let ok_to_continue4; true
if param_autoconfig.is_none() { }
let url = format!( /* C. Do we have any result? */
"http://autoconfig.{}/mail/config-v1.1.xml?emailaddress={}", 12 => {
param_domain, progress!(context, 500);
param_addr_urlencoded if let Some(ref cfg) = param_autoconfig {
); let r = dc_loginparam_get_readable(cfg);
param_autoconfig = info!(context, 0, "Got autoconfig: {}", r);
moz_autoconfigure(context, &url, &param); if !cfg.mail_user.is_empty() {
param.mail_user = cfg.mail_user.clone();
if s.shall_stop_ongoing {
ok_to_continue4 = false;
} else {
progress!(context, 340);
ok_to_continue4 = true;
}
} else {
ok_to_continue4 = true;
}
if ok_to_continue4 {
let ok_to_continue5;
if param_autoconfig.is_none() {
// do not transfer the email-address unencrypted
let url = format!(
"http://{}/.well-known/autoconfig/mail/config-v1.1.xml",
param_domain
);
param_autoconfig = moz_autoconfigure(
context, &url, &param,
);
if s.shall_stop_ongoing {
ok_to_continue5 = false;
} else {
progress!(context, 350);
ok_to_continue5 = true;
}
} else {
ok_to_continue5 = true;
}
if ok_to_continue5 {
let ok_to_continue6;
/* B. If we have no configuration yet, search configuration in Thunderbird's centeral database */
if param_autoconfig.is_none() {
/* always SSL for Thunderbird's database */
let url =
format!("https://autoconfig.thunderbird.net/v1.1/{}",
param_domain
);
param_autoconfig = moz_autoconfigure(
context, &url, &param,
);
if s.shall_stop_ongoing {
ok_to_continue6 = false;
} else {
progress!(context, 500);
ok_to_continue6 = true;
}
} else {
ok_to_continue6 = true;
}
if ok_to_continue6 {
if let Some(ref cfg) = param_autoconfig
{
let r =
dc_loginparam_get_readable(cfg);
info!(
context,
0, "Got autoconfig: {}", r
);
if !cfg.mail_user.is_empty() {
param.mail_user =
cfg.mail_user.clone();
}
param.mail_server =
cfg.mail_server.clone();
param.mail_port = cfg.mail_port;
param.send_server =
cfg.send_server.clone();
param.send_port = cfg.send_port;
param.send_user =
cfg.send_user.clone();
param.server_flags =
cfg.server_flags;
}
param.server_flags |= keep_flags;
ok_to_continue7 = true;
}
}
}
}
}
}
}
} else {
ok_to_continue7 = true;
} }
if ok_to_continue7 { param.mail_server = cfg.mail_server.clone(); /* all other values are always NULL when entering autoconfig */
if param.mail_server.is_empty() { param.mail_port = cfg.mail_port;
param.mail_server = format!("imap.{}", param_domain,) param.send_server = cfg.send_server.clone();
} param.send_port = cfg.send_port;
if param.mail_port == 0 { param.send_user = cfg.send_user.clone();
param.mail_port = if 0 != param.server_flags & (0x100 | 0x400) { param.server_flags = cfg.server_flags;
143 /* althoug param_autoconfig's data are no longer needed from, it is important to keep the object as
} else { we may enter "deep guessing" if we could not read a configuration */
993 }
} param.server_flags |= keep_flags;
} true
if param.mail_user.is_empty() { }
param.mail_user = param.addr.clone(); // Step 3: Fill missing fields with defaults
} 13 => {
if param.send_server.is_empty() && !param.mail_server.is_empty() { // if you move this, don't forget to update STEP_3_INDEX, too
param.send_server = param.mail_server.clone(); if param.mail_server.is_empty() {
if param.send_server.starts_with("imap.") { param.mail_server = format!("imap.{}", param_domain,)
param.send_server = }
param.send_server.replacen("imap", "smtp", 1); if param.mail_port == 0 {
} param.mail_port = if 0 != param.server_flags & (0x100 | 0x400) {
} 143
if param.send_port == 0 { } else {
param.send_port = if 0 != param.server_flags & 0x10000 { 993
587 }
} else if 0 != param.server_flags & 0x40000 { }
25 if param.mail_user.is_empty() {
} else { param.mail_user = param.addr.clone();
465 }
} if param.send_server.is_empty() && !param.mail_server.is_empty() {
} param.send_server = param.mail_server.clone();
if param.send_user.is_empty() && !param.mail_user.is_empty() { if param.send_server.starts_with("imap.") {
param.send_user = param.mail_user.clone(); param.send_server = param.send_server.replacen("imap", "smtp", 1);
} }
if param.send_pw.is_empty() && !param.mail_pw.is_empty() { }
param.send_pw = param.mail_pw.clone() if param.send_port == 0 {
} param.send_port = if 0 != param.server_flags & 0x10000 {
if !dc_exactly_one_bit_set(param.server_flags & (0x2 | 0x4)) { 587
param.server_flags &= !(0x2 | 0x4); } else if 0 != param.server_flags & 0x40000 {
param.server_flags |= 0x4 25
} } else {
if !dc_exactly_one_bit_set( 465
param.server_flags & (0x100 | 0x200 | 0x400), }
) { }
param.server_flags &= !(0x100 | 0x200 | 0x400); if param.send_user.is_empty() && !param.mail_user.is_empty() {
param.server_flags |= param.send_user = param.mail_user.clone();
if param.send_port == 143 { 0x100 } else { 0x200 } }
} if param.send_pw.is_empty() && !param.mail_pw.is_empty() {
if !dc_exactly_one_bit_set( param.send_pw = param.mail_pw.clone()
param.server_flags & (0x10000 | 0x20000 | 0x40000), }
) { if !dc_exactly_one_bit_set(param.server_flags & (0x2 | 0x4)) {
param.server_flags &= !(0x10000 | 0x20000 | 0x40000); param.server_flags &= !(0x2 | 0x4);
param.server_flags |= if param.send_port == 587 { param.server_flags |= 0x4
0x10000 }
} else if param.send_port == 25 { if !dc_exactly_one_bit_set(param.server_flags & (0x100 | 0x200 | 0x400)) {
0x40000 param.server_flags &= !(0x100 | 0x200 | 0x400);
} else { param.server_flags |= if param.send_port == 143 { 0x100 } else { 0x200 }
0x20000 }
} if !dc_exactly_one_bit_set(
} param.server_flags & (0x10000 | 0x20000 | 0x40000),
/* do we have a complete configuration? */ ) {
if param.mail_server.is_empty() param.server_flags &= !(0x10000 | 0x20000 | 0x40000);
|| param.mail_port == 0 param.server_flags |= if param.send_port == 587 {
|| param.mail_user.is_empty() 0x10000
|| param.mail_pw.is_empty() } else if param.send_port == 25 {
|| param.send_server.is_empty() 0x40000
|| param.send_port == 0 } else {
|| param.send_user.is_empty() 0x20000
|| param.send_pw.is_empty() }
|| param.server_flags == 0 }
/* do we have a complete configuration? */
if param.mail_server.is_empty()
|| param.mail_port == 0
|| param.mail_user.is_empty()
|| param.mail_pw.is_empty()
|| param.send_server.is_empty()
|| param.send_port == 0
|| param.send_user.is_empty()
|| param.send_pw.is_empty()
|| param.server_flags == 0
{
error!(context, 0, "Account settings incomplete.");
false
} else {
true
}
}
14 => {
progress!(context, 600);
/* try to connect to IMAP - if we did not got an autoconfig,
do some further tries with different settings and username variations */
let ok_to_continue8;
let mut username_variation = 0;
loop {
if !(username_variation <= 1) {
ok_to_continue8 = true;
break;
}
let r_0 = dc_loginparam_get_readable(&param);
info!(context, 0, "Trying: {}", r_0,);
if context.inbox.read().unwrap().connect(context, &param) {
ok_to_continue8 = true;
break;
}
if !param_autoconfig.is_none() {
ok_to_continue8 = false;
break;
}
// probe STARTTLS/993
if s.shall_stop_ongoing {
ok_to_continue8 = false;
break;
}
progress!(context, 650 + username_variation * 30);
param.server_flags &= !(0x100 | 0x200 | 0x400);
param.server_flags |= 0x100;
let r_1 = dc_loginparam_get_readable(&param);
info!(context, 0, "Trying: {}", r_1,);
if context.inbox.read().unwrap().connect(context, &param) {
ok_to_continue8 = true;
break;
}
// probe STARTTLS/143
if s.shall_stop_ongoing {
ok_to_continue8 = false;
break;
}
progress!(context, 660 + username_variation * 30);
param.mail_port = 143;
let r_2 = dc_loginparam_get_readable(&param);
info!(context, 0, "Trying: {}", r_2,);
if context.inbox.read().unwrap().connect(context, &param) {
ok_to_continue8 = true;
break;
}
if 0 != username_variation {
ok_to_continue8 = false;
break;
}
// next probe round with only the localpart of the email-address as the loginname
if s.shall_stop_ongoing {
ok_to_continue8 = false;
break;
}
progress!(context, 670 + username_variation * 30);
param.server_flags &= !(0x100 | 0x200 | 0x400);
param.server_flags |= 0x200;
param.mail_port = 993;
if let Some(at) = param.mail_user.find('@') {
param.mail_user = param.mail_user.split_at(at).0.to_string();
}
if let Some(at) = param.send_user.find('@') {
param.send_user = param.send_user.split_at(at).0.to_string();
}
username_variation += 1
}
if ok_to_continue8 {
// success, so we are connected and should disconnect in cleanup
imap_connected_here = true;
}
ok_to_continue8
}
15 => {
progress!(context, 800);
let success;
/* try to connect to SMTP - if we did not got an autoconfig, the first try was SSL-465 and we do a second try with STARTTLS-587 */
if !context
.smtp
.clone()
.lock()
.unwrap()
.connect(context, &param)
{
if !param_autoconfig.is_none() {
success = false;
} else if s.shall_stop_ongoing {
success = false;
} else {
progress!(context, 850);
param.server_flags &= !(0x10000 | 0x20000 | 0x40000);
param.server_flags |= 0x10000;
param.send_port = 587;
let r_3 = dc_loginparam_get_readable(&param);
info!(context, 0, "Trying: {}", r_3,);
if !context
.smtp
.clone()
.lock()
.unwrap()
.connect(context, &param)
{ {
error!(context, 0, "Account settings incomplete.",); if s.shall_stop_ongoing {
} else if !s.shall_stop_ongoing { success = false;
progress!(context, 600); } else {
/* try to connect to IMAP - if we did not got an autoconfig, progress!(context, 860);
do some further tries with different settings and username variations */ param.server_flags &= !(0x10000 | 0x20000 | 0x40000);
let ok_to_continue8; param.server_flags |= 0x10000;
let mut username_variation = 0; param.send_port = 25;
loop { let r_4 = dc_loginparam_get_readable(&param);
if !(username_variation <= 1) { info!(context, 0, "Trying: {}", r_4);
ok_to_continue8 = true;
break;
}
let r_0 = dc_loginparam_get_readable(&param);
info!(context, 0, "Trying: {}", r_0,);
if context.inbox.read().unwrap().connect(context, &param) { if !context
ok_to_continue8 = true; .smtp
break; .clone()
} .lock()
if !param_autoconfig.is_none() { .unwrap()
ok_to_continue8 = false; .connect(context, &param)
break; {
} success = false;
// probe STARTTLS/993 } else {
if s.shall_stop_ongoing { success = true;
ok_to_continue8 = false;
break;
}
progress!(context, 650 + username_variation * 30);
param.server_flags &= !(0x100 | 0x200 | 0x400);
param.server_flags |= 0x100;
let r_1 = dc_loginparam_get_readable(&param);
info!(context, 0, "Trying: {}", r_1,);
if context.inbox.read().unwrap().connect(context, &param) {
ok_to_continue8 = true;
break;
}
// probe STARTTLS/143
if s.shall_stop_ongoing {
ok_to_continue8 = false;
break;
}
progress!(context, 660 + username_variation * 30);
param.mail_port = 143;
let r_2 = dc_loginparam_get_readable(&param);
info!(context, 0, "Trying: {}", r_2,);
if context.inbox.read().unwrap().connect(context, &param) {
ok_to_continue8 = true;
break;
}
if 0 != username_variation {
ok_to_continue8 = false;
break;
}
// next probe round with only the localpart of the email-address as the loginname
if s.shall_stop_ongoing {
ok_to_continue8 = false;
break;
}
progress!(context, 670 + username_variation * 30);
param.server_flags &= !(0x100 | 0x200 | 0x400);
param.server_flags |= 0x200;
param.mail_port = 993;
if let Some(at) = param.mail_user.find('@') {
param.mail_user =
param.mail_user.split_at(at).0.to_string();
}
if let Some(at) = param.send_user.find('@') {
param.send_user =
param.send_user.split_at(at).0.to_string();
}
username_variation += 1
}
if ok_to_continue8 {
imap_connected_here = true;
if !s.shall_stop_ongoing {
progress!(context, 800);
let ok_to_continue9;
/* try to connect to SMTP - if we did not got an autoconfig, the first try was SSL-465 and we do a second try with STARTTLS-587 */
if !context
.smtp
.clone()
.lock()
.unwrap()
.connect(context, &param)
{
if !param_autoconfig.is_none() {
ok_to_continue9 = false;
} else if s.shall_stop_ongoing {
ok_to_continue9 = false;
} else {
progress!(context, 850);
param.server_flags &=
!(0x10000 | 0x20000 | 0x40000);
param.server_flags |= 0x10000;
param.send_port = 587;
let r_3 = dc_loginparam_get_readable(&param);
info!(context, 0, "Trying: {}", r_3,);
if !context
.smtp
.clone()
.lock()
.unwrap()
.connect(context, &param)
{
if s.shall_stop_ongoing {
ok_to_continue9 = false;
} else {
progress!(context, 860);
param.server_flags &=
!(0x10000 | 0x20000 | 0x40000);
param.server_flags |= 0x10000;
param.send_port = 25;
let r_4 =
dc_loginparam_get_readable(&param);
info!(context, 0, "Trying: {}", r_4);
if !context
.smtp
.clone()
.lock()
.unwrap()
.connect(context, &param)
{
ok_to_continue9 = false;
} else {
ok_to_continue9 = true;
}
}
} else {
ok_to_continue9 = true;
}
}
} else {
ok_to_continue9 = true;
}
if ok_to_continue9 {
smtp_connected_here = true;
if !s.shall_stop_ongoing {
progress!(context, 900);
flags = if 0
!= context
.sql
.get_config_int(context, "mvbox_watch")
.unwrap_or_else(|| 1)
|| 0 != context
.sql
.get_config_int(context, "mvbox_move")
.unwrap_or_else(|| 1)
{
0x1
} else {
0
};
context
.inbox
.read()
.unwrap()
.configure_folders(context, flags);
if !s.shall_stop_ongoing {
progress!(context, 910);
dc_loginparam_write(
context,
&param,
&context.sql,
"configured_",
);
context
.sql
.set_config_int(
context,
"configured",
1,
)
.ok();
if !s.shall_stop_ongoing {
progress!(context, 920);
e2ee::ensure_secret_key_exists(context);
success = true;
info!(
context,
0, "Configure completed."
);
if !s.shall_stop_ongoing {
progress!(context, 940);
}
}
}
}
}
} }
} }
} else {
success = true;
} }
} }
} else { } else {
error!(context, 0, "Bad email-address."); success = true;
} }
if success {
smtp_connected_here = true;
}
success
} }
16 => {
progress!(context, 900);
let flags: libc::c_int = if 0
!= context
.sql
.get_config_int(context, "mvbox_watch")
.unwrap_or_else(|| 1)
|| 0 != context
.sql
.get_config_int(context, "mvbox_move")
.unwrap_or_else(|| 1)
{
DC_CREATE_MVBOX as i32
} else {
0
};
context
.inbox
.read()
.unwrap()
.configure_folders(context, flags);
true
}
17 => {
progress!(context, 910);
/* configuration success - write back the configured parameters with the "configured_" prefix; also write the "configured"-flag */
dc_loginparam_write(
context,
&param,
&context.sql,
"configured_", /*the trailing underscore is correct*/
);
context.sql.set_config_int(context, "configured", 1).ok();
true
}
18 => {
progress!(context, 920);
// we generate the keypair just now - we could also postpone this until the first message is sent, however,
// this may result in a unexpected and annoying delay when the user sends his very first message
// (~30 seconds on a Moto G4 play) and might looks as if message sending is always that slow.
e2ee::ensure_secret_key_exists(context);
success = true;
info!(context, 0, "Configure completed.");
progress!(context, 940);
break; // We are done here
}
_ => {
error!(context, 0, "Internal error: step counter out of bound",);
break;
}
};
if !success {
break;
} }
} }
} }