summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJannis M. Hoffmann <jannis@fehcom.de>2024-12-05 17:07:32 +0100
committerJannis M. Hoffmann <jannis@fehcom.de>2024-12-05 17:07:32 +0100
commit83ce24c22eff6c778adcdb067b5fc4e8940d808d (patch)
treeebaf40d7ead8c8b57382549aaae315d078ea9c11 /src
parent48c2945172b88c35c187d298a35bf26716af4e91 (diff)
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
Diffstat (limited to 'src')
-rw-r--r--src/cmd.rs8
-rw-r--r--src/cmd/move.rs12
-rw-r--r--src/cmd/raw.rs5
-rw-r--r--src/cmd/search.rs2
-rw-r--r--src/main.rs1
5 files changed, 21 insertions, 7 deletions
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::result::Result<Vec<usize>, 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) })
});