diff --git a/notmuch/src/lib.rs b/notmuch/src/lib.rs index cd461e5..7ec60e4 100644 --- a/notmuch/src/lib.rs +++ b/notmuch/src/lib.rs @@ -208,9 +208,9 @@ use std::{ ffi::OsStr, - io::{self, BufRead, BufReader, Lines}, + io::{self}, path::{Path, PathBuf}, - process::{Child, ChildStdout, Command, Stdio}, + process::Command, }; use log::info; @@ -556,14 +556,14 @@ impl Notmuch { Ok(res) } - pub fn message_ids(&self, query: &str) -> Result>, NotmuchError> { - let mut child = self.run_notmuch_pipe(["search", "--output=messages", query])?; - Ok(BufReader::new(child.stdout.take().unwrap()).lines()) + pub fn message_ids(&self, query: &str) -> Result, NotmuchError> { + let res = self.run_notmuch(["search", "--output=messages", "--format=json", query])?; + Ok(serde_json::from_slice(&res)?) } - pub fn files(&self, query: &str) -> Result>, NotmuchError> { - let mut child = self.run_notmuch_pipe(["search", "--output=files", query])?; - Ok(BufReader::new(child.stdout.take().unwrap()).lines()) + pub fn files(&self, query: &str) -> Result, NotmuchError> { + let res = self.run_notmuch(["search", "--output=files", "--format=json", query])?; + Ok(serde_json::from_slice(&res)?) } fn run_notmuch(&self, args: I) -> Result, NotmuchError> @@ -580,21 +580,6 @@ impl Notmuch { let out = cmd.output()?; Ok(out.stdout) } - - fn run_notmuch_pipe(&self, args: I) -> Result - where - I: IntoIterator, - S: AsRef, - { - let mut cmd = Command::new("notmuch"); - if let Some(config_path) = &self.config_path { - cmd.arg("--config").arg(config_path); - } - cmd.args(args); - info!("{:?}", &cmd); - let child = cmd.stdout(Stdio::piped()).spawn()?; - Ok(child) - } } #[cfg(test)] diff --git a/server/src/graphql.rs b/server/src/graphql.rs index cc51cb9..6b7dc9e 100644 --- a/server/src/graphql.rs +++ b/server/src/graphql.rs @@ -313,8 +313,6 @@ impl QueryRoot { .exists(); let mut messages = Vec::new(); for (path, id) in std::iter::zip(nm.files(&thread_id)?, nm.message_ids(&thread_id)?) { - let path = path?; - let id = id?; info!("{id}\nfile: {path}"); let file = File::open(&path)?; let mmap = unsafe { MmapOptions::new().map(&file)? }; @@ -481,6 +479,9 @@ fn extract_related(m: &ParsedMail) -> Result { Err("extract_related".into()) } +// TODO(wathiede): make this walk_attachments that takes a closure. +// Then implement one closure for building `Attachment` and imlement another that can be used to +// get the bytes for serving attachments of HTTP fn extract_attachments(m: &ParsedMail) -> Result, Error> { let mut attachements = Vec::new(); for sp in &m.subparts {