diff --git a/notmuch/src/lib.rs b/notmuch/src/lib.rs index 7bb783f..d52dc53 100644 --- a/notmuch/src/lib.rs +++ b/notmuch/src/lib.rs @@ -508,6 +508,25 @@ impl Notmuch { Ok(val) } + pub fn show_part(&self, query: &str, part: usize) -> Result { + 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, NotmuchError> { self.show_original_part(id, 0) }