1#[cfg(any(
6 feature = "rustls-aws",
7 feature = "rustls-ring",
8 feature = "native-tls"
9))]
10use core::time::Duration;
11use core::{any::Any, error::Error, fmt};
12
13use alloc::{
14 boxed::Box,
15 string::{String, ToString},
16 vec::Vec,
17};
18use std::io::{self, Read, Write};
19
20use io_http::rfc6750::bearer::HttpAuthBearer;
21#[cfg(any(
24 feature = "rustls-aws",
25 feature = "rustls-ring",
26 feature = "native-tls"
27))]
28pub use pimalaya_stream::tls::*;
29#[cfg(any(
30 feature = "rustls-aws",
31 feature = "rustls-ring",
32 feature = "native-tls"
33))]
34use pimalaya_stream::{
35 proxy::Proxy,
36 stream::{Stream, TcpConnectOptions, TlsConnectOptions},
37};
38use serde::de::DeserializeOwned;
39#[cfg(any(
40 feature = "rustls-aws",
41 feature = "rustls-ring",
42 feature = "native-tls"
43))]
44use url::Url;
45
46#[cfg(any(
47 feature = "rustls-aws",
48 feature = "rustls-ring",
49 feature = "native-tls"
50))]
51use crate::v1::send::MSGRAPH_API_BASE;
52use crate::{
53 coroutine::*,
54 v1::page::{MsgraphPage, MsgraphPageGet},
55 v1::rest::batch::{MsgraphBatch, MsgraphBatchRequest, MsgraphBatchResponses},
56 v1::rest::users::{
57 MsgraphUser,
58 calendars::{
59 MsgraphCalendar,
60 create::MsgraphCalendarCreate,
61 delete::MsgraphCalendarDelete,
62 get::MsgraphCalendarGet,
63 list::{
64 MsgraphCalendarsList, MsgraphCalendarsListParams, MsgraphCalendarsListResponse,
65 },
66 update::MsgraphCalendarUpdate,
67 },
68 contact_folders::{
69 MsgraphContactFolder,
70 child_folders::MsgraphContactChildFoldersList,
71 create::MsgraphContactFolderCreate,
72 delete::MsgraphContactFolderDelete,
73 get::MsgraphContactFolderGet,
74 list::{
75 MsgraphContactFoldersList, MsgraphContactFoldersListParams,
76 MsgraphContactFoldersListResponse,
77 },
78 update::MsgraphContactFolderUpdate,
79 },
80 contacts::{
81 MsgraphContact,
82 create::MsgraphContactCreate,
83 delete::MsgraphContactDelete,
84 delta::{MsgraphContactsDelta, MsgraphContactsDeltaResponse},
85 get::MsgraphContactGet,
86 list::{MsgraphContactsList, MsgraphContactsListParams, MsgraphContactsListResponse},
87 update::MsgraphContactUpdate,
88 },
89 events::{
90 MsgraphEvent,
91 calendar_view::MsgraphCalendarView,
92 create::MsgraphEventCreate,
93 delete::MsgraphEventDelete,
94 delta::{MsgraphEventsDelta, MsgraphEventsDeltaResponse},
95 get::MsgraphEventGet,
96 instances::MsgraphEventInstances,
97 list::{MsgraphEventsList, MsgraphEventsListParams, MsgraphEventsListResponse},
98 update::MsgraphEventUpdate,
99 },
100 get::MsgraphUserGet,
101 mail_folders::{
102 MsgraphMailFolder,
103 child_folders::MsgraphMailChildFoldersList,
104 copy::MsgraphMailFolderCopy,
105 create::MsgraphMailFolderCreate,
106 delete::MsgraphMailFolderDelete,
107 get::MsgraphMailFolderGet,
108 list::{
109 MsgraphMailFoldersList, MsgraphMailFoldersListParams,
110 MsgraphMailFoldersListResponse,
111 },
112 r#move::MsgraphMailFolderMove,
113 update::MsgraphMailFolderUpdate,
114 },
115 messages::{
116 MsgraphMessage,
117 attachments::{
118 MsgraphAttachment,
119 create::MsgraphAttachmentCreate,
120 delete::MsgraphAttachmentDelete,
121 get_raw::MsgraphAttachmentGetRaw,
122 list::{MsgraphAttachmentsList, MsgraphAttachmentsListResponse},
123 },
124 copy::MsgraphMessageCopy,
125 create::MsgraphMessageCreate,
126 create_mime::MsgraphMessageCreateMime,
127 delete::MsgraphMessageDelete,
128 delta::{
129 MsgraphMessagesDelta, MsgraphMessagesDeltaParams, MsgraphMessagesDeltaResponse,
130 },
131 get::MsgraphMessageGet,
132 get_raw::MsgraphMessageGetRaw,
133 list::{MsgraphMessagesList, MsgraphMessagesListParams, MsgraphMessagesListResponse},
134 r#move::MsgraphMessageMove,
135 send::MsgraphMessageSend,
136 update::MsgraphMessageUpdate,
137 },
138 send_mail::{MsgraphMailSend, MsgraphMailSendMime},
139 todo::{
140 lists::{
141 MsgraphTodoList,
142 create::MsgraphTodoListCreate,
143 delete::MsgraphTodoListDelete,
144 delta::{MsgraphTodoListsDelta, MsgraphTodoListsDeltaResponse},
145 get::MsgraphTodoListGet,
146 list::{
147 MsgraphTodoListsList, MsgraphTodoListsListParams, MsgraphTodoListsListResponse,
148 },
149 update::MsgraphTodoListUpdate,
150 },
151 tasks::{
152 MsgraphTodoTask,
153 checklist_items::list::{
154 MsgraphChecklistItemsList, MsgraphChecklistItemsListResponse,
155 },
156 create::MsgraphTodoTaskCreate,
157 delete::MsgraphTodoTaskDelete,
158 delta::{MsgraphTodoTasksDelta, MsgraphTodoTasksDeltaResponse},
159 get::MsgraphTodoTaskGet,
160 list::{
161 MsgraphTodoTasksList, MsgraphTodoTasksListParams, MsgraphTodoTasksListResponse,
162 },
163 update::MsgraphTodoTaskUpdate,
164 },
165 },
166 },
167 v1::send::{MsgraphNoResponse, MsgraphSendError, MsgraphSendOutput},
168};
169
170#[derive(Debug)]
172pub enum MsgraphClientStdError {
173 Send(MsgraphSendError),
175 Io(io::Error),
177 #[cfg(any(
179 feature = "rustls-aws",
180 feature = "rustls-ring",
181 feature = "native-tls"
182 ))]
183 Tls(anyhow::Error),
184 #[cfg(any(
186 feature = "rustls-aws",
187 feature = "rustls-ring",
188 feature = "native-tls"
189 ))]
190 UrlMissingHost(String),
191 #[cfg(any(
193 feature = "rustls-aws",
194 feature = "rustls-ring",
195 feature = "native-tls"
196 ))]
197 UrlUnsupportedScheme {
198 url: String,
200 scheme: String,
202 },
203}
204
205impl fmt::Display for MsgraphClientStdError {
206 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
207 match self {
208 Self::Send(err) => err.fmt(f),
209 Self::Io(err) => err.fmt(f),
210 #[cfg(any(
211 feature = "rustls-aws",
212 feature = "rustls-ring",
213 feature = "native-tls"
214 ))]
215 Self::Tls(err) => err.fmt(f),
216 #[cfg(any(
217 feature = "rustls-aws",
218 feature = "rustls-ring",
219 feature = "native-tls"
220 ))]
221 Self::UrlMissingHost(url) => write!(f, "Microsoft Graph URL `{url}` has no host"),
222 #[cfg(any(
223 feature = "rustls-aws",
224 feature = "rustls-ring",
225 feature = "native-tls"
226 ))]
227 Self::UrlUnsupportedScheme { url, scheme } => write!(
228 f,
229 "Microsoft Graph URL `{url}` has unsupported scheme `{scheme}` (expected `http` or `https`)"
230 ),
231 }
232 }
233}
234
235impl Error for MsgraphClientStdError {
236 fn source(&self) -> Option<&(dyn Error + 'static)> {
237 match self {
238 Self::Send(err) => err.source(),
239 Self::Io(err) => err.source(),
240 #[cfg(any(
241 feature = "rustls-aws",
242 feature = "rustls-ring",
243 feature = "native-tls"
244 ))]
245 Self::Tls(err) => err.source(),
246 #[cfg(any(
247 feature = "rustls-aws",
248 feature = "rustls-ring",
249 feature = "native-tls"
250 ))]
251 _ => None,
252 }
253 }
254}
255
256impl From<MsgraphSendError> for MsgraphClientStdError {
257 fn from(err: MsgraphSendError) -> Self {
258 Self::Send(err)
259 }
260}
261
262impl From<io::Error> for MsgraphClientStdError {
263 fn from(err: io::Error) -> Self {
264 Self::Io(err)
265 }
266}
267
268#[cfg(any(
269 feature = "rustls-aws",
270 feature = "rustls-ring",
271 feature = "native-tls"
272))]
273impl From<anyhow::Error> for MsgraphClientStdError {
274 fn from(err: anyhow::Error) -> Self {
275 Self::Tls(err)
276 }
277}
278
279pub struct MsgraphClientStdConnectOptions {
282 #[cfg(any(
284 feature = "rustls-aws",
285 feature = "rustls-ring",
286 feature = "native-tls"
287 ))]
288 pub tls: Tls,
289 #[cfg(any(
292 feature = "rustls-aws",
293 feature = "rustls-ring",
294 feature = "native-tls"
295 ))]
296 pub proxy: Proxy,
297 pub user_id: String,
299}
300
301impl Default for MsgraphClientStdConnectOptions {
302 fn default() -> Self {
303 Self {
304 #[cfg(any(
305 feature = "rustls-aws",
306 feature = "rustls-ring",
307 feature = "native-tls"
308 ))]
309 tls: Tls::default(),
310 #[cfg(any(
311 feature = "rustls-aws",
312 feature = "rustls-ring",
313 feature = "native-tls"
314 ))]
315 proxy: Proxy::default(),
316 user_id: String::from("me"),
317 }
318 }
319}
320
321const READ_BUFFER_SIZE: usize = 16 * 1024;
322
323pub struct MsgraphClientStd {
326 pub stream: Box<dyn MsgraphStream>,
328 pub auth: HttpAuthBearer,
330 pub user_id: String,
332}
333
334impl MsgraphClientStd {
335 pub fn new<S: Read + Write + Send + 'static>(
337 stream: S,
338 token: impl ToString,
339 options: MsgraphClientStdConnectOptions,
340 ) -> Self {
341 Self {
342 stream: Box::new(stream),
343 auth: HttpAuthBearer::new(token.to_string()),
344 user_id: options.user_id,
345 }
346 }
347
348 #[cfg(any(
351 feature = "rustls-aws",
352 feature = "rustls-ring",
353 feature = "native-tls"
354 ))]
355 pub fn connect(
356 token: impl ToString,
357 options: MsgraphClientStdConnectOptions,
358 ) -> Result<Self, MsgraphClientStdError> {
359 let MsgraphClientStdConnectOptions {
360 tls,
361 proxy,
362 user_id,
363 } = options;
364
365 let url = Url::parse(MSGRAPH_API_BASE).expect("Microsoft Graph API base URL is valid");
366 let host = url
367 .host_str()
368 .ok_or_else(|| MsgraphClientStdError::UrlMissingHost(url.to_string()))?;
369
370 let stream = match url.scheme() {
371 "http" => {
372 let port = url.port().unwrap_or(80);
373 let opts = TcpConnectOptions {
374 proxy,
375 ..Default::default()
376 };
377
378 Stream::connect_tcp(host, port, opts)?
379 }
380 "https" => {
381 let port = url.port().unwrap_or(443);
382 let opts = TlsConnectOptions {
383 tls: tls.clone(),
384 proxy,
385 ..Default::default()
386 };
387
388 Stream::connect_tls(host, port, opts)?
389 }
390 scheme => {
391 return Err(MsgraphClientStdError::UrlUnsupportedScheme {
392 url: url.to_string(),
393 scheme: scheme.to_string(),
394 });
395 }
396 };
397
398 stream.set_read_timeout(Some(Duration::from_secs(30)))?;
399
400 Ok(Self {
401 stream: Box::new(stream),
402 auth: HttpAuthBearer::new(token.to_string()),
403 user_id,
404 })
405 }
406
407 pub fn set_stream<S: Read + Write + Send + 'static>(&mut self, stream: S) {
409 self.stream = Box::new(stream);
410 }
411
412 pub fn run<C, T>(
415 &mut self,
416 mut coroutine: C,
417 ) -> Result<MsgraphSendOutput<T>, MsgraphClientStdError>
418 where
419 C: MsgraphCoroutine<
420 Yield = MsgraphYield,
421 Return = Result<MsgraphSendOutput<T>, MsgraphSendError>,
422 >,
423 {
424 let mut buf = [0u8; READ_BUFFER_SIZE];
425 let mut arg: Option<&[u8]> = None;
426
427 loop {
428 match coroutine.resume(arg.take()) {
429 MsgraphCoroutineState::Complete(Ok(out)) => return Ok(out),
430 MsgraphCoroutineState::Complete(Err(err)) => return Err(err.into()),
431 MsgraphCoroutineState::Yielded(MsgraphYield::WantsRead) => {
432 let n = self.stream.read(&mut buf)?;
433 arg = Some(&buf[..n]);
434 }
435 MsgraphCoroutineState::Yielded(MsgraphYield::WantsWrite(bytes)) => {
436 self.stream.write_all(&bytes)?;
437 arg = None;
438 }
439 }
440 }
441 }
442
443 pub fn batch(
445 &mut self,
446 requests: &[MsgraphBatchRequest],
447 ) -> Result<MsgraphSendOutput<MsgraphBatchResponses>, MsgraphClientStdError> {
448 let coroutine = MsgraphBatch::new(&self.auth, requests)?;
449 self.run(coroutine)
450 }
451
452 pub fn page_get<T: DeserializeOwned>(
455 &mut self,
456 link: &str,
457 max_page_size: Option<u32>,
458 ) -> Result<MsgraphSendOutput<MsgraphPage<T>>, MsgraphClientStdError> {
459 let mut coroutine = MsgraphPageGet::new(&self.auth, link)?;
460 if let Some(size) = max_page_size {
461 coroutine = coroutine.max_page_size(size);
462 }
463 self.run(coroutine)
464 }
465
466 pub fn me(&mut self) -> Result<MsgraphSendOutput<MsgraphUser>, MsgraphClientStdError> {
468 let coroutine = MsgraphUserGet::new(&self.auth, &self.user_id)?;
469 self.run(coroutine)
470 }
471
472 pub fn mail_folders_list(
474 &mut self,
475 params: &MsgraphMailFoldersListParams,
476 ) -> Result<MsgraphSendOutput<MsgraphMailFoldersListResponse>, MsgraphClientStdError> {
477 let coroutine = MsgraphMailFoldersList::new(&self.auth, &self.user_id, params)?;
478 self.run(coroutine)
479 }
480
481 pub fn mail_folder_get(
483 &mut self,
484 id: &str,
485 ) -> Result<MsgraphSendOutput<MsgraphMailFolder>, MsgraphClientStdError> {
486 let coroutine = MsgraphMailFolderGet::new(&self.auth, &self.user_id, id)?;
487 self.run(coroutine)
488 }
489
490 pub fn mail_folder_create(
492 &mut self,
493 folder: &MsgraphMailFolder,
494 ) -> Result<MsgraphSendOutput<MsgraphMailFolder>, MsgraphClientStdError> {
495 let coroutine = MsgraphMailFolderCreate::new(&self.auth, &self.user_id, folder)?;
496 self.run(coroutine)
497 }
498
499 pub fn mail_folder_update(
501 &mut self,
502 id: &str,
503 folder: &MsgraphMailFolder,
504 ) -> Result<MsgraphSendOutput<MsgraphMailFolder>, MsgraphClientStdError> {
505 let coroutine = MsgraphMailFolderUpdate::new(&self.auth, &self.user_id, id, folder)?;
506 self.run(coroutine)
507 }
508
509 pub fn mail_folder_delete(
511 &mut self,
512 id: &str,
513 ) -> Result<MsgraphSendOutput<MsgraphNoResponse>, MsgraphClientStdError> {
514 let coroutine = MsgraphMailFolderDelete::new(&self.auth, &self.user_id, id)?;
515 self.run(coroutine)
516 }
517
518 pub fn mail_folder_copy(
520 &mut self,
521 id: &str,
522 destination: &str,
523 ) -> Result<MsgraphSendOutput<MsgraphMailFolder>, MsgraphClientStdError> {
524 let coroutine = MsgraphMailFolderCopy::new(&self.auth, &self.user_id, id, destination)?;
525 self.run(coroutine)
526 }
527
528 pub fn mail_folder_move(
530 &mut self,
531 id: &str,
532 destination: &str,
533 ) -> Result<MsgraphSendOutput<MsgraphMailFolder>, MsgraphClientStdError> {
534 let coroutine = MsgraphMailFolderMove::new(&self.auth, &self.user_id, id, destination)?;
535 self.run(coroutine)
536 }
537
538 pub fn mail_child_folders_list(
540 &mut self,
541 id: &str,
542 params: &MsgraphMailFoldersListParams,
543 ) -> Result<MsgraphSendOutput<MsgraphMailFoldersListResponse>, MsgraphClientStdError> {
544 let coroutine = MsgraphMailChildFoldersList::new(&self.auth, &self.user_id, id, params)?;
545 self.run(coroutine)
546 }
547
548 pub fn contact_folders_list(
550 &mut self,
551 params: &MsgraphContactFoldersListParams,
552 ) -> Result<MsgraphSendOutput<MsgraphContactFoldersListResponse>, MsgraphClientStdError> {
553 let coroutine = MsgraphContactFoldersList::new(&self.auth, &self.user_id, params)?;
554 self.run(coroutine)
555 }
556
557 pub fn contact_folder_get(
559 &mut self,
560 id: &str,
561 ) -> Result<MsgraphSendOutput<MsgraphContactFolder>, MsgraphClientStdError> {
562 let coroutine = MsgraphContactFolderGet::new(&self.auth, &self.user_id, id)?;
563 self.run(coroutine)
564 }
565
566 pub fn contact_folder_create(
568 &mut self,
569 folder: &MsgraphContactFolder,
570 ) -> Result<MsgraphSendOutput<MsgraphContactFolder>, MsgraphClientStdError> {
571 let coroutine = MsgraphContactFolderCreate::new(&self.auth, &self.user_id, folder)?;
572 self.run(coroutine)
573 }
574
575 pub fn contact_folder_update(
577 &mut self,
578 id: &str,
579 folder: &MsgraphContactFolder,
580 ) -> Result<MsgraphSendOutput<MsgraphContactFolder>, MsgraphClientStdError> {
581 let coroutine = MsgraphContactFolderUpdate::new(&self.auth, &self.user_id, id, folder)?;
582 self.run(coroutine)
583 }
584
585 pub fn contact_folder_delete(
587 &mut self,
588 id: &str,
589 ) -> Result<MsgraphSendOutput<MsgraphNoResponse>, MsgraphClientStdError> {
590 let coroutine = MsgraphContactFolderDelete::new(&self.auth, &self.user_id, id)?;
591 self.run(coroutine)
592 }
593
594 pub fn contact_child_folders_list(
596 &mut self,
597 id: &str,
598 params: &MsgraphContactFoldersListParams,
599 ) -> Result<MsgraphSendOutput<MsgraphContactFoldersListResponse>, MsgraphClientStdError> {
600 let coroutine = MsgraphContactChildFoldersList::new(&self.auth, &self.user_id, id, params)?;
601 self.run(coroutine)
602 }
603
604 pub fn contacts_list(
607 &mut self,
608 folder: Option<&str>,
609 params: &MsgraphContactsListParams,
610 ) -> Result<MsgraphSendOutput<MsgraphContactsListResponse>, MsgraphClientStdError> {
611 let coroutine = MsgraphContactsList::new(&self.auth, &self.user_id, folder, params)?;
612 self.run(coroutine)
613 }
614
615 pub fn contact_get(
617 &mut self,
618 id: &str,
619 expand: Option<&str>,
620 ) -> Result<MsgraphSendOutput<MsgraphContact>, MsgraphClientStdError> {
621 let coroutine = MsgraphContactGet::new(&self.auth, &self.user_id, id, expand)?;
622 self.run(coroutine)
623 }
624
625 pub fn contact_create(
628 &mut self,
629 folder: Option<&str>,
630 contact: &MsgraphContact,
631 ) -> Result<MsgraphSendOutput<MsgraphContact>, MsgraphClientStdError> {
632 let coroutine = MsgraphContactCreate::new(&self.auth, &self.user_id, folder, contact)?;
633 self.run(coroutine)
634 }
635
636 pub fn contact_update(
638 &mut self,
639 id: &str,
640 contact: &MsgraphContact,
641 ) -> Result<MsgraphSendOutput<MsgraphContact>, MsgraphClientStdError> {
642 let coroutine = MsgraphContactUpdate::new(&self.auth, &self.user_id, id, contact)?;
643 self.run(coroutine)
644 }
645
646 pub fn contact_delete(
648 &mut self,
649 id: &str,
650 ) -> Result<MsgraphSendOutput<MsgraphNoResponse>, MsgraphClientStdError> {
651 let coroutine = MsgraphContactDelete::new(&self.auth, &self.user_id, id)?;
652 self.run(coroutine)
653 }
654
655 pub fn contacts_delta(
658 &mut self,
659 folder: Option<&str>,
660 select: Option<&str>,
661 ) -> Result<MsgraphSendOutput<MsgraphContactsDeltaResponse>, MsgraphClientStdError> {
662 let coroutine = MsgraphContactsDelta::new(&self.auth, &self.user_id, folder, select)?;
663 self.run(coroutine)
664 }
665
666 pub fn contacts_delta_from_link(
669 &mut self,
670 link: &str,
671 ) -> Result<MsgraphSendOutput<MsgraphContactsDeltaResponse>, MsgraphClientStdError> {
672 let coroutine = MsgraphContactsDelta::from_link(&self.auth, link)?;
673 self.run(coroutine)
674 }
675
676 pub fn contacts_delta_with_page_size(
680 &mut self,
681 folder: Option<&str>,
682 select: Option<&str>,
683 max_page_size: Option<u32>,
684 ) -> Result<MsgraphSendOutput<MsgraphContactsDeltaResponse>, MsgraphClientStdError> {
685 let mut coroutine = MsgraphContactsDelta::new(&self.auth, &self.user_id, folder, select)?;
686 if let Some(size) = max_page_size {
687 coroutine = coroutine.max_page_size(size);
688 }
689 self.run(coroutine)
690 }
691
692 pub fn contacts_delta_from_link_with_page_size(
696 &mut self,
697 link: &str,
698 max_page_size: Option<u32>,
699 ) -> Result<MsgraphSendOutput<MsgraphContactsDeltaResponse>, MsgraphClientStdError> {
700 let mut coroutine = MsgraphContactsDelta::from_link(&self.auth, link)?;
701 if let Some(size) = max_page_size {
702 coroutine = coroutine.max_page_size(size);
703 }
704 self.run(coroutine)
705 }
706
707 pub fn calendars_list(
709 &mut self,
710 params: &MsgraphCalendarsListParams,
711 ) -> Result<MsgraphSendOutput<MsgraphCalendarsListResponse>, MsgraphClientStdError> {
712 let coroutine = MsgraphCalendarsList::new(&self.auth, &self.user_id, params)?;
713 self.run(coroutine)
714 }
715
716 pub fn calendar_get(
718 &mut self,
719 id: &str,
720 ) -> Result<MsgraphSendOutput<MsgraphCalendar>, MsgraphClientStdError> {
721 let coroutine = MsgraphCalendarGet::new(&self.auth, &self.user_id, id)?;
722 self.run(coroutine)
723 }
724
725 pub fn calendar_create(
727 &mut self,
728 calendar: &MsgraphCalendar,
729 ) -> Result<MsgraphSendOutput<MsgraphCalendar>, MsgraphClientStdError> {
730 let coroutine = MsgraphCalendarCreate::new(&self.auth, &self.user_id, calendar)?;
731 self.run(coroutine)
732 }
733
734 pub fn calendar_update(
736 &mut self,
737 id: &str,
738 calendar: &MsgraphCalendar,
739 ) -> Result<MsgraphSendOutput<MsgraphCalendar>, MsgraphClientStdError> {
740 let coroutine = MsgraphCalendarUpdate::new(&self.auth, &self.user_id, id, calendar)?;
741 self.run(coroutine)
742 }
743
744 pub fn calendar_delete(
746 &mut self,
747 id: &str,
748 ) -> Result<MsgraphSendOutput<MsgraphNoResponse>, MsgraphClientStdError> {
749 let coroutine = MsgraphCalendarDelete::new(&self.auth, &self.user_id, id)?;
750 self.run(coroutine)
751 }
752
753 pub fn events_list(
756 &mut self,
757 calendar: Option<&str>,
758 params: &MsgraphEventsListParams,
759 ) -> Result<MsgraphSendOutput<MsgraphEventsListResponse>, MsgraphClientStdError> {
760 let coroutine = MsgraphEventsList::new(&self.auth, &self.user_id, calendar, params)?;
761 self.run(coroutine)
762 }
763
764 pub fn events_list_from_link(
766 &mut self,
767 link: &str,
768 ) -> Result<MsgraphSendOutput<MsgraphEventsListResponse>, MsgraphClientStdError> {
769 let coroutine = MsgraphEventsList::from_link(&self.auth, link)?;
770 self.run(coroutine)
771 }
772
773 pub fn event_get(
776 &mut self,
777 id: &str,
778 select: Option<&str>,
779 expand: Option<&str>,
780 ) -> Result<MsgraphSendOutput<MsgraphEvent>, MsgraphClientStdError> {
781 let coroutine = MsgraphEventGet::new(&self.auth, &self.user_id, id, select, expand)?;
782 self.run(coroutine)
783 }
784
785 pub fn event_create(
788 &mut self,
789 calendar: Option<&str>,
790 event: &MsgraphEvent,
791 ) -> Result<MsgraphSendOutput<MsgraphEvent>, MsgraphClientStdError> {
792 let coroutine = MsgraphEventCreate::new(&self.auth, &self.user_id, calendar, event)?;
793 self.run(coroutine)
794 }
795
796 pub fn event_update(
798 &mut self,
799 id: &str,
800 event: &MsgraphEvent,
801 ) -> Result<MsgraphSendOutput<MsgraphEvent>, MsgraphClientStdError> {
802 let coroutine = MsgraphEventUpdate::new(&self.auth, &self.user_id, id, event)?;
803 self.run(coroutine)
804 }
805
806 pub fn event_delete(
808 &mut self,
809 id: &str,
810 ) -> Result<MsgraphSendOutput<MsgraphNoResponse>, MsgraphClientStdError> {
811 let coroutine = MsgraphEventDelete::new(&self.auth, &self.user_id, id)?;
812 self.run(coroutine)
813 }
814
815 pub fn event_instances(
817 &mut self,
818 id: &str,
819 start: &str,
820 end: &str,
821 params: &MsgraphEventsListParams,
822 ) -> Result<MsgraphSendOutput<MsgraphEventsListResponse>, MsgraphClientStdError> {
823 let coroutine =
824 MsgraphEventInstances::new(&self.auth, &self.user_id, id, start, end, params)?;
825 self.run(coroutine)
826 }
827
828 pub fn calendar_view(
830 &mut self,
831 calendar: Option<&str>,
832 start: &str,
833 end: &str,
834 params: &MsgraphEventsListParams,
835 ) -> Result<MsgraphSendOutput<MsgraphEventsListResponse>, MsgraphClientStdError> {
836 let coroutine =
837 MsgraphCalendarView::new(&self.auth, &self.user_id, calendar, start, end, params)?;
838 self.run(coroutine)
839 }
840
841 pub fn events_delta(
843 &mut self,
844 calendar: Option<&str>,
845 start: &str,
846 end: &str,
847 ) -> Result<MsgraphSendOutput<MsgraphEventsDeltaResponse>, MsgraphClientStdError> {
848 let coroutine = MsgraphEventsDelta::new(&self.auth, &self.user_id, calendar, start, end)?;
849 self.run(coroutine)
850 }
851
852 pub fn events_delta_from_link(
854 &mut self,
855 link: &str,
856 ) -> Result<MsgraphSendOutput<MsgraphEventsDeltaResponse>, MsgraphClientStdError> {
857 let coroutine = MsgraphEventsDelta::from_link(&self.auth, link)?;
858 self.run(coroutine)
859 }
860
861 pub fn events_delta_with_page_size(
865 &mut self,
866 calendar: Option<&str>,
867 start: &str,
868 end: &str,
869 max_page_size: Option<u32>,
870 ) -> Result<MsgraphSendOutput<MsgraphEventsDeltaResponse>, MsgraphClientStdError> {
871 let mut coroutine =
872 MsgraphEventsDelta::new(&self.auth, &self.user_id, calendar, start, end)?;
873 if let Some(size) = max_page_size {
874 coroutine = coroutine.max_page_size(size);
875 }
876 self.run(coroutine)
877 }
878
879 pub fn events_delta_from_link_with_page_size(
883 &mut self,
884 link: &str,
885 max_page_size: Option<u32>,
886 ) -> Result<MsgraphSendOutput<MsgraphEventsDeltaResponse>, MsgraphClientStdError> {
887 let mut coroutine = MsgraphEventsDelta::from_link(&self.auth, link)?;
888 if let Some(size) = max_page_size {
889 coroutine = coroutine.max_page_size(size);
890 }
891 self.run(coroutine)
892 }
893
894 pub fn todo_lists_list(
896 &mut self,
897 params: &MsgraphTodoListsListParams,
898 ) -> Result<MsgraphSendOutput<MsgraphTodoListsListResponse>, MsgraphClientStdError> {
899 let coroutine = MsgraphTodoListsList::new(&self.auth, &self.user_id, params)?;
900 self.run(coroutine)
901 }
902
903 pub fn todo_lists_list_from_link(
905 &mut self,
906 link: &str,
907 ) -> Result<MsgraphSendOutput<MsgraphTodoListsListResponse>, MsgraphClientStdError> {
908 let coroutine = MsgraphTodoListsList::from_link(&self.auth, link)?;
909 self.run(coroutine)
910 }
911
912 pub fn todo_list_get(
914 &mut self,
915 id: &str,
916 ) -> Result<MsgraphSendOutput<MsgraphTodoList>, MsgraphClientStdError> {
917 let coroutine = MsgraphTodoListGet::new(&self.auth, &self.user_id, id)?;
918 self.run(coroutine)
919 }
920
921 pub fn todo_list_create(
923 &mut self,
924 list: &MsgraphTodoList,
925 ) -> Result<MsgraphSendOutput<MsgraphTodoList>, MsgraphClientStdError> {
926 let coroutine = MsgraphTodoListCreate::new(&self.auth, &self.user_id, list)?;
927 self.run(coroutine)
928 }
929
930 pub fn todo_list_update(
932 &mut self,
933 id: &str,
934 list: &MsgraphTodoList,
935 ) -> Result<MsgraphSendOutput<MsgraphTodoList>, MsgraphClientStdError> {
936 let coroutine = MsgraphTodoListUpdate::new(&self.auth, &self.user_id, id, list)?;
937 self.run(coroutine)
938 }
939
940 pub fn todo_list_delete(
942 &mut self,
943 id: &str,
944 ) -> Result<MsgraphSendOutput<MsgraphNoResponse>, MsgraphClientStdError> {
945 let coroutine = MsgraphTodoListDelete::new(&self.auth, &self.user_id, id)?;
946 self.run(coroutine)
947 }
948
949 pub fn todo_lists_delta(
951 &mut self,
952 ) -> Result<MsgraphSendOutput<MsgraphTodoListsDeltaResponse>, MsgraphClientStdError> {
953 let coroutine = MsgraphTodoListsDelta::new(&self.auth, &self.user_id)?;
954 self.run(coroutine)
955 }
956
957 pub fn todo_lists_delta_from_link(
959 &mut self,
960 link: &str,
961 ) -> Result<MsgraphSendOutput<MsgraphTodoListsDeltaResponse>, MsgraphClientStdError> {
962 let coroutine = MsgraphTodoListsDelta::from_link(&self.auth, link)?;
963 self.run(coroutine)
964 }
965
966 pub fn todo_tasks_list(
968 &mut self,
969 list_id: &str,
970 params: &MsgraphTodoTasksListParams,
971 ) -> Result<MsgraphSendOutput<MsgraphTodoTasksListResponse>, MsgraphClientStdError> {
972 let coroutine = MsgraphTodoTasksList::new(&self.auth, &self.user_id, list_id, params)?;
973 self.run(coroutine)
974 }
975
976 pub fn todo_tasks_list_from_link(
978 &mut self,
979 link: &str,
980 ) -> Result<MsgraphSendOutput<MsgraphTodoTasksListResponse>, MsgraphClientStdError> {
981 let coroutine = MsgraphTodoTasksList::from_link(&self.auth, link)?;
982 self.run(coroutine)
983 }
984
985 pub fn todo_task_get(
988 &mut self,
989 list_id: &str,
990 id: &str,
991 select: Option<&str>,
992 expand: Option<&str>,
993 ) -> Result<MsgraphSendOutput<MsgraphTodoTask>, MsgraphClientStdError> {
994 let coroutine =
995 MsgraphTodoTaskGet::new(&self.auth, &self.user_id, list_id, id, select, expand)?;
996 self.run(coroutine)
997 }
998
999 pub fn todo_task_create(
1001 &mut self,
1002 list_id: &str,
1003 task: &MsgraphTodoTask,
1004 ) -> Result<MsgraphSendOutput<MsgraphTodoTask>, MsgraphClientStdError> {
1005 let coroutine = MsgraphTodoTaskCreate::new(&self.auth, &self.user_id, list_id, task)?;
1006 self.run(coroutine)
1007 }
1008
1009 pub fn todo_task_update(
1011 &mut self,
1012 list_id: &str,
1013 id: &str,
1014 task: &MsgraphTodoTask,
1015 ) -> Result<MsgraphSendOutput<MsgraphTodoTask>, MsgraphClientStdError> {
1016 let coroutine = MsgraphTodoTaskUpdate::new(&self.auth, &self.user_id, list_id, id, task)?;
1017 self.run(coroutine)
1018 }
1019
1020 pub fn todo_task_delete(
1022 &mut self,
1023 list_id: &str,
1024 id: &str,
1025 ) -> Result<MsgraphSendOutput<MsgraphNoResponse>, MsgraphClientStdError> {
1026 let coroutine = MsgraphTodoTaskDelete::new(&self.auth, &self.user_id, list_id, id)?;
1027 self.run(coroutine)
1028 }
1029
1030 pub fn todo_tasks_delta(
1033 &mut self,
1034 list_id: &str,
1035 select: Option<&str>,
1036 ) -> Result<MsgraphSendOutput<MsgraphTodoTasksDeltaResponse>, MsgraphClientStdError> {
1037 let coroutine = MsgraphTodoTasksDelta::new(&self.auth, &self.user_id, list_id, select)?;
1038 self.run(coroutine)
1039 }
1040
1041 pub fn todo_tasks_delta_from_link(
1043 &mut self,
1044 link: &str,
1045 ) -> Result<MsgraphSendOutput<MsgraphTodoTasksDeltaResponse>, MsgraphClientStdError> {
1046 let coroutine = MsgraphTodoTasksDelta::from_link(&self.auth, link)?;
1047 self.run(coroutine)
1048 }
1049
1050 pub fn checklist_items_list(
1053 &mut self,
1054 list_id: &str,
1055 task_id: &str,
1056 ) -> Result<MsgraphSendOutput<MsgraphChecklistItemsListResponse>, MsgraphClientStdError> {
1057 let coroutine =
1058 MsgraphChecklistItemsList::new(&self.auth, &self.user_id, list_id, task_id)?;
1059 self.run(coroutine)
1060 }
1061
1062 pub fn messages_list(
1065 &mut self,
1066 folder: Option<&str>,
1067 params: &MsgraphMessagesListParams,
1068 ) -> Result<MsgraphSendOutput<MsgraphMessagesListResponse>, MsgraphClientStdError> {
1069 let coroutine = MsgraphMessagesList::new(&self.auth, &self.user_id, folder, params)?;
1070 self.run(coroutine)
1071 }
1072
1073 pub fn message_get(
1076 &mut self,
1077 id: &str,
1078 select: Option<&str>,
1079 expand: Option<&str>,
1080 ) -> Result<MsgraphSendOutput<MsgraphMessage>, MsgraphClientStdError> {
1081 let coroutine = MsgraphMessageGet::new(&self.auth, &self.user_id, id, select, expand)?;
1082 self.run(coroutine)
1083 }
1084
1085 pub fn message_get_raw(
1087 &mut self,
1088 id: &str,
1089 ) -> Result<MsgraphSendOutput<Vec<u8>>, MsgraphClientStdError> {
1090 let coroutine = MsgraphMessageGetRaw::new(&self.auth, &self.user_id, id)?;
1091 self.run(coroutine)
1092 }
1093
1094 pub fn message_create(
1097 &mut self,
1098 folder: Option<&str>,
1099 message: &MsgraphMessage,
1100 ) -> Result<MsgraphSendOutput<MsgraphMessage>, MsgraphClientStdError> {
1101 let coroutine = MsgraphMessageCreate::new(&self.auth, &self.user_id, folder, message)?;
1102 self.run(coroutine)
1103 }
1104
1105 pub fn message_create_mime(
1108 &mut self,
1109 folder: Option<&str>,
1110 raw: &[u8],
1111 ) -> Result<MsgraphSendOutput<MsgraphMessage>, MsgraphClientStdError> {
1112 let coroutine = MsgraphMessageCreateMime::new(&self.auth, &self.user_id, folder, raw)?;
1113 self.run(coroutine)
1114 }
1115
1116 pub fn message_update(
1118 &mut self,
1119 id: &str,
1120 message: &MsgraphMessage,
1121 ) -> Result<MsgraphSendOutput<MsgraphMessage>, MsgraphClientStdError> {
1122 let coroutine = MsgraphMessageUpdate::new(&self.auth, &self.user_id, id, message)?;
1123 self.run(coroutine)
1124 }
1125
1126 pub fn message_delete(
1128 &mut self,
1129 id: &str,
1130 ) -> Result<MsgraphSendOutput<MsgraphNoResponse>, MsgraphClientStdError> {
1131 let coroutine = MsgraphMessageDelete::new(&self.auth, &self.user_id, id)?;
1132 self.run(coroutine)
1133 }
1134
1135 pub fn message_move(
1137 &mut self,
1138 id: &str,
1139 destination: &str,
1140 ) -> Result<MsgraphSendOutput<MsgraphMessage>, MsgraphClientStdError> {
1141 let coroutine = MsgraphMessageMove::new(&self.auth, &self.user_id, id, destination)?;
1142 self.run(coroutine)
1143 }
1144
1145 pub fn message_copy(
1147 &mut self,
1148 id: &str,
1149 destination: &str,
1150 ) -> Result<MsgraphSendOutput<MsgraphMessage>, MsgraphClientStdError> {
1151 let coroutine = MsgraphMessageCopy::new(&self.auth, &self.user_id, id, destination)?;
1152 self.run(coroutine)
1153 }
1154
1155 pub fn messages_delta(
1158 &mut self,
1159 folder: Option<&str>,
1160 select: Option<&str>,
1161 ) -> Result<MsgraphSendOutput<MsgraphMessagesDeltaResponse>, MsgraphClientStdError> {
1162 let coroutine = MsgraphMessagesDelta::new(&self.auth, &self.user_id, folder, select)?;
1163 self.run(coroutine)
1164 }
1165
1166 pub fn messages_delta_from_link(
1169 &mut self,
1170 link: &str,
1171 ) -> Result<MsgraphSendOutput<MsgraphMessagesDeltaResponse>, MsgraphClientStdError> {
1172 let coroutine = MsgraphMessagesDelta::from_link(&self.auth, link)?;
1173 self.run(coroutine)
1174 }
1175
1176 pub fn messages_delta_with_params(
1179 &mut self,
1180 folder: Option<&str>,
1181 params: &MsgraphMessagesDeltaParams,
1182 ) -> Result<MsgraphSendOutput<MsgraphMessagesDeltaResponse>, MsgraphClientStdError> {
1183 let coroutine =
1184 MsgraphMessagesDelta::with_params(&self.auth, &self.user_id, folder, params)?;
1185 self.run(coroutine)
1186 }
1187
1188 pub fn messages_delta_from_link_with_page_size(
1192 &mut self,
1193 link: &str,
1194 max_page_size: Option<u32>,
1195 ) -> Result<MsgraphSendOutput<MsgraphMessagesDeltaResponse>, MsgraphClientStdError> {
1196 let mut coroutine = MsgraphMessagesDelta::from_link(&self.auth, link)?;
1197 if let Some(size) = max_page_size {
1198 coroutine = coroutine.max_page_size(size);
1199 }
1200 self.run(coroutine)
1201 }
1202
1203 pub fn attachment_create(
1205 &mut self,
1206 message_id: &str,
1207 name: &str,
1208 content: &[u8],
1209 content_type: Option<&str>,
1210 ) -> Result<MsgraphSendOutput<MsgraphAttachment>, MsgraphClientStdError> {
1211 let coroutine = MsgraphAttachmentCreate::new(
1212 &self.auth,
1213 &self.user_id,
1214 message_id,
1215 name,
1216 content,
1217 content_type,
1218 )?;
1219 self.run(coroutine)
1220 }
1221
1222 pub fn attachments_list(
1224 &mut self,
1225 message_id: &str,
1226 ) -> Result<MsgraphSendOutput<MsgraphAttachmentsListResponse>, MsgraphClientStdError> {
1227 let coroutine = MsgraphAttachmentsList::new(&self.auth, &self.user_id, message_id)?;
1228 self.run(coroutine)
1229 }
1230
1231 pub fn attachment_get_raw(
1233 &mut self,
1234 message_id: &str,
1235 attachment_id: &str,
1236 ) -> Result<MsgraphSendOutput<Vec<u8>>, MsgraphClientStdError> {
1237 let coroutine =
1238 MsgraphAttachmentGetRaw::new(&self.auth, &self.user_id, message_id, attachment_id)?;
1239 self.run(coroutine)
1240 }
1241
1242 pub fn attachment_delete(
1244 &mut self,
1245 message_id: &str,
1246 attachment_id: &str,
1247 ) -> Result<MsgraphSendOutput<MsgraphNoResponse>, MsgraphClientStdError> {
1248 let coroutine =
1249 MsgraphAttachmentDelete::new(&self.auth, &self.user_id, message_id, attachment_id)?;
1250 self.run(coroutine)
1251 }
1252
1253 pub fn message_send(
1255 &mut self,
1256 id: &str,
1257 ) -> Result<MsgraphSendOutput<MsgraphNoResponse>, MsgraphClientStdError> {
1258 let coroutine = MsgraphMessageSend::new(&self.auth, &self.user_id, id)?;
1259 self.run(coroutine)
1260 }
1261
1262 pub fn mail_send(
1264 &mut self,
1265 message: &MsgraphMessage,
1266 save_to_sent_items: bool,
1267 ) -> Result<MsgraphSendOutput<MsgraphNoResponse>, MsgraphClientStdError> {
1268 let coroutine =
1269 MsgraphMailSend::new(&self.auth, &self.user_id, message, save_to_sent_items)?;
1270 self.run(coroutine)
1271 }
1272
1273 pub fn mail_send_mime(
1276 &mut self,
1277 raw: &[u8],
1278 ) -> Result<MsgraphSendOutput<MsgraphNoResponse>, MsgraphClientStdError> {
1279 let coroutine = MsgraphMailSendMime::new(&self.auth, &self.user_id, raw)?;
1280 self.run(coroutine)
1281 }
1282}
1283
1284impl fmt::Debug for MsgraphClientStd {
1285 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1286 f.debug_struct("MsgraphClientStd")
1287 .field("auth", &self.auth)
1288 .field("user_id", &self.user_id)
1289 .finish_non_exhaustive()
1290 }
1291}
1292
1293pub trait MsgraphStream: Read + Write + Send + Any {
1296 fn as_any_mut(&mut self) -> &mut dyn Any;
1298}
1299
1300impl<T: Read + Write + Send + Any> MsgraphStream for T {
1301 fn as_any_mut(&mut self) -> &mut dyn Any {
1302 self
1303 }
1304}