summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Cargo.lock2
-rw-r--r--Cargo.toml2
-rw-r--r--jwebmail.proto9
-rw-r--r--src/arguments.rs1
-rw-r--r--src/cmd.rs2
-rw-r--r--src/cmd/add_folder.rs37
-rw-r--r--src/main.rs3
7 files changed, 53 insertions, 3 deletions
diff --git a/Cargo.lock b/Cargo.lock
index a1f201c..4592685 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -335,7 +335,7 @@ dependencies = [
[[package]]
name = "jwebmail-extract"
-version = "0.7.0"
+version = "0.8.0"
dependencies = [
"anyhow",
"chrono",
diff --git a/Cargo.toml b/Cargo.toml
index cc2b1a1..91de65b 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -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)]
diff --git a/src/cmd.rs b/src/cmd.rs
index 308cc5f..201f498 100644
--- a/src/cmd.rs
+++ b/src/cmd.rs
@@ -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())
}