mirror of
https://github.com/chatmail/core.git
synced 2026-05-07 08:56:30 +03:00
wip
This commit is contained in:
@@ -46,17 +46,23 @@ pub fn dc_is_configured(context: &Context) -> bool {
|
|||||||
// 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 mut success = false;
|
|
||||||
let mut imap_connected_here = false;
|
|
||||||
let mut smtp_connected_here = false;
|
|
||||||
let mut ongoing_allocated_here = false;
|
|
||||||
|
|
||||||
let mut param_autoconfig: Option<LoginParam> = None;
|
|
||||||
if dc_alloc_ongoing(context) {
|
if !dc_alloc_ongoing(context) {
|
||||||
ongoing_allocated_here = true;
|
progress!(context, 0);
|
||||||
if !context.sql.is_open() {
|
return;
|
||||||
error!(context, "Cannot configure, database not opened.",);
|
}
|
||||||
} else {
|
if !context.sql.is_open() {
|
||||||
|
error!(context, "Cannot configure, database not opened.",);
|
||||||
|
progress!(context, 0);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
let mut success = false;
|
||||||
|
let mut imap_connected_here = false;
|
||||||
|
let mut smtp_connected_here = false;
|
||||||
|
let mut param_autoconfig: Option<LoginParam> = None;
|
||||||
|
|
||||||
context.inbox.read().unwrap().disconnect(context);
|
context.inbox.read().unwrap().disconnect(context);
|
||||||
context
|
context
|
||||||
.sentbox_thread
|
.sentbox_thread
|
||||||
@@ -339,26 +345,18 @@ pub unsafe fn dc_job_do_DC_JOB_CONFIGURE_IMAP(context: &Context, _job: &Job) {
|
|||||||
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 */
|
||||||
let ok_to_continue8;
|
for username_variation in 0..2 {
|
||||||
let mut username_variation = 0;
|
|
||||||
loop {
|
|
||||||
if !(username_variation <= 1) {
|
|
||||||
ok_to_continue8 = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
info!(context, "Trying: {}", ¶m);
|
info!(context, "Trying: {}", ¶m);
|
||||||
|
|
||||||
if context.inbox.read().unwrap().connect(context, ¶m) {
|
if context.inbox.read().unwrap().connect(context, ¶m) {
|
||||||
ok_to_continue8 = true;
|
imap_connected_here = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if !param_autoconfig.is_none() {
|
if param_autoconfig.is_some() {
|
||||||
ok_to_continue8 = false;
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
// probe STARTTLS/993
|
// probe STARTTLS/993
|
||||||
if s.shall_stop_ongoing {
|
if s.shall_stop_ongoing {
|
||||||
ok_to_continue8 = false;
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
progress!(context, 650 + username_variation * 30);
|
progress!(context, 650 + username_variation * 30);
|
||||||
@@ -367,12 +365,11 @@ pub unsafe fn dc_job_do_DC_JOB_CONFIGURE_IMAP(context: &Context, _job: &Job) {
|
|||||||
info!(context, "Trying: {}", ¶m);
|
info!(context, "Trying: {}", ¶m);
|
||||||
|
|
||||||
if context.inbox.read().unwrap().connect(context, ¶m) {
|
if context.inbox.read().unwrap().connect(context, ¶m) {
|
||||||
ok_to_continue8 = true;
|
imap_connected_here = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
// probe STARTTLS/143
|
// probe STARTTLS/143
|
||||||
if s.shall_stop_ongoing {
|
if s.shall_stop_ongoing {
|
||||||
ok_to_continue8 = false;
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
progress!(context, 660 + username_variation * 30);
|
progress!(context, 660 + username_variation * 30);
|
||||||
@@ -380,16 +377,14 @@ pub unsafe fn dc_job_do_DC_JOB_CONFIGURE_IMAP(context: &Context, _job: &Job) {
|
|||||||
info!(context, "Trying: {}", ¶m);
|
info!(context, "Trying: {}", ¶m);
|
||||||
|
|
||||||
if context.inbox.read().unwrap().connect(context, ¶m) {
|
if context.inbox.read().unwrap().connect(context, ¶m) {
|
||||||
ok_to_continue8 = true;
|
imap_connected_here = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if 0 != username_variation {
|
if username_variation > 0 {
|
||||||
ok_to_continue8 = false;
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
// next probe round with only the localpart of the email-address as the loginname
|
// next probe round with only the localpart of the email-address as the loginname
|
||||||
if s.shall_stop_ongoing {
|
if s.shall_stop_ongoing {
|
||||||
ok_to_continue8 = false;
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
progress!(context, 670 + username_variation * 30);
|
progress!(context, 670 + username_variation * 30);
|
||||||
@@ -403,18 +398,11 @@ pub unsafe fn dc_job_do_DC_JOB_CONFIGURE_IMAP(context: &Context, _job: &Job) {
|
|||||||
if let Some(at) = param.send_user.find('@') {
|
if let Some(at) = param.send_user.find('@') {
|
||||||
param.send_user = param.send_user.split_at(at).0.to_string();
|
param.send_user = param.send_user.split_at(at).0.to_string();
|
||||||
}
|
}
|
||||||
|
|
||||||
username_variation += 1
|
|
||||||
}
|
}
|
||||||
if ok_to_continue8 {
|
imap_connected_here
|
||||||
// success, so we are connected and should disconnect in cleanup
|
|
||||||
imap_connected_here = true;
|
|
||||||
}
|
|
||||||
ok_to_continue8
|
|
||||||
}
|
}
|
||||||
15 => {
|
15 => {
|
||||||
progress!(context, 800);
|
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 */
|
/* 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
|
if !context
|
||||||
.smtp
|
.smtp
|
||||||
@@ -423,11 +411,7 @@ pub unsafe fn dc_job_do_DC_JOB_CONFIGURE_IMAP(context: &Context, _job: &Job) {
|
|||||||
.unwrap()
|
.unwrap()
|
||||||
.connect(context, ¶m)
|
.connect(context, ¶m)
|
||||||
{
|
{
|
||||||
if !param_autoconfig.is_none() {
|
if param_autoconfig.is_none() && !s.shall_stop_ongoing {
|
||||||
success = false;
|
|
||||||
} else if s.shall_stop_ongoing {
|
|
||||||
success = false;
|
|
||||||
} else {
|
|
||||||
progress!(context, 850);
|
progress!(context, 850);
|
||||||
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;
|
||||||
@@ -441,38 +425,31 @@ pub unsafe fn dc_job_do_DC_JOB_CONFIGURE_IMAP(context: &Context, _job: &Job) {
|
|||||||
.unwrap()
|
.unwrap()
|
||||||
.connect(context, ¶m)
|
.connect(context, ¶m)
|
||||||
{
|
{
|
||||||
if s.shall_stop_ongoing {
|
if !s.shall_stop_ongoing {
|
||||||
success = false;
|
|
||||||
} else {
|
|
||||||
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;
|
||||||
info!(context, "Trying: {}", ¶m);
|
info!(context, "Trying: {}", ¶m);
|
||||||
|
|
||||||
if !context
|
if context
|
||||||
.smtp
|
.smtp
|
||||||
.clone()
|
.clone()
|
||||||
.lock()
|
.lock()
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.connect(context, ¶m)
|
.connect(context, ¶m)
|
||||||
{
|
{
|
||||||
success = false;
|
smtp_connected_here = true;
|
||||||
} else {
|
|
||||||
success = true;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
success = true;
|
smtp_connected_here = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
success = true;
|
|
||||||
}
|
|
||||||
if success {
|
|
||||||
smtp_connected_here = true;
|
smtp_connected_here = true;
|
||||||
}
|
}
|
||||||
success
|
smtp_connected_here
|
||||||
}
|
}
|
||||||
16 => {
|
16 => {
|
||||||
progress!(context, 900);
|
progress!(context, 900);
|
||||||
@@ -532,8 +509,6 @@ pub unsafe fn dc_job_do_DC_JOB_CONFIGURE_IMAP(context: &Context, _job: &Job) {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
if imap_connected_here {
|
if imap_connected_here {
|
||||||
context.inbox.read().unwrap().disconnect(context);
|
context.inbox.read().unwrap().disconnect(context);
|
||||||
}
|
}
|
||||||
@@ -558,9 +533,7 @@ pub unsafe fn dc_job_do_DC_JOB_CONFIGURE_IMAP(context: &Context, _job: &Job) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
if ongoing_allocated_here {
|
dc_free_ongoing(context);
|
||||||
dc_free_ongoing(context);
|
|
||||||
}
|
|
||||||
|
|
||||||
progress!(context, if success { 1000 } else { 0 });
|
progress!(context, if success { 1000 } else { 0 });
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user