Merge commit 'f6bdf30'
This commit is contained in:
commit
94f7ad109a
@ -208,9 +208,9 @@
|
|||||||
|
|
||||||
use std::{
|
use std::{
|
||||||
ffi::OsStr,
|
ffi::OsStr,
|
||||||
io::{self, BufRead, BufReader, Lines},
|
io::{self},
|
||||||
path::{Path, PathBuf},
|
path::{Path, PathBuf},
|
||||||
process::{Child, ChildStdout, Command, Stdio},
|
process::Command,
|
||||||
};
|
};
|
||||||
|
|
||||||
use log::info;
|
use log::info;
|
||||||
@ -556,14 +556,14 @@ impl Notmuch {
|
|||||||
Ok(res)
|
Ok(res)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn message_ids(&self, query: &str) -> Result<Lines<BufReader<ChildStdout>>, NotmuchError> {
|
pub fn message_ids(&self, query: &str) -> Result<Vec<String>, NotmuchError> {
|
||||||
let mut child = self.run_notmuch_pipe(["search", "--output=messages", query])?;
|
let res = self.run_notmuch(["search", "--output=messages", "--format=json", query])?;
|
||||||
Ok(BufReader::new(child.stdout.take().unwrap()).lines())
|
Ok(serde_json::from_slice(&res)?)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn files(&self, query: &str) -> Result<Lines<BufReader<ChildStdout>>, NotmuchError> {
|
pub fn files(&self, query: &str) -> Result<Vec<String>, NotmuchError> {
|
||||||
let mut child = self.run_notmuch_pipe(["search", "--output=files", query])?;
|
let res = self.run_notmuch(["search", "--output=files", "--format=json", query])?;
|
||||||
Ok(BufReader::new(child.stdout.take().unwrap()).lines())
|
Ok(serde_json::from_slice(&res)?)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn run_notmuch<I, S>(&self, args: I) -> Result<Vec<u8>, NotmuchError>
|
fn run_notmuch<I, S>(&self, args: I) -> Result<Vec<u8>, NotmuchError>
|
||||||
@ -580,21 +580,6 @@ impl Notmuch {
|
|||||||
let out = cmd.output()?;
|
let out = cmd.output()?;
|
||||||
Ok(out.stdout)
|
Ok(out.stdout)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn run_notmuch_pipe<I, S>(&self, args: I) -> Result<Child, NotmuchError>
|
|
||||||
where
|
|
||||||
I: IntoIterator<Item = S>,
|
|
||||||
S: AsRef<OsStr>,
|
|
||||||
{
|
|
||||||
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)]
|
#[cfg(test)]
|
||||||
|
|||||||
@ -313,8 +313,6 @@ impl QueryRoot {
|
|||||||
.exists();
|
.exists();
|
||||||
let mut messages = Vec::new();
|
let mut messages = Vec::new();
|
||||||
for (path, id) in std::iter::zip(nm.files(&thread_id)?, nm.message_ids(&thread_id)?) {
|
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}");
|
info!("{id}\nfile: {path}");
|
||||||
let file = File::open(&path)?;
|
let file = File::open(&path)?;
|
||||||
let mmap = unsafe { MmapOptions::new().map(&file)? };
|
let mmap = unsafe { MmapOptions::new().map(&file)? };
|
||||||
@ -481,6 +479,9 @@ fn extract_related(m: &ParsedMail) -> Result<Body, Error> {
|
|||||||
Err("extract_related".into())
|
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<Vec<Attachment>, Error> {
|
fn extract_attachments(m: &ParsedMail) -> Result<Vec<Attachment>, Error> {
|
||||||
let mut attachements = Vec::new();
|
let mut attachements = Vec::new();
|
||||||
for sp in &m.subparts {
|
for sp in &m.subparts {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user