✨ 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:
committed by
Jeremiah Russell
parent
2551d02eba
commit
5533bff054
12
src/list.rs
12
src/list.rs
@@ -19,6 +19,7 @@ pub struct List {
|
|||||||
hub: Gmail<HttpsConnector<HttpConnector>>,
|
hub: Gmail<HttpsConnector<HttpConnector>>,
|
||||||
max_results: u32,
|
max_results: u32,
|
||||||
label_ids: Vec<String>,
|
label_ids: Vec<String>,
|
||||||
|
query: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl List {
|
impl List {
|
||||||
@@ -55,6 +56,7 @@ impl List {
|
|||||||
hub: Gmail::new(client, auth),
|
hub: Gmail::new(client, auth),
|
||||||
max_results: DEFAULT_MAX_RESULTS.parse::<u32>().unwrap(),
|
max_results: DEFAULT_MAX_RESULTS.parse::<u32>().unwrap(),
|
||||||
label_ids: Vec::new(),
|
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
|
/// Run the Gmail api as configured
|
||||||
pub async fn run(&self, pages: u32) -> Result<(), Error> {
|
pub async fn run(&self, pages: u32) -> Result<(), Error> {
|
||||||
let log_estimate = |est: &Option<u32>| {
|
let log_estimate = |est: &Option<u32>| {
|
||||||
@@ -139,6 +146,11 @@ impl List {
|
|||||||
call = call.add_label_ids(id);
|
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
|
// Add a page token if it exists
|
||||||
if let Some(page_token) = next_page_token {
|
if let Some(page_token) = next_page_token {
|
||||||
log::debug!("Setting token for next page.");
|
log::debug!("Setting token for next page.");
|
||||||
|
|||||||
Reference in New Issue
Block a user