summaryrefslogtreecommitdiff
path: root/src/cmd/add_folder.rs
blob: 0d640af65aaf069e2222e01df07a948abc55b1f5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
use std::fs::create_dir;

use crate::cmd::MailStorage;
use crate::de_jmhoffmann_jwebmail_mailstorage::{AddFolder_Reply_status, Call_AddFolder};

pub fn add_folder(
    ms: &MailStorage,
    call: &mut dyn Call_AddFolder,
    name: String,
) -> varlink::Result<()> {
    if let Some(mut p) = ms.maildir_path.read().unwrap().clone() {
        let mut folder = ".".to_owned();
        folder.push_str(&name);

        p.push(folder);

        if p.is_dir() {
            return call.reply(AddFolder_Reply_status::skiped);
        }

        create_dir(&p).map_err(varlink::map_context!())?;

        p.push("tmp");
        create_dir(&p).map_err(varlink::map_context!())?;

        p.pop();
        p.push("new");
        create_dir(&p).map_err(varlink::map_context!())?;

        p.pop();
        p.push("cur");
        create_dir(p).map_err(varlink::map_context!())?;

        call.reply(AddFolder_Reply_status::created)
    } else {
        call.reply_not_initialized()
    }
}