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.