mirror of
https://github.com/chatmail/core.git
synced 2026-05-09 01:46:30 +03:00
Make Imap.connect() async
This commit is contained in:
@@ -6,6 +6,8 @@ mod read_url;
|
|||||||
|
|
||||||
use percent_encoding::{utf8_percent_encode, NON_ALPHANUMERIC};
|
use percent_encoding::{utf8_percent_encode, NON_ALPHANUMERIC};
|
||||||
|
|
||||||
|
use async_std::task;
|
||||||
|
|
||||||
use crate::config::Config;
|
use crate::config::Config;
|
||||||
use crate::constants::*;
|
use crate::constants::*;
|
||||||
use crate::context::Context;
|
use crate::context::Context;
|
||||||
@@ -540,12 +542,12 @@ fn try_imap_one_param(context: &Context, param: &LoginParam) -> Option<bool> {
|
|||||||
param.imap_certificate_checks
|
param.imap_certificate_checks
|
||||||
);
|
);
|
||||||
info!(context, "Trying: {}", inf);
|
info!(context, "Trying: {}", inf);
|
||||||
if context
|
if task::block_on(context
|
||||||
.inbox_thread
|
.inbox_thread
|
||||||
.read()
|
.read()
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.imap
|
.imap
|
||||||
.connect(context, ¶m)
|
.connect(context, ¶m))
|
||||||
{
|
{
|
||||||
info!(context, "success: {}", inf);
|
info!(context, "success: {}", inf);
|
||||||
return Some(true);
|
return Some(true);
|
||||||
|
|||||||
@@ -339,7 +339,7 @@ impl Imap {
|
|||||||
let param = LoginParam::from_database(context, "configured_");
|
let param = LoginParam::from_database(context, "configured_");
|
||||||
// the trailing underscore is correct
|
// the trailing underscore is correct
|
||||||
|
|
||||||
if self.connect(context, ¶m) {
|
if task::block_on(self.connect(context, ¶m)) {
|
||||||
self.ensure_configured_folders(context, true)
|
self.ensure_configured_folders(context, true)
|
||||||
} else {
|
} else {
|
||||||
Err(Error::ConnectionFailed(format!("{}", param)))
|
Err(Error::ConnectionFailed(format!("{}", param)))
|
||||||
@@ -348,8 +348,7 @@ impl Imap {
|
|||||||
|
|
||||||
/// tries connecting to imap account using the specific login
|
/// tries connecting to imap account using the specific login
|
||||||
/// parameters
|
/// parameters
|
||||||
pub fn connect(&self, context: &Context, lp: &LoginParam) -> bool {
|
pub async fn connect(&self, context: &Context, lp: &LoginParam) -> bool {
|
||||||
task::block_on(async move {
|
|
||||||
if lp.mail_server.is_empty() || lp.mail_user.is_empty() || lp.mail_pw.is_empty() {
|
if lp.mail_server.is_empty() || lp.mail_user.is_empty() || lp.mail_pw.is_empty() {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -423,7 +422,6 @@ impl Imap {
|
|||||||
} else {
|
} else {
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn disconnect(&self, context: &Context) {
|
pub fn disconnect(&self, context: &Context) {
|
||||||
|
|||||||
Reference in New Issue
Block a user