notmuch: add show_part method.
This commit is contained in:
parent
f809f89dd0
commit
b57e4d9df2
@ -508,6 +508,25 @@ impl Notmuch {
|
|||||||
Ok(val)
|
Ok(val)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn show_part(&self, query: &str, part: usize) -> Result<Part, NotmuchError> {
|
||||||
|
let slice = self.run_notmuch([
|
||||||
|
"show",
|
||||||
|
"--include-html=true",
|
||||||
|
"--entire-thread=true",
|
||||||
|
"--format=json",
|
||||||
|
&format!("--part={}", part),
|
||||||
|
query,
|
||||||
|
])?;
|
||||||
|
// Notmuch returns JSON with invalid unicode. So we lossy convert it to a string here an
|
||||||
|
// use that for parsing in rust.
|
||||||
|
let s = String::from_utf8_lossy(&slice);
|
||||||
|
let mut deserializer = serde_json::Deserializer::from_str(&s);
|
||||||
|
deserializer.disable_recursion_limit();
|
||||||
|
let val = serde::de::Deserialize::deserialize(&mut deserializer)?;
|
||||||
|
deserializer.end()?;
|
||||||
|
Ok(val)
|
||||||
|
}
|
||||||
|
|
||||||
pub fn show_original(&self, id: &MessageId) -> Result<Vec<u8>, NotmuchError> {
|
pub fn show_original(&self, id: &MessageId) -> Result<Vec<u8>, NotmuchError> {
|
||||||
self.show_original_part(id, 0)
|
self.show_original_part(id, 0)
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user