mirror of
https://github.com/chatmail/core.git
synced 2026-04-17 21:46:35 +03:00
fix: skip unconfigured folders in background_fetch()
Otherwise `background_fetch()` fails on unconfigured Mvbox, which is typical for chatmail accounts, and does not get to checking QUOTA ever.
This commit is contained in:
@@ -561,11 +561,13 @@ impl Context {
|
||||
// Inbox is fetched before Mvbox because fetching from Inbox
|
||||
// may result in moving some messages to Mvbox.
|
||||
for folder_meaning in [FolderMeaning::Inbox, FolderMeaning::Mvbox] {
|
||||
let (_folder_config, watch_folder) =
|
||||
convert_folder_meaning(self, folder_meaning).await?;
|
||||
connection
|
||||
.fetch_move_delete(self, &mut session, &watch_folder, folder_meaning)
|
||||
.await?;
|
||||
if let Some((_folder_config, watch_folder)) =
|
||||
convert_folder_meaning(self, folder_meaning).await?
|
||||
{
|
||||
connection
|
||||
.fetch_move_delete(self, &mut session, &watch_folder, folder_meaning)
|
||||
.await?;
|
||||
}
|
||||
}
|
||||
|
||||
// Update quota (to send warning if full) - but only check it once in a while.
|
||||
|
||||
@@ -433,36 +433,33 @@ async fn inbox_loop(
|
||||
}
|
||||
|
||||
/// Convert folder meaning
|
||||
/// used internally by [fetch_idle] and [Context::background_fetch]
|
||||
/// used internally by [fetch_idle] and [Context::background_fetch].
|
||||
///
|
||||
/// Returns folder configuration key and folder name
|
||||
/// if such folder is configured, `Ok(None)` otherwise.
|
||||
pub async fn convert_folder_meaning(
|
||||
ctx: &Context,
|
||||
folder_meaning: FolderMeaning,
|
||||
) -> Result<(Config, String)> {
|
||||
) -> Result<Option<(Config, String)>> {
|
||||
let folder_config = match folder_meaning.to_config() {
|
||||
Some(c) => c,
|
||||
None => {
|
||||
bail!("Bad folder meaning: {}", folder_meaning);
|
||||
// Such folder cannot be configured,
|
||||
// e.g. a `FolderMeaning::Spam` folder.
|
||||
return Ok(None);
|
||||
}
|
||||
};
|
||||
|
||||
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 folder = ctx
|
||||
.get_config(folder_config)
|
||||
.await
|
||||
.with_context(|| format!("Failed to retrieve {folder_config} folder"))?;
|
||||
|
||||
let watch_folder = if let Some(watch_folder) = folder {
|
||||
watch_folder
|
||||
if let Some(watch_folder) = folder {
|
||||
Ok(Some((folder_config, watch_folder)))
|
||||
} else {
|
||||
bail!("Can not watch {} folder, not set", folder_config);
|
||||
};
|
||||
|
||||
Ok((folder_config, watch_folder))
|
||||
Ok(None)
|
||||
}
|
||||
}
|
||||
|
||||
async fn inbox_fetch_idle(ctx: &Context, imap: &mut Imap, mut session: Session) -> Result<Session> {
|
||||
@@ -554,17 +551,14 @@ async fn fetch_idle(
|
||||
mut session: Session,
|
||||
folder_meaning: FolderMeaning,
|
||||
) -> Result<Session> {
|
||||
let (folder_config, watch_folder) = match convert_folder_meaning(ctx, folder_meaning).await {
|
||||
Ok(meaning) => meaning,
|
||||
Err(err) => {
|
||||
// Warning instead of error because the folder may not be configured.
|
||||
// For example, this happens if the server does not have Sent folder
|
||||
// but watching Sent folder is enabled.
|
||||
warn!(ctx, "Error converting IMAP Folder name: {err:#}.");
|
||||
connection.connectivity.set_not_configured(ctx).await;
|
||||
connection.idle_interrupt_receiver.recv().await.ok();
|
||||
return Err(err);
|
||||
}
|
||||
let Some((folder_config, watch_folder)) = convert_folder_meaning(ctx, folder_meaning).await?
|
||||
else {
|
||||
// The folder is not configured.
|
||||
// For example, this happens if the server does not have Sent folder
|
||||
// but watching Sent folder is enabled.
|
||||
connection.connectivity.set_not_configured(ctx).await;
|
||||
connection.idle_interrupt_receiver.recv().await.ok();
|
||||
bail!("Cannot fetch folder {folder_meaning} because it is not configured");
|
||||
};
|
||||
|
||||
if folder_config == Config::ConfiguredInboxFolder {
|
||||
|
||||
Reference in New Issue
Block a user