summaryrefslogtreecommitdiff
path: root/src/cmd/add_folder.rs
diff options
context:
space:
mode:
authorJannis M. Hoffmann <jannis@fehcom.de>2024-11-21 21:14:40 +0100
committerJannis M. Hoffmann <jannis@fehcom.de>2024-11-21 21:14:40 +0100
commit48c2945172b88c35c187d298a35bf26716af4e91 (patch)
tree2af21ddb4dcacd191e07fef156609b7c1488ebaf /src/cmd/add_folder.rs
parent6ed535387df0dffa72a10e601b8ea37c99345d84 (diff)
Switch to varlink as IPC protocol
This is a lot! Whole new design on top of a statefult varlink interface. You can now handle multiple request response cycles over a single connection. The error responses are lot more refined than just status codes with optional messages and finally part of the protocol. TODO: A lot of error handling needs to be improved.
Diffstat (limited to 'src/cmd/add_folder.rs')
-rw-r--r--src/cmd/add_folder.rs53
1 files changed, 28 insertions, 25 deletions
diff --git a/src/cmd/add_folder.rs b/src/cmd/add_folder.rs
index 82df1f9..07ad455 100644
--- a/src/cmd/add_folder.rs
+++ b/src/cmd/add_folder.rs
@@ -1,37 +1,40 @@
use std::fs::create_dir;
-use std::path::PathBuf;
-use protobuf::Message as _;
+use varlink;
-use crate::error::Result;
-use crate::pb3::jwebmail::{AddFolderReq, AddFolderResp};
+use crate::cmd::MailStorage;
+use crate::de_jmhoffmann_jwebmail_mailstorage::{AddFolder_Reply_status, Call_AddFolder};
-pub fn add_folder(mut p: PathBuf, req: &[u8]) -> Result<Vec<u8>> {
- let r = AddFolderReq::parse_from_bytes(req)?;
- let mut resp = AddFolderResp::new();
+pub fn add_folder(
+ ms: &MailStorage,
+ call: &mut dyn Call_AddFolder,
+ name: String,
+) -> varlink::Result<()> {
+ if let Some(mut p) = ms.maildir_path.read().unwrap().clone() {
+ let mut folder = ".".to_owned();
+ folder.push_str(&name);
- let mut folder = ".".to_owned();
- folder.push_str(&r.name);
- p.push(folder);
+ p.push(folder);
- if p.is_dir() {
- resp.status = 1;
- return resp.write_to_bytes().map_err(|e| e.into());
- }
+ if p.is_dir() {
+ return call.reply(AddFolder_Reply_status::skiped);
+ }
- create_dir(&p)?;
+ create_dir(&p).map_err(varlink::map_context!())?;
- p.push("tmp");
- create_dir(&p)?;
+ p.push("tmp");
+ create_dir(&p).map_err(varlink::map_context!())?;
- p.pop();
- p.push("new");
- create_dir(&p)?;
+ p.pop();
+ p.push("new");
+ create_dir(&p).map_err(varlink::map_context!())?;
- p.pop();
- p.push("cur");
- create_dir(p)?;
+ p.pop();
+ p.push("cur");
+ create_dir(p).map_err(varlink::map_context!())?;
- resp.status = 0;
- resp.write_to_bytes().map_err(|e| e.into())
+ call.reply(AddFolder_Reply_status::created)
+ } else {
+ call.reply_not_initialized()
+ }
}