mirror of
https://github.com/chatmail/core.git
synced 2026-04-17 21:46:35 +03:00
refactor(imap): move list_folders() to Session
This commit is contained in:
@@ -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")?;
|
||||
|
||||
@@ -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<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>> {
|
||||
|
||||
@@ -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<Vec<async_imap::types::Name>> {
|
||||
let list = self.list(Some(""), Some("*")).await?.try_collect().await?;
|
||||
Ok(list)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user