email/folder/add/
maildir.rs1use async_trait::async_trait;
2use tracing::info;
3
4use super::AddFolder;
5use crate::{folder::error::Error, maildir::MaildirContextSync, AnyResult};
6
7pub struct AddMaildirFolder {
8 ctx: MaildirContextSync,
9}
10
11impl AddMaildirFolder {
12 pub fn new(ctx: &MaildirContextSync) -> Self {
13 Self { ctx: ctx.clone() }
14 }
15
16 pub fn new_boxed(ctx: &MaildirContextSync) -> Box<dyn AddFolder> {
17 Box::new(Self::new(ctx))
18 }
19
20 pub fn some_new_boxed(ctx: &MaildirContextSync) -> Option<Box<dyn AddFolder>> {
21 Some(Self::new_boxed(ctx))
22 }
23}
24
25#[async_trait]
26impl AddFolder for AddMaildirFolder {
27 async fn add_folder(&self, folder: &str) -> AnyResult<()> {
28 info!("creating maildir folder {folder}");
29
30 let ctx = self.ctx.lock().await;
31 let config = &ctx.account_config;
32
33 ctx.root
34 .create(config.get_folder_alias(folder))
35 .map_err(|e| Error::CreateFolderStructureMaildirError(e, ctx.root.path().to_owned()))?;
36
37 Ok(())
38 }
39}