notmuch: add tag manipulation

This commit is contained in:
Bill Thiede 2024-02-11 19:59:20 -08:00
parent f7010fa278
commit ce836cd1e8

View File

@ -480,11 +480,25 @@ impl Notmuch {
self.run_notmuch(std::iter::empty::<&str>())
}
pub fn tags(&self) -> Result<Vec<String>, NotmuchError> {
let res = self.run_notmuch(["search", "--format=json", "--output=tags", "*"])?;
pub fn tags_for_query(&self, query: &str) -> Result<Vec<String>, NotmuchError> {
let res = self.run_notmuch(["search", "--format=json", "--output=tags", query])?;
Ok(serde_json::from_slice(&res)?)
}
pub fn tags(&self) -> Result<Vec<String>, NotmuchError> {
self.tags_for_query("*")
}
pub fn tag_add(&self, tag: &str, search_term: &str) -> Result<(), NotmuchError> {
self.run_notmuch(["tag", &format!("+{tag}"), search_term])?;
Ok(())
}
pub fn tag_remove(&self, tag: &str, search_term: &str) -> Result<(), NotmuchError> {
self.run_notmuch(["tag", &format!("-{tag}"), search_term])?;
Ok(())
}
pub fn search(
&self,
query: &str,
@ -514,7 +528,7 @@ impl Notmuch {
let slice = self.run_notmuch([
"show",
"--include-html=true",
"--entire-thread=true",
"--entire-thread=false",
"--format=json",
query,
])?;