pub struct MessagesApi<'a> { /* private fields */ }Expand description
Messages API façade.
Implementations§
Source§impl<'a> MessagesApi<'a>
impl<'a> MessagesApi<'a>
Sourcepub fn new(client: &'a GmailClient) -> Self
pub fn new(client: &'a GmailClient) -> Self
Wraps an existing GmailClient for message operations.
Sourcepub async fn search(
&self,
query: Option<&str>,
label_ids: &[&str],
limit: usize,
page_token: Option<&str>,
) -> Result<MessageListResponse>
pub async fn search( &self, query: Option<&str>, label_ids: &[&str], limit: usize, page_token: Option<&str>, ) -> Result<MessageListResponse>
Searches messages matching query, returning a single page.
limit is rejected client-side when it exceeds MAX_PAGE_LIMIT;
use Self::search_all to auto-paginate across pages.
Sourcepub async fn search_all(
&self,
query: Option<&str>,
label_ids: &[&str],
limit: usize,
) -> Result<MessageListResponse>
pub async fn search_all( &self, query: Option<&str>, label_ids: &[&str], limit: usize, ) -> Result<MessageListResponse>
Searches messages, auto-paginating via cursor as needed.
limit == 0 means “fetch every match up to HARD_CAP”. This cap
is a deliberate safety limit for this interactive surface — see
Self::search_all_unbounded_streaming for the one caller that must
not have it.
Sourcepub async fn get(
&self,
id: &str,
format: MessageFormat,
metadata_headers: &[&str],
) -> Result<Message>
pub async fn get( &self, id: &str, format: MessageFormat, metadata_headers: &[&str], ) -> Result<Message>
Fetches a single message by id.
Sourcepub async fn search_summaries(
&self,
query: Option<&str>,
label_ids: &[&str],
limit: usize,
concurrency: usize,
) -> Result<Vec<MessageSummary>>
pub async fn search_summaries( &self, query: Option<&str>, label_ids: &[&str], limit: usize, concurrency: usize, ) -> Result<Vec<MessageSummary>>
Searches messages and enriches each hit with From/Subject/Date
via one messages.get(format=metadata) call per hit.
Gmail’s list endpoint only returns {id, threadId} per hit — a
search-shaped CLI/MCP surface needs more than bare ids to be
useful, so this costs one extra request per result. Gmail’s quota is
250 units/user/second and messages.get costs 5 units, so
this is a genuinely expensive operation — callers are expected to
treat it as opt-in (the CLI’s --enrich flag) rather than a default,
and concurrency bounds the fan-out (modelled on
src/cli/atlassian/confluence/download.rs’s
Semaphore::new(params.concurrency) list-then-hydrate shape) so a
large limit can’t burst past the quota in an uncontrolled way.
Order is preserved (buffered, not buffer_unordered) so results
match search_all’s ordering. A hydration failure on any one id
aborts the whole call with that error, once every already-in-flight
fetch in its concurrency batch completes — it is never silently
dropped from the results.
Sourcepub async fn batch_modify(
&self,
ids: &[&str],
add_label_ids: &[&str],
remove_label_ids: &[&str],
) -> Result<()>
pub async fn batch_modify( &self, ids: &[&str], add_label_ids: &[&str], remove_label_ids: &[&str], ) -> Result<()>
Adds/removes labels on up to 1000 messages in one call.
Requires the gmail.modify scope — no client-side scope gating is
performed (matches this client’s posture elsewhere of letting the
server enforce authorization): a gmail.readonly-only token simply
gets a 403 back from Google, surfaced via
GmailClient::response_to_error.