diff --git a/src/list.rs b/src/list.rs index 8249ebb..d181348 100644 --- a/src/list.rs +++ b/src/list.rs @@ -19,6 +19,7 @@ pub struct List { hub: Gmail>, max_results: u32, label_ids: Vec, + query: String, } impl List { @@ -55,6 +56,7 @@ impl List { hub: Gmail::new(client, auth), max_results: DEFAULT_MAX_RESULTS.parse::().unwrap(), label_ids: Vec::new(), + query: String::new(), }) } @@ -77,6 +79,11 @@ impl List { } } + /// Set the query string + pub fn set_query(&mut self, query: &str) { + self.query = query.to_string() + } + /// Run the Gmail api as configured pub async fn run(&self, pages: u32) -> Result<(), Error> { let log_estimate = |est: &Option| { @@ -139,6 +146,11 @@ impl List { call = call.add_label_ids(id); } } + // Add query + if !self.query.is_empty() { + log::debug!("Setting query string `{}`", self.query); + call = call.q(&self.query); + } // Add a page token if it exists if let Some(page_token) = next_page_token { log::debug!("Setting token for next page.");