mirror of
https://github.com/chatmail/core.git
synced 2026-05-05 22:36:30 +03:00
cargo fmt
This commit is contained in:
@@ -50,11 +50,11 @@ pub fn dc_job_do_DC_JOB_CONFIGURE_IMAP(context: &Context) {
|
|||||||
if !context.sql.is_open() {
|
if !context.sql.is_open() {
|
||||||
error!(context, "Cannot configure, database not opened.",);
|
error!(context, "Cannot configure, database not opened.",);
|
||||||
progress!(context, 0);
|
progress!(context, 0);
|
||||||
return
|
return;
|
||||||
}
|
}
|
||||||
if !context.alloc_ongoing() {
|
if !context.alloc_ongoing() {
|
||||||
progress!(context, 0);
|
progress!(context, 0);
|
||||||
return
|
return;
|
||||||
}
|
}
|
||||||
let mut success = false;
|
let mut success = false;
|
||||||
let mut imap_connected_here = false;
|
let mut imap_connected_here = false;
|
||||||
@@ -170,8 +170,7 @@ pub fn dc_job_do_DC_JOB_CONFIGURE_IMAP(context: &Context) {
|
|||||||
// the doc does not mention `emailaddress=`, however, Thunderbird adds it, see https://releases.mozilla.org/pub/thunderbird/ , which makes some sense
|
// the doc does not mention `emailaddress=`, however, Thunderbird adds it, see https://releases.mozilla.org/pub/thunderbird/ , which makes some sense
|
||||||
let url = format!(
|
let url = format!(
|
||||||
"https://{}/.well-known/autoconfig/mail/config-v1.1.xml?emailaddress={}",
|
"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, ¶m);
|
param_autoconfig = moz_autoconfigure(context, &url, ¶m);
|
||||||
}
|
}
|
||||||
@@ -230,8 +229,7 @@ pub fn dc_job_do_DC_JOB_CONFIGURE_IMAP(context: &Context) {
|
|||||||
progress!(context, 350);
|
progress!(context, 350);
|
||||||
if param_autoconfig.is_none() {
|
if param_autoconfig.is_none() {
|
||||||
/* always SSL for Thunderbird's database */
|
/* always SSL for Thunderbird's database */
|
||||||
let url =
|
let url = format!("https://autoconfig.thunderbird.net/v1.1/{}", param_domain);
|
||||||
format!("https://autoconfig.thunderbird.net/v1.1/{}", param_domain);
|
|
||||||
param_autoconfig = moz_autoconfigure(context, &url, ¶m);
|
param_autoconfig = moz_autoconfigure(context, &url, ¶m);
|
||||||
}
|
}
|
||||||
true
|
true
|
||||||
@@ -279,8 +277,8 @@ pub fn dc_job_do_DC_JOB_CONFIGURE_IMAP(context: &Context) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if param.send_port == 0 {
|
if param.send_port == 0 {
|
||||||
param.send_port =
|
param.send_port = if 0 != param.server_flags & DC_LP_SMTP_SOCKET_STARTTLS as i32
|
||||||
if 0 != param.server_flags & DC_LP_SMTP_SOCKET_STARTTLS as i32 {
|
{
|
||||||
587
|
587
|
||||||
} else if 0 != param.server_flags & DC_LP_SMTP_SOCKET_PLAIN as i32 {
|
} else if 0 != param.server_flags & DC_LP_SMTP_SOCKET_PLAIN as i32 {
|
||||||
25
|
25
|
||||||
@@ -298,9 +296,7 @@ pub 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_FLAGS as i32);
|
||||||
param.server_flags |= DC_LP_AUTH_NORMAL as i32
|
param.server_flags |= DC_LP_AUTH_NORMAL as i32
|
||||||
}
|
}
|
||||||
if !dc_exactly_one_bit_set(
|
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 &= !(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 {
|
param.server_flags |= if param.send_port == 143 {
|
||||||
DC_LP_IMAP_SOCKET_STARTTLS as i32
|
DC_LP_IMAP_SOCKET_STARTTLS as i32
|
||||||
@@ -308,9 +304,7 @@ pub fn dc_job_do_DC_JOB_CONFIGURE_IMAP(context: &Context) {
|
|||||||
DC_LP_IMAP_SOCKET_SSL as i32
|
DC_LP_IMAP_SOCKET_SSL as i32
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if !dc_exactly_one_bit_set(
|
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 &= !(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 {
|
param.server_flags |= if param.send_port == 587 {
|
||||||
DC_LP_SMTP_SOCKET_STARTTLS as i32
|
DC_LP_SMTP_SOCKET_STARTTLS as i32
|
||||||
@@ -341,12 +335,14 @@ pub fn dc_job_do_DC_JOB_CONFIGURE_IMAP(context: &Context) {
|
|||||||
progress!(context, 600);
|
progress!(context, 600);
|
||||||
/* try to connect to IMAP - if we did not got an autoconfig,
|
/* try to connect to IMAP - if we did not got an autoconfig,
|
||||||
do some further tries with different settings and username variations */
|
do some further tries with different settings and username variations */
|
||||||
imap_connected_here = try_imap_connections(context, &mut param, param_autoconfig.is_some());
|
imap_connected_here =
|
||||||
|
try_imap_connections(context, &mut param, param_autoconfig.is_some());
|
||||||
imap_connected_here
|
imap_connected_here
|
||||||
}
|
}
|
||||||
15 => {
|
15 => {
|
||||||
progress!(context, 800);
|
progress!(context, 800);
|
||||||
smtp_connected_here = try_smtp_connections(context, &mut param, param_autoconfig.is_some());
|
smtp_connected_here =
|
||||||
|
try_smtp_connections(context, &mut param, param_autoconfig.is_some());
|
||||||
smtp_connected_here
|
smtp_connected_here
|
||||||
}
|
}
|
||||||
16 => {
|
16 => {
|
||||||
@@ -428,7 +424,11 @@ pub fn dc_job_do_DC_JOB_CONFIGURE_IMAP(context: &Context) {
|
|||||||
progress!(context, if success { 1000 } else { 0 });
|
progress!(context, if success { 1000 } else { 0 });
|
||||||
}
|
}
|
||||||
|
|
||||||
fn try_imap_connections(context: &Context, mut param: &mut LoginParam, was_autoconfig: bool) -> bool {
|
fn try_imap_connections(
|
||||||
|
context: &Context,
|
||||||
|
mut param: &mut LoginParam,
|
||||||
|
was_autoconfig: bool,
|
||||||
|
) -> bool {
|
||||||
// progress 650 and 660
|
// progress 650 and 660
|
||||||
if let Some(res) = try_imap_connection(context, &mut param, was_autoconfig, 0) {
|
if let Some(res) = try_imap_connection(context, &mut param, was_autoconfig, 0) {
|
||||||
return res;
|
return res;
|
||||||
@@ -452,7 +452,12 @@ fn try_imap_connections(context: &Context, mut param: &mut LoginParam, was_autoc
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn try_imap_connection(context: &Context, param: &mut LoginParam, was_autoconfig: bool, variation: usize) -> Option<bool> {
|
fn try_imap_connection(
|
||||||
|
context: &Context,
|
||||||
|
param: &mut LoginParam,
|
||||||
|
was_autoconfig: bool,
|
||||||
|
variation: usize,
|
||||||
|
) -> Option<bool> {
|
||||||
if let Some(res) = try_imap_one_param(context, ¶m) {
|
if let Some(res) = try_imap_one_param(context, ¶m) {
|
||||||
return Some(res);
|
return Some(res);
|
||||||
}
|
}
|
||||||
@@ -475,7 +480,8 @@ fn try_imap_connection(context: &Context, param: &mut LoginParam, was_autoconfig
|
|||||||
fn try_imap_one_param(context: &Context, param: &LoginParam) -> Option<bool> {
|
fn try_imap_one_param(context: &Context, param: &LoginParam) -> Option<bool> {
|
||||||
let inf = format!(
|
let inf = format!(
|
||||||
"imap: {}@{}:{} flags=0x{:x}",
|
"imap: {}@{}:{} flags=0x{:x}",
|
||||||
param.mail_user, param.mail_server, param.mail_port, param.server_flags);
|
param.mail_user, param.mail_server, param.mail_port, param.server_flags
|
||||||
|
);
|
||||||
info!(context, "Trying: {}", inf);
|
info!(context, "Trying: {}", inf);
|
||||||
if context.inbox.read().unwrap().connect(context, ¶m) {
|
if context.inbox.read().unwrap().connect(context, ¶m) {
|
||||||
info!(context, "success: {}", inf);
|
info!(context, "success: {}", inf);
|
||||||
@@ -488,10 +494,14 @@ fn try_imap_one_param(context: &Context, param: &LoginParam) -> Option<bool> {
|
|||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
|
||||||
fn try_smtp_connections(context: &Context, mut param: &mut LoginParam, was_autoconfig: bool) -> bool {
|
fn try_smtp_connections(
|
||||||
|
context: &Context,
|
||||||
|
mut param: &mut LoginParam,
|
||||||
|
was_autoconfig: bool,
|
||||||
|
) -> bool {
|
||||||
/* 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 */
|
/* 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 let Some(res) = try_smtp_one_param(context, ¶m) {
|
if let Some(res) = try_smtp_one_param(context, ¶m) {
|
||||||
return res
|
return res;
|
||||||
}
|
}
|
||||||
if was_autoconfig {
|
if was_autoconfig {
|
||||||
return false;
|
return false;
|
||||||
@@ -502,29 +512,36 @@ fn try_smtp_connections(context: &Context, mut param: &mut LoginParam, was_autoc
|
|||||||
param.send_port = 587;
|
param.send_port = 587;
|
||||||
|
|
||||||
if let Some(res) = try_smtp_one_param(context, ¶m) {
|
if let Some(res) = try_smtp_one_param(context, ¶m) {
|
||||||
return res
|
return res;
|
||||||
}
|
}
|
||||||
progress!(context, 860);
|
progress!(context, 860);
|
||||||
param.server_flags &= !(DC_LP_SMTP_SOCKET_FLAGS as i32);
|
param.server_flags &= !(DC_LP_SMTP_SOCKET_FLAGS as i32);
|
||||||
param.server_flags |= DC_LP_SMTP_SOCKET_STARTTLS as i32;
|
param.server_flags |= DC_LP_SMTP_SOCKET_STARTTLS as i32;
|
||||||
param.send_port = 25;
|
param.send_port = 25;
|
||||||
if let Some(res) = try_smtp_one_param(context, ¶m) {
|
if let Some(res) = try_smtp_one_param(context, ¶m) {
|
||||||
return res
|
return res;
|
||||||
}
|
}
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
|
|
||||||
fn try_smtp_one_param(context: &Context, param: &LoginParam, ) -> Option<bool> {
|
fn try_smtp_one_param(context: &Context, param: &LoginParam) -> Option<bool> {
|
||||||
let inf = format!(
|
let inf = format!(
|
||||||
"smtp: {}@{}:{} flags: 0x{:x}",
|
"smtp: {}@{}:{} flags: 0x{:x}",
|
||||||
param.send_user, param.send_server, param.send_port, param.server_flags);
|
param.send_user, param.send_server, param.send_port, param.server_flags
|
||||||
|
);
|
||||||
info!(context, "Trying: {}", inf);
|
info!(context, "Trying: {}", inf);
|
||||||
if context.smtp.clone().lock().unwrap().connect(context, ¶m) {
|
if context
|
||||||
|
.smtp
|
||||||
|
.clone()
|
||||||
|
.lock()
|
||||||
|
.unwrap()
|
||||||
|
.connect(context, ¶m)
|
||||||
|
{
|
||||||
info!(context, "success: {}", inf);
|
info!(context, "success: {}", inf);
|
||||||
return Some(true);
|
return Some(true);
|
||||||
}
|
}
|
||||||
if context.shall_stop_ongoing() {
|
if context.shall_stop_ongoing() {
|
||||||
return Some(false)
|
return Some(false);
|
||||||
}
|
}
|
||||||
info!(context, "could not connect: {}", inf);
|
info!(context, "could not connect: {}", inf);
|
||||||
None
|
None
|
||||||
|
|||||||
Reference in New Issue
Block a user