email/folder/list/
maildir.rs

1use async_trait::async_trait;
2use tracing::info;
3
4use super::ListFolders;
5use crate::{folder::Folders, maildir::MaildirContextSync, AnyResult};
6
7pub struct ListMaildirFolders {
8    ctx: MaildirContextSync,
9}
10
11impl ListMaildirFolders {
12    pub fn new(ctx: &MaildirContextSync) -> Self {
13        Self { ctx: ctx.clone() }
14    }
15
16    pub fn new_boxed(ctx: &MaildirContextSync) -> Box<dyn ListFolders> {
17        Box::new(Self::new(ctx))
18    }
19
20    pub fn some_new_boxed(ctx: &MaildirContextSync) -> Option<Box<dyn ListFolders>> {
21        Some(Self::new_boxed(ctx))
22    }
23}
24
25#[async_trait]
26impl ListFolders for ListMaildirFolders {
27    async fn list_folders(&self) -> AnyResult<Folders> {
28        info!("listing maildir folders");
29
30        let ctx = self.ctx.lock().await;
31        let folders = Folders::from_maildir_context(&ctx);
32
33        Ok(folders.into())
34    }
35}