summaryrefslogtreecommitdiff
path: root/src/cmd/add_folder.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/cmd/add_folder.rs')
-rw-r--r--src/cmd/add_folder.rs37
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())
+}