pub struct GraphClient { /* private fields */ }Expand description
Stateful Microsoft Graph client. Holds an AuthClient and a shared HTTP client.
Implementations§
Source§impl GraphClient
impl GraphClient
pub fn new(auth: AuthClient) -> Result<Self, ClientError>
pub fn for_test(auth: AuthClient, base_url: impl Into<String>) -> Self
pub fn auth(&self) -> &AuthClient
Sourcepub async fn me(&self, access_token: &str) -> Result<Me, ClientError>
pub async fn me(&self, access_token: &str) -> Result<Me, ClientError>
GET /me. Used right after sign-in to learn the user’s email.
Sourcepub async fn list_inbox(
&self,
account: &str,
limit: usize,
skip: usize,
unread_only: bool,
) -> Result<InboxPage, ClientError>
pub async fn list_inbox( &self, account: &str, limit: usize, skip: usize, unread_only: bool, ) -> Result<InboxPage, ClientError>
GET /me/mailFolders/inbox/messages for a given account email.
Acquires/refreshes a token transparently via AuthClient::get_valid_token.
Sourcepub async fn list_folder(
&self,
account: &str,
folder_id: &str,
limit: usize,
skip: usize,
unread_only: bool,
) -> Result<InboxPage, ClientError>
pub async fn list_folder( &self, account: &str, folder_id: &str, limit: usize, skip: usize, unread_only: bool, ) -> Result<InboxPage, ClientError>
GET /me/mailFolders/{folder_id}/messages: list a custom folder.
Sourcepub async fn mail_delta_bootstrap(
&self,
account: &str,
folder: &str,
) -> Result<(Vec<Message>, String), ClientError>
pub async fn mail_delta_bootstrap( &self, account: &str, folder: &str, ) -> Result<(Vec<Message>, String), ClientError>
GET /me/messages with $search="<query>" for a given account.
Bootstrap a mail delta stream for a folder: (current messages, deltaLink).
Sourcepub async fn mail_delta(
&self,
account: &str,
delta_link: &str,
) -> Result<(Vec<MailDeltaEvent>, String), ClientError>
pub async fn mail_delta( &self, account: &str, delta_link: &str, ) -> Result<(Vec<MailDeltaEvent>, String), ClientError>
Poll a mail deltaLink for changes.
Sourcepub async fn calendar_delta_bootstrap(
&self,
account: &str,
start: DateTime<Utc>,
end: DateTime<Utc>,
) -> Result<(Vec<Event>, String), ClientError>
pub async fn calendar_delta_bootstrap( &self, account: &str, start: DateTime<Utc>, end: DateTime<Utc>, ) -> Result<(Vec<Event>, String), ClientError>
Bootstrap a calendar delta stream over a window: (current events, deltaLink).
Sourcepub async fn calendar_delta(
&self,
account: &str,
delta_link: &str,
) -> Result<(Vec<CalendarDeltaEvent>, String), ClientError>
pub async fn calendar_delta( &self, account: &str, delta_link: &str, ) -> Result<(Vec<CalendarDeltaEvent>, String), ClientError>
Poll a calendar deltaLink for changes.
Sourcepub async fn batch_all(
&self,
account: &str,
requests: Vec<BatchRequest>,
) -> Result<Vec<BatchResponse>, ClientError>
pub async fn batch_all( &self, account: &str, requests: Vec<BatchRequest>, ) -> Result<Vec<BatchResponse>, ClientError>
Run a set of batch sub-requests for one account.
Sourcepub async fn list_conversation(
&self,
account: &str,
conversation_id: &str,
) -> Result<Vec<Message>, ClientError>
pub async fn list_conversation( &self, account: &str, conversation_id: &str, ) -> Result<Vec<Message>, ClientError>
Fetch every message in a conversation (thread), oldest first.
Sourcepub async fn list_messages_at(
&self,
account: &str,
url: &str,
) -> Result<InboxPage, ClientError>
pub async fn list_messages_at( &self, account: &str, url: &str, ) -> Result<InboxPage, ClientError>
Fetch a page of messages at an absolute Graph continuation URL.
pub async fn search_messages( &self, account: &str, query: &str, limit: usize, ) -> Result<InboxPage, ClientError>
Sourcepub async fn search_folder(
&self,
account: &str,
folder: &str,
query: &str,
limit: usize,
) -> Result<InboxPage, ClientError>
pub async fn search_folder( &self, account: &str, folder: &str, query: &str, limit: usize, ) -> Result<InboxPage, ClientError>
$search within one folder (well-known name or folder id).
Sourcepub async fn mark_unread(
&self,
account: &str,
message_id: &str,
) -> Result<(), ClientError>
pub async fn mark_unread( &self, account: &str, message_id: &str, ) -> Result<(), ClientError>
PATCH /me/messages/{id} with { "isRead": false }.
Sourcepub async fn set_flag(
&self,
account: &str,
message_id: &str,
flagged: bool,
) -> Result<(), ClientError>
pub async fn set_flag( &self, account: &str, message_id: &str, flagged: bool, ) -> Result<(), ClientError>
PATCH /me/messages/{id} with { "flag": { "flagStatus": "flagged"|"notFlagged" } }.
Sourcepub async fn get_categories(
&self,
account: &str,
message_id: &str,
) -> Result<Vec<String>, ClientError>
pub async fn get_categories( &self, account: &str, message_id: &str, ) -> Result<Vec<String>, ClientError>
GET /me/messages/{id}?$select=categories.
Sourcepub async fn set_categories(
&self,
account: &str,
message_id: &str,
categories: &[String],
) -> Result<(), ClientError>
pub async fn set_categories( &self, account: &str, message_id: &str, categories: &[String], ) -> Result<(), ClientError>
PATCH /me/messages/{id} categories.
Sourcepub async fn move_message(
&self,
account: &str,
message_id: &str,
destination: &str,
) -> Result<(), ClientError>
pub async fn move_message( &self, account: &str, message_id: &str, destination: &str, ) -> Result<(), ClientError>
POST /me/messages/{id}/move: move to a folder by ID or well-known name.
Sourcepub async fn list_mail_folders(
&self,
account: &str,
) -> Result<Vec<MailFolder>, ClientError>
pub async fn list_mail_folders( &self, account: &str, ) -> Result<Vec<MailFolder>, ClientError>
GET /me/mailFolders: list the account’s top-level folders.
Sourcepub async fn create_mail_folder(
&self,
account: &str,
display_name: &str,
) -> Result<MailFolder, ClientError>
pub async fn create_mail_folder( &self, account: &str, display_name: &str, ) -> Result<MailFolder, ClientError>
POST /me/mailFolders: create a top-level folder, returning it.
Sourcepub async fn list_child_folders(
&self,
account: &str,
parent_id: &str,
) -> Result<Vec<MailFolder>, ClientError>
pub async fn list_child_folders( &self, account: &str, parent_id: &str, ) -> Result<Vec<MailFolder>, ClientError>
GET /me/mailFolders/{parent_id}/childFolders: list a folder’s children.
Sourcepub async fn create_child_folder(
&self,
account: &str,
parent_id: &str,
display_name: &str,
) -> Result<MailFolder, ClientError>
pub async fn create_child_folder( &self, account: &str, parent_id: &str, display_name: &str, ) -> Result<MailFolder, ClientError>
POST /me/mailFolders/{parent_id}/childFolders: create a child folder.
Sourcepub async fn delete_mail_folder(
&self,
account: &str,
folder_id: &str,
) -> Result<(), ClientError>
pub async fn delete_mail_folder( &self, account: &str, folder_id: &str, ) -> Result<(), ClientError>
DELETE /me/mailFolders/{id}: delete a folder (contents move to Deleted Items).
Sourcepub async fn send_mail(
&self,
account: &str,
message: &Outgoing,
) -> Result<(), ClientError>
pub async fn send_mail( &self, account: &str, message: &Outgoing, ) -> Result<(), ClientError>
POST /me/sendMail: compose-and-send a new message.
Sourcepub async fn reply_message(
&self,
account: &str,
message_id: &str,
comment: &str,
) -> Result<(), ClientError>
pub async fn reply_message( &self, account: &str, message_id: &str, comment: &str, ) -> Result<(), ClientError>
POST /me/messages/{id}/reply.
Sourcepub async fn reply_all_message(
&self,
account: &str,
message_id: &str,
comment: &str,
) -> Result<(), ClientError>
pub async fn reply_all_message( &self, account: &str, message_id: &str, comment: &str, ) -> Result<(), ClientError>
POST /me/messages/{id}/replyAll.
Sourcepub async fn forward_message(
&self,
account: &str,
message_id: &str,
to: &[String],
comment: &str,
) -> Result<(), ClientError>
pub async fn forward_message( &self, account: &str, message_id: &str, to: &[String], comment: &str, ) -> Result<(), ClientError>
POST /me/messages/{id}/forward.
Sourcepub async fn list_drafts(
&self,
account: &str,
limit: usize,
skip: usize,
) -> Result<InboxPage, ClientError>
pub async fn list_drafts( &self, account: &str, limit: usize, skip: usize, ) -> Result<InboxPage, ClientError>
GET /me/mailFolders/drafts/messages.
Sourcepub async fn create_draft(
&self,
account: &str,
message: &Outgoing,
) -> Result<String, ClientError>
pub async fn create_draft( &self, account: &str, message: &Outgoing, ) -> Result<String, ClientError>
POST /me/messages: create a draft, returning its new message ID.
Sourcepub async fn create_reply_draft(
&self,
account: &str,
message_id: &str,
comment: &str,
) -> Result<String, ClientError>
pub async fn create_reply_draft( &self, account: &str, message_id: &str, comment: &str, ) -> Result<String, ClientError>
POST /me/messages/{id}/createReply.
Sourcepub async fn create_reply_all_draft(
&self,
account: &str,
message_id: &str,
comment: &str,
) -> Result<String, ClientError>
pub async fn create_reply_all_draft( &self, account: &str, message_id: &str, comment: &str, ) -> Result<String, ClientError>
POST /me/messages/{id}/createReplyAll.
Sourcepub async fn create_forward_draft(
&self,
account: &str,
message_id: &str,
to: &[String],
comment: &str,
) -> Result<String, ClientError>
pub async fn create_forward_draft( &self, account: &str, message_id: &str, to: &[String], comment: &str, ) -> Result<String, ClientError>
POST /me/messages/{id}/createForward.
Sourcepub async fn send_draft(
&self,
account: &str,
message_id: &str,
) -> Result<(), ClientError>
pub async fn send_draft( &self, account: &str, message_id: &str, ) -> Result<(), ClientError>
POST /me/messages/{id}/send: send an existing draft.
Sourcepub async fn update_draft(
&self,
account: &str,
message_id: &str,
message: &Outgoing,
) -> Result<(), ClientError>
pub async fn update_draft( &self, account: &str, message_id: &str, message: &Outgoing, ) -> Result<(), ClientError>
PATCH /me/messages/{id}: overwrite a draft’s editable fields.
Sourcepub async fn update_draft_recipients(
&self,
account: &str,
message_id: &str,
to: Option<&[String]>,
cc: Option<&[String]>,
bcc: Option<&[String]>,
) -> Result<(), ClientError>
pub async fn update_draft_recipients( &self, account: &str, message_id: &str, to: Option<&[String]>, cc: Option<&[String]>, bcc: Option<&[String]>, ) -> Result<(), ClientError>
PATCH /me/messages/{id}: replace only the given recipient lists.
Sourcepub async fn delete_message(
&self,
account: &str,
message_id: &str,
) -> Result<(), ClientError>
pub async fn delete_message( &self, account: &str, message_id: &str, ) -> Result<(), ClientError>
DELETE /me/messages/{id}: moves to Deleted Items. Works for both drafts and inbox messages.
Sourcepub async fn add_attachment(
&self,
account: &str,
message_id: &str,
name: &str,
content_type: &str,
bytes: &[u8],
) -> Result<String, ClientError>
pub async fn add_attachment( &self, account: &str, message_id: &str, name: &str, content_type: &str, bytes: &[u8], ) -> Result<String, ClientError>
POST /me/messages/{id}/attachments: attach a file (simple upload).
Sourcepub async fn delete_attachment(
&self,
account: &str,
message_id: &str,
attachment_id: &str,
) -> Result<(), ClientError>
pub async fn delete_attachment( &self, account: &str, message_id: &str, attachment_id: &str, ) -> Result<(), ClientError>
DELETE /me/messages/{id}/attachments/{att_id}.
Sourcepub async fn get_message(
&self,
account: &str,
message_id: &str,
) -> Result<FullMessage, ClientError>
pub async fn get_message( &self, account: &str, message_id: &str, ) -> Result<FullMessage, ClientError>
GET /me/messages/{id} for a given account email.
Sourcepub async fn fetch_message_headers(
&self,
account: &str,
message_id: &str,
) -> Result<Vec<(String, String)>, ClientError>
pub async fn fetch_message_headers( &self, account: &str, message_id: &str, ) -> Result<Vec<(String, String)>, ClientError>
GET /me/messages/{id}?$select=internetMessageHeaders.
Sourcepub async fn list_attachments(
&self,
account: &str,
message_id: &str,
) -> Result<Vec<Attachment>, ClientError>
pub async fn list_attachments( &self, account: &str, message_id: &str, ) -> Result<Vec<Attachment>, ClientError>
GET /me/messages/{id}/attachments.
Sourcepub async fn unsubscribe_one_click(&self, url: &str) -> Result<(), ClientError>
pub async fn unsubscribe_one_click(&self, url: &str) -> Result<(), ClientError>
POST a List-Unsubscribe=One-Click form body (RFC 8058) to a
third-party unsubscribe URL. No bearer token; the URL belongs to
the sender, not Microsoft.
Only https to a public host; see mail::unsubscribe_one_click.
A Self::for_test client also reaches a loopback mock server.
Sourcepub async fn list_people(
&self,
account: &str,
top: usize,
) -> Result<Vec<Person>, ClientError>
pub async fn list_people( &self, account: &str, top: usize, ) -> Result<Vec<Person>, ClientError>
GET /me/people?$top={top}&$select=displayName,scoredEmailAddresses: Outlook’s ranked “people I interact with” list.
Sourcepub async fn get_attachment_bytes(
&self,
account: &str,
message_id: &str,
attachment_id: &str,
) -> Result<Vec<u8>, ClientError>
pub async fn get_attachment_bytes( &self, account: &str, message_id: &str, attachment_id: &str, ) -> Result<Vec<u8>, ClientError>
GET /me/messages/{id}/attachments/{att_id} returning decoded bytes.
Sourcepub async fn mark_read(
&self,
account: &str,
message_id: &str,
) -> Result<(), ClientError>
pub async fn mark_read( &self, account: &str, message_id: &str, ) -> Result<(), ClientError>
PATCH /me/messages/{id} with isRead: true.
Sourcepub async fn list_calendars(
&self,
account: &str,
) -> Result<Vec<Calendar>, ClientError>
pub async fn list_calendars( &self, account: &str, ) -> Result<Vec<Calendar>, ClientError>
GET /me/calendars.
Sourcepub async fn list_calendar_view(
&self,
account: &str,
calendar_id: Option<&str>,
start: DateTime<Utc>,
end: DateTime<Utc>,
limit: usize,
) -> Result<EventsPage, ClientError>
pub async fn list_calendar_view( &self, account: &str, calendar_id: Option<&str>, start: DateTime<Utc>, end: DateTime<Utc>, limit: usize, ) -> Result<EventsPage, ClientError>
GET /me/calendarView (or /me/calendars/{id}/calendarView).
Sourcepub async fn list_events_at(
&self,
account: &str,
url: &str,
) -> Result<EventsPage, ClientError>
pub async fn list_events_at( &self, account: &str, url: &str, ) -> Result<EventsPage, ClientError>
Fetch a page of calendar events at an absolute Graph continuation URL.
Sourcepub async fn get_event(
&self,
account: &str,
event_id: &str,
) -> Result<Event, ClientError>
pub async fn get_event( &self, account: &str, event_id: &str, ) -> Result<Event, ClientError>
GET /me/events/{id}.
Sourcepub async fn create_event(
&self,
account: &str,
calendar_id: Option<&str>,
new_event: &NewEvent,
) -> Result<String, ClientError>
pub async fn create_event( &self, account: &str, calendar_id: Option<&str>, new_event: &NewEvent, ) -> Result<String, ClientError>
POST /me/calendar/events (or /me/calendars/{id}/events).
Sourcepub async fn update_event(
&self,
account: &str,
event_id: &str,
new_event: &NewEvent,
) -> Result<(), ClientError>
pub async fn update_event( &self, account: &str, event_id: &str, new_event: &NewEvent, ) -> Result<(), ClientError>
PATCH /me/events/{id}: overwrite editable fields.
Sourcepub async fn move_time(
&self,
account: &str,
event_id: &str,
start: DateTime<Utc>,
end: DateTime<Utc>,
tz: &str,
) -> Result<(), ClientError>
pub async fn move_time( &self, account: &str, event_id: &str, start: DateTime<Utc>, end: DateTime<Utc>, tz: &str, ) -> Result<(), ClientError>
PATCH /me/events/{id}: change only start + end.
Sourcepub async fn delete_event(
&self,
account: &str,
event_id: &str,
) -> Result<(), ClientError>
pub async fn delete_event( &self, account: &str, event_id: &str, ) -> Result<(), ClientError>
DELETE /me/events/{id}: silent removal.
Sourcepub async fn cancel_event(
&self,
account: &str,
event_id: &str,
comment: &str,
) -> Result<(), ClientError>
pub async fn cancel_event( &self, account: &str, event_id: &str, comment: &str, ) -> Result<(), ClientError>
POST /me/events/{id}/cancel: organizer-only.
Sourcepub async fn rsvp_event(
&self,
account: &str,
event_id: &str,
kind: RsvpKind,
comment: &str,
send_response: bool,
proposed: Option<&ProposedTime>,
) -> Result<(), ClientError>
pub async fn rsvp_event( &self, account: &str, event_id: &str, kind: RsvpKind, comment: &str, send_response: bool, proposed: Option<&ProposedTime>, ) -> Result<(), ClientError>
POST /me/events/{id}/accept | /tentativelyAccept | /decline.
proposed carries a counter-proposed time; Graph only honors it on
tentativelyAccept and decline (ignored for Accept).
Sourcepub async fn move_event_to_calendar(
&self,
account: &str,
event_id: &str,
destination_calendar_id: &str,
) -> Result<(), ClientError>
pub async fn move_event_to_calendar( &self, account: &str, event_id: &str, destination_calendar_id: &str, ) -> Result<(), ClientError>
PATCH /me/events/{id} with calendar@odata.bind: move between calendars.