diff options
author | Jannis M. Hoffmann <jannis@fehcom.de> | 2024-11-17 13:49:11 +0100 |
---|---|---|
committer | Jannis M. Hoffmann <jannis@fehcom.de> | 2024-11-17 13:49:11 +0100 |
commit | 20d247bae690eed12e4edbfbe19c611375314da1 (patch) | |
tree | 27842079f258369b792ca5c38f52f39dcced914f /src/cmd/add_folder.rs | |
parent | 4406d97de9ce88a1f36bc4a33aed6cbd8ba74b44 (diff) |
add "add_folder" command
Diffstat (limited to 'src/cmd/add_folder.rs')
-rw-r--r-- | src/cmd/add_folder.rs | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/src/cmd/add_folder.rs b/src/cmd/add_folder.rs new file mode 100644 index 0000000..1a77c63 --- /dev/null +++ b/src/cmd/add_folder.rs @@ -0,0 +1,37 @@ +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<Vec<u8>> { + 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()) +} |