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 | |
parent | 4406d97de9ce88a1f36bc4a33aed6cbd8ba74b44 (diff) |
add "add_folder" command
-rw-r--r-- | Cargo.lock | 2 | ||||
-rw-r--r-- | Cargo.toml | 2 | ||||
-rw-r--r-- | jwebmail.proto | 9 | ||||
-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 |
7 files changed, 53 insertions, 3 deletions
@@ -335,7 +335,7 @@ dependencies = [ [[package]] name = "jwebmail-extract" -version = "0.7.0" +version = "0.8.0" dependencies = [ "anyhow", "chrono", @@ -1,6 +1,6 @@ [package] name = "jwebmail-extract" -version = "0.7.0" +version = "0.8.0" authors = ["Jannis M. Hoffmann <jannis@fehcom.de>"] edition = "2021" rust-version = "1.80" diff --git a/jwebmail.proto b/jwebmail.proto index bf1454a..e4cba3b 100644 --- a/jwebmail.proto +++ b/jwebmail.proto @@ -144,6 +144,14 @@ message RemoveReq { message RemoveResp { } +message AddFolderReq { + string name = 1; +} + +message AddFolderResp { + int32 status = 1; +} + service MailService { rpc List(ListReq) returns (ListResp); rpc Stats(StatsReq) returns (StatsResp); @@ -153,4 +161,5 @@ service MailService { rpc Folders(FoldersReq) returns (FoldersResp); rpc Move(MoveReq) returns (MoveResp); rpc Remove(RemoveReq) returns (RemoveResp); + rpc AddFolder(AddFolderReq) returns (AddFolderResp); } 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()) } |