From 83ce24c22eff6c778adcdb067b5fc4e8940d808d Mon Sep 17 00:00:00 2001 From: "Jannis M. Hoffmann" Date: Thu, 5 Dec 2024 17:07:32 +0100 Subject: small round of fixes better error handlig in cmd/move do not leak memory in cmd/raw only process the first given varlink socket this fixes reuse of global state over multiple sessions --- Cargo.lock | 2 +- Cargo.toml | 2 +- src/cmd.rs | 8 +++++--- src/cmd/move.rs | 12 +++++++++++- src/cmd/raw.rs | 5 +++-- src/cmd/search.rs | 2 +- src/main.rs | 1 + 7 files changed, 23 insertions(+), 9 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index aa92063..3d582b0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -206,7 +206,7 @@ dependencies = [ [[package]] name = "jwebmail-extract" -version = "0.8.0" +version = "0.8.1" dependencies = [ "base64", "chrono", diff --git a/Cargo.toml b/Cargo.toml index 9a4795d..40ee19c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "jwebmail-extract" -version = "0.8.0" +version = "0.8.1" authors = ["Jannis M. Hoffmann "] edition = "2021" rust-version = "1.80" diff --git a/src/cmd.rs b/src/cmd.rs index 576c9d4..49ba70e 100644 --- a/src/cmd.rs +++ b/src/cmd.rs @@ -11,9 +11,9 @@ mod list; mod r#move; mod raw; mod remove; +mod search; mod show; mod stats; -mod search; use add_folder::add_folder; use folders::folders; @@ -22,9 +22,9 @@ use list::list; use r#move::r#move; use raw::raw; use remove::remove; +use search::search; use show::show; use stats::stats; -use search::search; pub fn open_submaildir(mut path: PathBuf, sub: &str) -> Maildir { if !sub.is_empty() { @@ -39,7 +39,9 @@ pub struct MailStorage { impl Default for MailStorage { fn default() -> Self { - MailStorage { maildir_path: RwLock::new(None) } + MailStorage { + maildir_path: RwLock::new(None), + } } } diff --git a/src/cmd/move.rs b/src/cmd/move.rs index c852d6c..7fc762f 100644 --- a/src/cmd/move.rs +++ b/src/cmd/move.rs @@ -11,7 +11,17 @@ pub fn r#move( if let Some(p) = ms.maildir_path.read().unwrap().clone() { let from = open_submaildir(p.clone(), &from_folder); let to = open_submaildir(p, &to_folder); - from.move_to(&mid, &to).unwrap(); + if from.move_to(&mid, &to).is_err() { + // This is not neccessarily true! + // The error needs to be investigated to find out the actual cause. + // + // Other plausible causes: + // + // InvalidFolder(folder: from_folder) + // InvalidMid(folder: from_folder, mid: mid) + // + return call.reply_invalid_folder(to_folder); + } call.reply() } else { call.reply_not_initialized() diff --git a/src/cmd/raw.rs b/src/cmd/raw.rs index a20eded..0a4df86 100644 --- a/src/cmd/raw.rs +++ b/src/cmd/raw.rs @@ -36,6 +36,7 @@ pub fn raw( .map(|x| x.parse()) .collect::, std::num::ParseIntError>>() { + let mut s; let mut m = mail.parsed().unwrap(); if path[0] != 0 { @@ -56,8 +57,8 @@ pub fn raw( mime_path.to_owned(), ); } - let s: &'static _ = m.get_body_raw().unwrap().leak(); - m = mailparse::parse_mail(s).unwrap(); + s = m.get_body_raw().unwrap(); + m = mailparse::parse_mail(&s).unwrap(); } x if x.starts_with("multipart/") => { if *i >= m.subparts.len() { diff --git a/src/cmd/search.rs b/src/cmd/search.rs index 7cf0fb0..00cc192 100644 --- a/src/cmd/search.rs +++ b/src/cmd/search.rs @@ -9,7 +9,7 @@ pub fn search( ) -> varlink::Result<()> { if let Some(p) = ms.maildir_path.read().unwrap().clone() { let md = open_submaildir(p, &folder); - + todo!(); } else { call.reply_not_initialized() diff --git a/src/main.rs b/src/main.rs index a8e33b2..5ab99e9 100644 --- a/src/main.rs +++ b/src/main.rs @@ -48,6 +48,7 @@ fn main() { .split(':') .enumerate() .filter(|(_, name)| *name == "varlink") + .take(1) .for_each(|(i, _)| { accept_con(&service, unsafe { UnixStream::from_raw_fd(3 + i as i32) }) }); -- cgit v1.2.3