refactor(imap): move list_folders() to Session

This commit is contained in:
link2xt
2024-02-28 21:40:22 +00:00
parent 08a30031eb
commit d4a505b52e
3 changed files with 12 additions and 15 deletions

View File

@@ -1014,7 +1014,8 @@ impl Imap {
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?; 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")?;

View File

@@ -1,7 +1,6 @@
use std::collections::BTreeMap; use std::collections::BTreeMap;
use anyhow::{Context as _, Result}; use anyhow::{Context as _, Result};
use futures::TryStreamExt;
use super::{get_folder_meaning_by_attrs, get_folder_meaning_by_name}; use super::{get_folder_meaning_by_attrs, get_folder_meaning_by_name};
use crate::config::Config; use crate::config::Config;
@@ -28,7 +27,8 @@ impl Imap {
info!(context, "Starting full folder scan"); info!(context, "Starting full folder scan");
self.prepare(context).await?; 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 watched_folders = get_watched_folders(context).await?;
let mut folder_configs = BTreeMap::new(); let mut folder_configs = BTreeMap::new();
@@ -97,18 +97,6 @@ impl Imap {
last_scan.replace(tools::Time::now()); last_scan.replace(tools::Time::now());
Ok(true) Ok(true)
} }
/// Returns the names of all folders on the IMAP server.
pub async fn list_folders(self: &mut Imap) -> Result<Vec<async_imap::types::Name>> {
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<Vec<Config>> { pub(crate) async fn get_watched_folder_configs(context: &Context) -> Result<Vec<Config>> {

View File

@@ -1,7 +1,9 @@
use std::ops::{Deref, DerefMut}; use std::ops::{Deref, DerefMut};
use anyhow::Result;
use async_imap::types::Mailbox; use async_imap::types::Mailbox;
use async_imap::Session as ImapSession; use async_imap::Session as ImapSession;
use futures::TryStreamExt;
use crate::imap::capabilities::Capabilities; use crate::imap::capabilities::Capabilities;
use crate::net::session::SessionStream; use crate::net::session::SessionStream;
@@ -68,4 +70,10 @@ impl Session {
pub fn can_metadata(&self) -> bool { pub fn can_metadata(&self) -> bool {
self.capabilities.can_metadata self.capabilities.can_metadata
} }
/// Returns the names of all folders on the IMAP server.
pub async fn list_folders(&mut self) -> Result<Vec<async_imap::types::Name>> {
let list = self.list(Some(""), Some("*")).await?.try_collect().await?;
Ok(list)
}
} }