mirror of
https://github.com/chatmail/core.git
synced 2026-04-17 21:46:35 +03:00
refactor: move convert folder meaning logic in own method
also unify the error handling for the cases where it can go wrong.
This commit is contained in:
@@ -477,6 +477,39 @@ async fn inbox_loop(
|
|||||||
.await;
|
.await;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Convert folder meaning
|
||||||
|
/// used internally by [fetch_idle] and [Context::background_fetch]
|
||||||
|
pub async fn convert_folder_meaning(
|
||||||
|
ctx: &Context,
|
||||||
|
folder_meaning: FolderMeaning,
|
||||||
|
) -> Result<(Config, String)> {
|
||||||
|
let folder_config = match folder_meaning.to_config() {
|
||||||
|
Some(c) => c,
|
||||||
|
None => {
|
||||||
|
bail!("Bad folder meaning: {}", folder_meaning);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
let folder = match ctx.get_config(folder_config).await {
|
||||||
|
Ok(folder) => folder,
|
||||||
|
Err(err) => {
|
||||||
|
bail!(
|
||||||
|
"Can not watch {} folder, failed to retrieve config: {:#}",
|
||||||
|
folder_config,
|
||||||
|
err
|
||||||
|
);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
let watch_folder = if let Some(watch_folder) = folder {
|
||||||
|
watch_folder
|
||||||
|
} else {
|
||||||
|
bail!("Can not watch {} folder, not set", folder_config);
|
||||||
|
};
|
||||||
|
|
||||||
|
Ok((folder_config, watch_folder))
|
||||||
|
}
|
||||||
|
|
||||||
/// Implement a single iteration of IMAP loop.
|
/// Implement a single iteration of IMAP loop.
|
||||||
///
|
///
|
||||||
/// This function performs all IMAP operations on a single folder, selecting it if necessary and
|
/// This function performs all IMAP operations on a single folder, selecting it if necessary and
|
||||||
@@ -484,40 +517,17 @@ async fn inbox_loop(
|
|||||||
/// critical operation fails such as fetching new messages fails, connection is reset via
|
/// critical operation fails such as fetching new messages fails, connection is reset via
|
||||||
/// `trigger_reconnect`, so a fresh one can be opened.
|
/// `trigger_reconnect`, so a fresh one can be opened.
|
||||||
async fn fetch_idle(ctx: &Context, connection: &mut Imap, folder_meaning: FolderMeaning) {
|
async fn fetch_idle(ctx: &Context, connection: &mut Imap, folder_meaning: FolderMeaning) {
|
||||||
let folder_config = match folder_meaning.to_config() {
|
let (folder_config, watch_folder) = match convert_folder_meaning(ctx, folder_meaning).await {
|
||||||
Some(c) => c,
|
Ok(meaning) => meaning,
|
||||||
None => {
|
Err(error) => {
|
||||||
error!(ctx, "Bad folder meaning: {}", folder_meaning);
|
error!(ctx, "Error converting IMAP Folder name: {:?}", error);
|
||||||
|
connection.connectivity.set_not_configured(ctx).await;
|
||||||
connection
|
connection
|
||||||
.fake_idle(ctx, None, FolderMeaning::Unknown)
|
.fake_idle(ctx, None, FolderMeaning::Unknown)
|
||||||
.await;
|
.await;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
let folder = match ctx.get_config(folder_config).await {
|
|
||||||
Ok(folder) => folder,
|
|
||||||
Err(err) => {
|
|
||||||
warn!(
|
|
||||||
ctx,
|
|
||||||
"Can not watch {} folder, failed to retrieve config: {:#}", folder_config, err
|
|
||||||
);
|
|
||||||
connection
|
|
||||||
.fake_idle(ctx, None, FolderMeaning::Unknown)
|
|
||||||
.await;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
let watch_folder = if let Some(watch_folder) = folder {
|
|
||||||
watch_folder
|
|
||||||
} else {
|
|
||||||
connection.connectivity.set_not_configured(ctx).await;
|
|
||||||
info!(ctx, "Can not watch {} folder, not set", folder_config);
|
|
||||||
connection
|
|
||||||
.fake_idle(ctx, None, FolderMeaning::Unknown)
|
|
||||||
.await;
|
|
||||||
return;
|
|
||||||
};
|
|
||||||
|
|
||||||
// connect and fake idle if unable to connect
|
// connect and fake idle if unable to connect
|
||||||
if let Err(err) = connection
|
if let Err(err) = connection
|
||||||
|
|||||||
Reference in New Issue
Block a user