mirror of
https://github.com/chatmail/core.git
synced 2026-05-19 06:46:32 +03:00
imap: resultify Imap.connect
This commit is contained in:
committed by
link2xt
parent
0b743c6bc3
commit
dd682e87db
@@ -445,12 +445,12 @@ async fn try_imap_one_param(
|
|||||||
);
|
);
|
||||||
info!(context, "Trying: {}", inf);
|
info!(context, "Trying: {}", inf);
|
||||||
|
|
||||||
if imap.connect(context, param, addr, oauth2).await {
|
if let Err(err) = imap.connect(context, param, addr, oauth2).await {
|
||||||
|
info!(context, "failure: {}", err);
|
||||||
|
false
|
||||||
|
} else {
|
||||||
info!(context, "success: {}", inf);
|
info!(context, "success: {}", inf);
|
||||||
true
|
true
|
||||||
} else {
|
|
||||||
info!(context, "failure: {}", inf);
|
|
||||||
false
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -330,7 +330,7 @@ impl Imap {
|
|||||||
let param = LoginParam::from_database(context, "configured_").await;
|
let param = LoginParam::from_database(context, "configured_").await;
|
||||||
// the trailing underscore is correct
|
// the trailing underscore is correct
|
||||||
|
|
||||||
if self
|
if let Err(err) = self
|
||||||
.connect(
|
.connect(
|
||||||
context,
|
context,
|
||||||
¶m.imap,
|
¶m.imap,
|
||||||
@@ -339,9 +339,9 @@ impl Imap {
|
|||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
{
|
{
|
||||||
self.ensure_configured_folders(context, true).await
|
bail!("IMAP Connection Failed with params {}: {}", param, err);
|
||||||
} else {
|
} else {
|
||||||
bail!("IMAP Connection Failed params: {}", param);
|
self.ensure_configured_folders(context, true).await
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -354,9 +354,9 @@ impl Imap {
|
|||||||
lp: &ServerLoginParam,
|
lp: &ServerLoginParam,
|
||||||
addr: &str,
|
addr: &str,
|
||||||
oauth2: bool,
|
oauth2: bool,
|
||||||
) -> bool {
|
) -> Result<()> {
|
||||||
if lp.server.is_empty() || lp.user.is_empty() || lp.password.is_empty() {
|
if lp.server.is_empty() || lp.user.is_empty() || lp.password.is_empty() {
|
||||||
return false;
|
bail!("Incomplete IMAP connection parameters");
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
@@ -378,7 +378,7 @@ impl Imap {
|
|||||||
if let Err(err) = self.setup_handle_if_needed(context).await {
|
if let Err(err) = self.setup_handle_if_needed(context).await {
|
||||||
warn!(context, "failed to setup imap handle: {}", err);
|
warn!(context, "failed to setup imap handle: {}", err);
|
||||||
self.free_connect_params().await;
|
self.free_connect_params().await;
|
||||||
return false;
|
return Err(err);
|
||||||
}
|
}
|
||||||
|
|
||||||
let teardown = match &mut self.session {
|
let teardown = match &mut self.session {
|
||||||
@@ -422,10 +422,9 @@ impl Imap {
|
|||||||
if teardown {
|
if teardown {
|
||||||
self.disconnect(context).await;
|
self.disconnect(context).await;
|
||||||
|
|
||||||
false
|
bail!("IMAP disconnected immediately after connecting due to error");
|
||||||
} else {
|
|
||||||
true
|
|
||||||
}
|
}
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn disconnect(&mut self, context: &Context) {
|
pub async fn disconnect(&mut self, context: &Context) {
|
||||||
|
|||||||
Reference in New Issue
Block a user