mirror of
https://github.com/chatmail/core.git
synced 2026-05-08 01:16:31 +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
|
// Inbox is fetched before Mvbox because fetching from Inbox
|
||||||
// may result in moving some messages to Mvbox.
|
// may result in moving some messages to Mvbox.
|
||||||
for folder_meaning in [FolderMeaning::Inbox, FolderMeaning::Mvbox] {
|
for folder_meaning in [FolderMeaning::Inbox, FolderMeaning::Mvbox] {
|
||||||
let (_folder_config, watch_folder) =
|
if let Some((_folder_config, watch_folder)) =
|
||||||
convert_folder_meaning(self, folder_meaning).await?;
|
convert_folder_meaning(self, folder_meaning).await?
|
||||||
connection
|
{
|
||||||
.fetch_move_delete(self, &mut session, &watch_folder, folder_meaning)
|
connection
|
||||||
.await?;
|
.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.
|
// 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
|
/// 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(
|
pub async fn convert_folder_meaning(
|
||||||
ctx: &Context,
|
ctx: &Context,
|
||||||
folder_meaning: FolderMeaning,
|
folder_meaning: FolderMeaning,
|
||||||
) -> Result<(Config, String)> {
|
) -> Result<Option<(Config, String)>> {
|
||||||
let folder_config = match folder_meaning.to_config() {
|
let folder_config = match folder_meaning.to_config() {
|
||||||
Some(c) => c,
|
Some(c) => c,
|
||||||
None => {
|
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 {
|
let folder = ctx
|
||||||
Ok(folder) => folder,
|
.get_config(folder_config)
|
||||||
Err(err) => {
|
.await
|
||||||
bail!(
|
.with_context(|| format!("Failed to retrieve {folder_config} folder"))?;
|
||||||
"Can not watch {} folder, failed to retrieve config: {:#}",
|
|
||||||
folder_config,
|
|
||||||
err
|
|
||||||
);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
let watch_folder = if let Some(watch_folder) = folder {
|
if let Some(watch_folder) = folder {
|
||||||
watch_folder
|
Ok(Some((folder_config, watch_folder)))
|
||||||
} else {
|
} else {
|
||||||
bail!("Can not watch {} folder, not set", folder_config);
|
Ok(None)
|
||||||
};
|
}
|
||||||
|
|
||||||
Ok((folder_config, watch_folder))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn inbox_fetch_idle(ctx: &Context, imap: &mut Imap, mut session: Session) -> Result<Session> {
|
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,
|
mut session: Session,
|
||||||
folder_meaning: FolderMeaning,
|
folder_meaning: FolderMeaning,
|
||||||
) -> Result<Session> {
|
) -> Result<Session> {
|
||||||
let (folder_config, watch_folder) = match convert_folder_meaning(ctx, folder_meaning).await {
|
let Some((folder_config, watch_folder)) = convert_folder_meaning(ctx, folder_meaning).await?
|
||||||
Ok(meaning) => meaning,
|
else {
|
||||||
Err(err) => {
|
// The folder is not configured.
|
||||||
// Warning instead of error because the folder may not be configured.
|
// For example, this happens if the server does not have Sent folder
|
||||||
// For example, this happens if the server does not have Sent folder
|
// but watching Sent folder is enabled.
|
||||||
// but watching Sent folder is enabled.
|
connection.connectivity.set_not_configured(ctx).await;
|
||||||
warn!(ctx, "Error converting IMAP Folder name: {err:#}.");
|
connection.idle_interrupt_receiver.recv().await.ok();
|
||||||
connection.connectivity.set_not_configured(ctx).await;
|
bail!("Cannot fetch folder {folder_meaning} because it is not configured");
|
||||||
connection.idle_interrupt_receiver.recv().await.ok();
|
|
||||||
return Err(err);
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
if folder_config == Config::ConfiguredInboxFolder {
|
if folder_config == Config::ConfiguredInboxFolder {
|
||||||
|
|||||||
Reference in New Issue
Block a user