feat(list): add query support to list messages

- allow users to filter messages using a query string
  - implement set_query method to set the query
  - add query parameter to the Gmail API call
This commit is contained in:
Jeremiah Russell
2025-10-03 17:13:09 +01:00
committed by Jeremiah Russell
parent 2551d02eba
commit 5533bff054

View File

@@ -19,6 +19,7 @@ pub struct List {
hub: Gmail<HttpsConnector<HttpConnector>>,
max_results: u32,
label_ids: Vec<String>,
query: String,
}
impl List {
@@ -55,6 +56,7 @@ impl List {
hub: Gmail::new(client, auth),
max_results: DEFAULT_MAX_RESULTS.parse::<u32>().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<u32>| {
@@ -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.");