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 search_messages(
&self,
account: &str,
query: &str,
limit: usize,
) -> Result<Vec<Message>, ClientError>
pub async fn search_messages( &self, account: &str, query: &str, limit: usize, ) -> Result<Vec<Message>, ClientError>
GET /me/messages with $search="<query>" for a given account.
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 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 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 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 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 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,
) -> Result<(), ClientError>
pub async fn rsvp_event( &self, account: &str, event_id: &str, kind: RsvpKind, comment: &str, send_response: bool, ) -> Result<(), ClientError>
POST /me/events/{id}/accept | /tentativelyAccept | /decline.
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.
Sourcepub async fn search_events(
&self,
account: &str,
query: &str,
limit: usize,
) -> Result<Vec<Event>, ClientError>
pub async fn search_events( &self, account: &str, query: &str, limit: usize, ) -> Result<Vec<Event>, ClientError>
GET /me/events?$search=“