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 | |
parent | 4406d97de9ce88a1f36bc4a33aed6cbd8ba74b44 (diff) |
add "add_folder" command
Diffstat (limited to 'src')
-rw-r--r-- | src/arguments.rs | 1 | ||||
-rw-r--r-- | src/cmd.rs | 2 | ||||
-rw-r--r-- | src/cmd/add_folder.rs | 37 | ||||
-rw-r--r-- | src/main.rs | 3 |
4 files changed, 42 insertions, 1 deletions
diff --git a/src/arguments.rs b/src/arguments.rs index c017744..a944abe 100644 --- a/src/arguments.rs +++ b/src/arguments.rs @@ -12,6 +12,7 @@ pub enum Mode { Folders, Move, Remove, + AddFolder, } #[derive(Parser)] @@ -2,6 +2,7 @@ use std::path::PathBuf; use maildir::Maildir; +mod add_folder; mod count; mod folders; mod list; @@ -10,6 +11,7 @@ mod raw; mod read; mod remove; +pub use add_folder::add_folder; pub use count::count; pub use folders::folders; pub use list::list; 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()) +} diff --git a/src/main.rs b/src/main.rs index f9ba899..5598b30 100644 --- a/src/main.rs +++ b/src/main.rs @@ -69,8 +69,9 @@ fn main() -> Result<()> { //Mode::Search => cmd::search(&path, &req), Mode::Move => cmd::move_mail(path, &req), Mode::Remove => cmd::remove(path, &req), + Mode::AddFolder => cmd::add_folder(path, &req), _ => todo!(), }?; - stdout().write(&res).map(|_| ()).map_err(|e| e.into()) + stdout().write_all(&res).map_err(|e| e.into()) } |