summaryrefslogtreecommitdiff
path: root/src/cmd/folders.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/folders.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/folders.rs')
-rw-r--r--src/cmd/folders.rs35
1 files changed, 17 insertions, 18 deletions
diff --git a/src/cmd/folders.rs b/src/cmd/folders.rs
index 417203c..8bf9a30 100644
--- a/src/cmd/folders.rs
+++ b/src/cmd/folders.rs
@@ -1,9 +1,7 @@
-use std::path::{Path, PathBuf};
+use std::path::Path;
-use protobuf::Message as _;
-
-use crate::error::Result;
-use crate::pb3::jwebmail::{FoldersReq, FoldersResp};
+use crate::cmd::MailStorage;
+use crate::de_jmhoffmann_jwebmail_mailstorage::Call_Folders;
fn is_mailsubdir(p: &Path) -> bool {
if !p.is_dir() {
@@ -32,19 +30,20 @@ fn is_mailsubdir(p: &Path) -> bool {
true
}
-pub fn folders(path: PathBuf, req: &[u8]) -> Result<Vec<u8>> {
- let _ = FoldersReq::parse_from_bytes(req)?;
-
- let mut subdirs: Vec<_> = path
- .read_dir()?
- .filter_map(|d| d.ok())
- .filter(|d| is_mailsubdir(&d.path()))
- .filter_map(|d| Some(d.path().file_name()?.to_string_lossy()[1..].to_owned()))
- .collect();
+pub fn folders(ms: &MailStorage, call: &mut dyn Call_Folders) -> varlink::Result<()> {
+ if let Some(path) = &*ms.maildir_path.read().unwrap() {
+ let mut subdirs: Vec<_> = path
+ .read_dir()
+ .map_err(varlink::map_context!())?
+ .filter_map(|d| d.ok())
+ .filter(|d| is_mailsubdir(&d.path()))
+ .filter_map(|d| Some(d.path().file_name()?.to_string_lossy()[1..].to_owned()))
+ .collect();
- subdirs.sort();
+ subdirs.sort();
- let mut res = FoldersResp::new();
- res.folders = subdirs;
- res.write_to_bytes().map_err(|e| e.into())
+ call.reply(subdirs)
+ } else {
+ call.reply_not_initialized()
+ }
}