diff options
author | Jannis M. Hoffmann <jannis@fehcom.de> | 2024-11-21 21:14:40 +0100 |
---|---|---|
committer | Jannis M. Hoffmann <jannis@fehcom.de> | 2024-11-21 21:14:40 +0100 |
commit | 48c2945172b88c35c187d298a35bf26716af4e91 (patch) | |
tree | 2af21ddb4dcacd191e07fef156609b7c1488ebaf /src/cmd.rs | |
parent | 6ed535387df0dffa72a10e601b8ea37c99345d84 (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.rs')
-rw-r--r-- | src/cmd.rs | 114 |
1 files changed, 103 insertions, 11 deletions
@@ -1,24 +1,30 @@ use std::path::PathBuf; +use std::sync::RwLock; +use crate::de_jmhoffmann_jwebmail_mailstorage::*; use maildir::Maildir; mod add_folder; -mod count; mod folders; +mod init; mod list; -mod move_mail; +mod r#move; mod raw; -mod read; mod remove; +mod show; +mod stats; +mod search; -pub use add_folder::add_folder; -pub use count::count; -pub use folders::folders; -pub use list::list; -pub use move_mail::move_mail; -pub use raw::raw; -pub use read::read; -pub use remove::remove; +use add_folder::add_folder; +use folders::folders; +use init::init; +use list::list; +use r#move::r#move; +use raw::raw; +use remove::remove; +use show::show; +use stats::stats; +use search::search; pub fn open_submaildir(mut path: PathBuf, sub: &str) -> Maildir { if !sub.is_empty() { @@ -26,3 +32,89 @@ pub fn open_submaildir(mut path: PathBuf, sub: &str) -> Maildir { } Maildir::from(path) } + +pub struct MailStorage { + maildir_path: RwLock<Option<PathBuf>>, +} + +impl Default for MailStorage { + fn default() -> Self { + MailStorage { maildir_path: RwLock::new(None) } + } +} + +impl VarlinkInterface for MailStorage { + fn init( + &self, + call: &mut dyn Call_Init, + unix_user: String, + mailbox_path: String, + ) -> varlink::Result<()> { + init(self, call, unix_user, mailbox_path) + } + + fn add_folder(&self, call: &mut dyn Call_AddFolder, name: String) -> varlink::Result<()> { + add_folder(self, call, name) + } + + fn stats(&self, call: &mut dyn Call_Stats, folder: String) -> varlink::Result<()> { + stats(self, call, folder) + } + + fn folders(&self, call: &mut dyn Call_Folders) -> varlink::Result<()> { + folders(self, call) + } + + fn list( + &self, + call: &mut dyn Call_List, + folder: String, + start: i64, + end: i64, + sort: Sort, + ) -> varlink::Result<()> { + list(self, call, folder, start, end, sort) + } + + fn r#move( + &self, + call: &mut dyn Call_Move, + mid: String, + from_folder: String, + to_folder: String, + ) -> varlink::Result<()> { + r#move(self, call, mid, from_folder, to_folder) + } + + fn raw( + &self, + call: &mut dyn Call_Raw, + folder: String, + mid: String, + path: Option<String>, + ) -> varlink::Result<()> { + raw(self, call, folder, mid, path) + } + + fn remove( + &self, + call: &mut dyn Call_Remove, + folder: String, + mid: String, + ) -> varlink::Result<()> { + remove(self, call, folder, mid) + } + + fn search( + &self, + call: &mut dyn Call_Search, + folder: String, + pattern: String, + ) -> varlink::Result<()> { + search(self, call, folder, pattern) + } + + fn show(&self, call: &mut dyn Call_Show, folder: String, mid: String) -> varlink::Result<()> { + show(self, call, folder, mid) + } +} |