Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -594,9 +594,9 @@ impl Context {
.quota_needs_update(DC_BACKGROUND_FETCH_QUOTA_CHECK_RATELIMIT)
.await
{
if let Err(err) = self.update_recent_quota(&mut session).await {
warn!(self, "Failed to update quota: {err:#}.");
}
self.update_recent_quota(&mut session)
.await
.context("Failed to update quota")?;
}
}

Expand Down
15 changes: 10 additions & 5 deletions src/quota.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,14 +124,16 @@ impl Context {
/// in case for some providers the quota is always at ~100%
/// and new space is allocated as needed.
pub(crate) async fn update_recent_quota(&self, session: &mut ImapSession) -> Result<()> {
info!(self, "Updating IMAP quota.");

let quota = if session.can_check_quota() {
let folders = get_watched_folders(self).await?;
get_unique_quota_roots_and_usage(session, folders).await
Some(get_unique_quota_roots_and_usage(session, folders).await?)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, does this mean that if a provider erreneously says that it has the quota capability, while it actually does not, connecting to this provider will fail?

Not sure whether this ever happens, but also, not sure whether we should include this right before the release - otoh, it hopefully also fixes a bug.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Before, quota.modified was updated in this case, maybe still do so and then bubble up the error? This way we won't try to update the quota again after reconnecting. This would be closer to the previous behavior

Copy link
Collaborator Author

@link2xt link2xt Jul 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's merge it as is after 2.x releases and see if anyone reports problems. I will try to finish #7014 instead, it should prevent stream reuse after error while still allowing to ignore errors here.

} else {
Err(anyhow!(stock_str::not_supported_by_provider(self).await))
None
};

if let Ok(quota) = &quota {
let recent = if let Some(quota) = &quota {
match get_highest_usage(quota) {
Ok((highest, _, _)) => {
if needs_quota_warning(
Expand All @@ -153,10 +155,13 @@ impl Context {
}
Err(err) => warn!(self, "cannot get highest quota usage: {:#}", err),
}
}
Ok(quota)
} else {
Err(anyhow!(stock_str::not_supported_by_provider(self).await))
};

*self.quota.write().await = Some(QuotaInfo {
recent: quota,
recent: recent.cloned(),
modified: tools::Time::now(),
});

Expand Down
14 changes: 7 additions & 7 deletions src/scheduler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -481,17 +481,17 @@ async fn inbox_fetch_idle(ctx: &Context, imap: &mut Imap, mut session: Session)

// Update quota no more than once a minute.
if ctx.quota_needs_update(60).await {
if let Err(err) = ctx.update_recent_quota(&mut session).await {
warn!(ctx, "Failed to update quota: {:#}.", err);
}
ctx.update_recent_quota(&mut session)
.await
.context("Failed to update quota")?;
}

let resync_requested = ctx.resync_request.swap(false, Ordering::Relaxed);
if resync_requested {
if let Err(err) = session.resync_folders(ctx).await {
warn!(ctx, "Failed to resync folders: {:#}.", err);
ctx.resync_request.store(true, Ordering::Relaxed);
}
session
.resync_folders(ctx)
.await
.context("resync_folders")?;
}

maybe_add_time_based_warnings(ctx).await;
Expand Down
Loading