refactor(imap): move resync_folders() to Session

This commit is contained in:
link2xt
2024-02-28 22:26:25 +00:00
parent 7bc2f0cb6b
commit 2a0a05d03c
2 changed files with 13 additions and 11 deletions

View File

@@ -789,29 +789,25 @@ impl Imap {
info!(context, "Done fetching existing messages."); info!(context, "Done fetching existing messages.");
Ok(()) Ok(())
} }
}
impl Session {
/// Synchronizes UIDs for all folders. /// Synchronizes UIDs for all folders.
pub(crate) async fn resync_folders(&mut self, context: &Context) -> Result<()> { pub(crate) async fn resync_folders(&mut self, context: &Context) -> Result<()> {
self.prepare(context).await?; let all_folders = self
let session = self.session.as_mut().context("No IMAP session")?;
let all_folders = session
.list_folders() .list_folders()
.await .await
.context("listing folders for resync")?; .context("listing folders for resync")?;
for folder in all_folders { for folder in all_folders {
let folder_meaning = get_folder_meaning(&folder); let folder_meaning = get_folder_meaning(&folder);
if folder_meaning != FolderMeaning::Virtual { if folder_meaning != FolderMeaning::Virtual {
session self.resync_folder_uids(context, folder.name(), folder_meaning)
.resync_folder_uids(context, folder.name(), folder_meaning)
.await?; .await?;
} }
} }
Ok(()) Ok(())
} }
}
impl Session {
/// Synchronizes UIDs in the database with UIDs on the server. /// Synchronizes UIDs in the database with UIDs on the server.
/// ///
/// It is assumed that no operations are taking place on the same /// It is assumed that no operations are taking place on the same

View File

@@ -393,6 +393,10 @@ async fn inbox_loop(
}; };
loop { loop {
if let Err(err) = connection.prepare(&ctx).await {
warn!(ctx, "Failed to prepare connection: {:#}.", err);
}
{ {
// Update quota no more than once a minute. // Update quota no more than once a minute.
let quota_needs_update = { let quota_needs_update = {
@@ -412,9 +416,11 @@ async fn inbox_loop(
let resync_requested = ctx.resync_request.swap(false, Ordering::Relaxed); let resync_requested = ctx.resync_request.swap(false, Ordering::Relaxed);
if resync_requested { if resync_requested {
if let Err(err) = connection.resync_folders(&ctx).await { if let Some(session) = connection.session.as_mut() {
warn!(ctx, "Failed to resync folders: {:#}.", err); if let Err(err) = session.resync_folders(&ctx).await {
ctx.resync_request.store(true, Ordering::Relaxed); warn!(ctx, "Failed to resync folders: {:#}.", err);
ctx.resync_request.store(true, Ordering::Relaxed);
}
} }
} }