diff options
Diffstat (limited to 'src/cmd/add_folder.rs')
-rw-r--r-- | src/cmd/add_folder.rs | 53 |
1 files changed, 28 insertions, 25 deletions
diff --git a/src/cmd/add_folder.rs b/src/cmd/add_folder.rs index 82df1f9..07ad455 100644 --- a/src/cmd/add_folder.rs +++ b/src/cmd/add_folder.rs @@ -1,37 +1,40 @@ use std::fs::create_dir; -use std::path::PathBuf; -use protobuf::Message as _; +use varlink; -use crate::error::Result; -use crate::pb3::jwebmail::{AddFolderReq, AddFolderResp}; +use crate::cmd::MailStorage; +use crate::de_jmhoffmann_jwebmail_mailstorage::{AddFolder_Reply_status, Call_AddFolder}; -pub fn add_folder(mut p: PathBuf, req: &[u8]) -> Result<Vec<u8>> { - let r = AddFolderReq::parse_from_bytes(req)?; - let mut resp = AddFolderResp::new(); +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); - let mut folder = ".".to_owned(); - folder.push_str(&r.name); - p.push(folder); + p.push(folder); - if p.is_dir() { - resp.status = 1; - return resp.write_to_bytes().map_err(|e| e.into()); - } + if p.is_dir() { + return call.reply(AddFolder_Reply_status::skiped); + } - create_dir(&p)?; + create_dir(&p).map_err(varlink::map_context!())?; - p.push("tmp"); - create_dir(&p)?; + p.push("tmp"); + create_dir(&p).map_err(varlink::map_context!())?; - p.pop(); - p.push("new"); - create_dir(&p)?; + p.pop(); + p.push("new"); + create_dir(&p).map_err(varlink::map_context!())?; - p.pop(); - p.push("cur"); - create_dir(p)?; + p.pop(); + p.push("cur"); + create_dir(p).map_err(varlink::map_context!())?; - resp.status = 0; - resp.write_to_bytes().map_err(|e| e.into()) + call.reply(AddFolder_Reply_status::created) + } else { + call.reply_not_initialized() + } } |