summaryrefslogtreecommitdiff
path: root/src/cmd/stats.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/stats.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/stats.rs')
-rw-r--r--src/cmd/stats.rs25
1 files changed, 25 insertions, 0 deletions
diff --git a/src/cmd/stats.rs b/src/cmd/stats.rs
new file mode 100644
index 0000000..e8e8325
--- /dev/null
+++ b/src/cmd/stats.rs
@@ -0,0 +1,25 @@
+use crate::cmd::{open_submaildir, MailStorage};
+use crate::de_jmhoffmann_jwebmail_mailstorage::Call_Stats;
+
+pub fn stats(ms: &MailStorage, call: &mut dyn Call_Stats, folder: String) -> varlink::Result<()> {
+ if let Some(maildir_path) = ms.maildir_path.read().unwrap().clone() {
+ let maildir = open_submaildir(maildir_path, &folder);
+
+ let mail_count = maildir.count_cur() as i64;
+ let unread_count = maildir
+ .list_cur()
+ .filter(|x| x.as_ref().map_or(false, |z| !z.is_seen()))
+ .count() as i64;
+ let byte_size: u64 = maildir
+ .path()
+ .join("cur")
+ .read_dir()
+ .map_err(varlink::map_context!())?
+ .map(|x| x.map_or(0, |z| z.metadata().map_or(0, |y| y.len())))
+ .sum();
+
+ call.reply(mail_count, unread_count, byte_size as i64)
+ } else {
+ call.reply_not_initialized()
+ }
+}