summaryrefslogtreecommitdiff
path: root/src/cmd/folders.rs
diff options
context:
space:
mode:
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()
+ }
}