diff --git a/src/imap.rs b/src/imap.rs index 4da64b385..f014d5d68 100644 --- a/src/imap.rs +++ b/src/imap.rs @@ -1014,7 +1014,8 @@ impl Imap { 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() .await .context("listing folders for resync")?; diff --git a/src/imap/scan_folders.rs b/src/imap/scan_folders.rs index 15aac412b..d5f76453b 100644 --- a/src/imap/scan_folders.rs +++ b/src/imap/scan_folders.rs @@ -1,7 +1,6 @@ use std::collections::BTreeMap; use anyhow::{Context as _, Result}; -use futures::TryStreamExt; use super::{get_folder_meaning_by_attrs, get_folder_meaning_by_name}; use crate::config::Config; @@ -28,7 +27,8 @@ impl Imap { info!(context, "Starting full folder scan"); self.prepare(context).await?; - let folders = self.list_folders().await?; + let session = self.session.as_mut().context("No IMAP session")?; + let folders = session.list_folders().await?; let watched_folders = get_watched_folders(context).await?; let mut folder_configs = BTreeMap::new(); @@ -97,18 +97,6 @@ impl Imap { last_scan.replace(tools::Time::now()); Ok(true) } - - /// Returns the names of all folders on the IMAP server. - pub async fn list_folders(self: &mut Imap) -> Result> { - let session = self.session.as_mut(); - let session = session.context("No IMAP connection")?; - let list = session - .list(Some(""), Some("*")) - .await? - .try_collect() - .await?; - Ok(list) - } } pub(crate) async fn get_watched_folder_configs(context: &Context) -> Result> { diff --git a/src/imap/session.rs b/src/imap/session.rs index 1e2b5fc7a..e3058987f 100644 --- a/src/imap/session.rs +++ b/src/imap/session.rs @@ -1,7 +1,9 @@ use std::ops::{Deref, DerefMut}; +use anyhow::Result; use async_imap::types::Mailbox; use async_imap::Session as ImapSession; +use futures::TryStreamExt; use crate::imap::capabilities::Capabilities; use crate::net::session::SessionStream; @@ -68,4 +70,10 @@ impl Session { pub fn can_metadata(&self) -> bool { self.capabilities.can_metadata } + + /// Returns the names of all folders on the IMAP server. + pub async fn list_folders(&mut self) -> Result> { + let list = self.list(Some(""), Some("*")).await?.try_collect().await?; + Ok(list) + } }