use std::fs::create_dir; use std::path::PathBuf; use protobuf::Message as _; use crate::error::Result; use crate::pb3::jwebmail::{AddFolderReq, AddFolderResp}; pub fn add_folder(mut p: PathBuf, req: &[u8]) -> Result> { let r = AddFolderReq::parse_from_bytes(req)?; let mut resp = AddFolderResp::new(); let mut folder = ".".to_owned(); folder.push_str(&r.name); p.push(folder); if p.is_dir() { resp.status = 1; return resp.write_to_bytes().map_err(|e| e.into()); } create_dir(p.clone())?; p.push("tmp"); create_dir(p.clone())?; p.pop(); p.push("new"); create_dir(p.clone())?; p.pop(); p.push("cur"); create_dir(p)?; resp.status = 0; resp.write_to_bytes().map_err(|e| e.into()) }