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 permanent_delete::MsgraphCalendarPermanentDelete,
67 update::MsgraphCalendarUpdate,
68 },
69 contact_folders::{
70 MsgraphContactFolder,
71 child_folders::MsgraphContactChildFoldersList,
72 create::MsgraphContactFolderCreate,
73 delete::MsgraphContactFolderDelete,
74 get::MsgraphContactFolderGet,
75 list::{
76 MsgraphContactFoldersList, MsgraphContactFoldersListParams,
77 MsgraphContactFoldersListResponse,
78 },
79 permanent_delete::MsgraphContactFolderPermanentDelete,
80 update::MsgraphContactFolderUpdate,
81 },
82 contacts::{
83 MsgraphContact,
84 create::MsgraphContactCreate,
85 delete::MsgraphContactDelete,
86 delta::{MsgraphContactsDelta, MsgraphContactsDeltaResponse},
87 get::MsgraphContactGet,
88 list::{MsgraphContactsList, MsgraphContactsListParams, MsgraphContactsListResponse},
89 update::MsgraphContactUpdate,
90 },
91 events::{
92 MsgraphEvent,
93 calendar_view::MsgraphCalendarView,
94 create::MsgraphEventCreate,
95 delete::MsgraphEventDelete,
96 delta::{MsgraphEventsDelta, MsgraphEventsDeltaResponse},
97 get::MsgraphEventGet,
98 instances::MsgraphEventInstances,
99 list::{MsgraphEventsList, MsgraphEventsListParams, MsgraphEventsListResponse},
100 update::MsgraphEventUpdate,
101 },
102 get::MsgraphUserGet,
103 mail_folders::{
104 MsgraphMailFolder,
105 child_folders::MsgraphMailChildFoldersList,
106 copy::MsgraphMailFolderCopy,
107 create::MsgraphMailFolderCreate,
108 delete::MsgraphMailFolderDelete,
109 get::MsgraphMailFolderGet,
110 list::{
111 MsgraphMailFoldersList, MsgraphMailFoldersListParams,
112 MsgraphMailFoldersListResponse,
113 },
114 r#move::MsgraphMailFolderMove,
115 permanent_delete::MsgraphMailFolderPermanentDelete,
116 update::MsgraphMailFolderUpdate,
117 },
118 messages::{
119 MsgraphMessage,
120 attachments::{
121 MsgraphAttachment,
122 create::MsgraphAttachmentCreate,
123 delete::MsgraphAttachmentDelete,
124 get_raw::MsgraphAttachmentGetRaw,
125 list::{MsgraphAttachmentsList, MsgraphAttachmentsListResponse},
126 },
127 copy::MsgraphMessageCopy,
128 create::MsgraphMessageCreate,
129 create_mime::MsgraphMessageCreateMime,
130 delete::MsgraphMessageDelete,
131 delta::{
132 MsgraphMessagesDelta, MsgraphMessagesDeltaParams, MsgraphMessagesDeltaResponse,
133 },
134 get::MsgraphMessageGet,
135 get_raw::MsgraphMessageGetRaw,
136 list::{MsgraphMessagesList, MsgraphMessagesListParams, MsgraphMessagesListResponse},
137 r#move::MsgraphMessageMove,
138 permanent_delete::MsgraphMessagePermanentDelete,
139 send::MsgraphMessageSend,
140 update::MsgraphMessageUpdate,
141 },
142 send_mail::{MsgraphMailSend, MsgraphMailSendMime},
143 todo::{
144 lists::{
145 MsgraphTodoList,
146 create::MsgraphTodoListCreate,
147 delete::MsgraphTodoListDelete,
148 delta::{MsgraphTodoListsDelta, MsgraphTodoListsDeltaResponse},
149 get::MsgraphTodoListGet,
150 list::{
151 MsgraphTodoListsList, MsgraphTodoListsListParams, MsgraphTodoListsListResponse,
152 },
153 update::MsgraphTodoListUpdate,
154 },
155 tasks::{
156 MsgraphTodoTask,
157 checklist_items::list::{
158 MsgraphChecklistItemsList, MsgraphChecklistItemsListResponse,
159 },
160 create::MsgraphTodoTaskCreate,
161 delete::MsgraphTodoTaskDelete,
162 delta::{MsgraphTodoTasksDelta, MsgraphTodoTasksDeltaResponse},
163 get::MsgraphTodoTaskGet,
164 list::{
165 MsgraphTodoTasksList, MsgraphTodoTasksListParams, MsgraphTodoTasksListResponse,
166 },
167 update::MsgraphTodoTaskUpdate,
168 },
169 },
170 },
171 v1::send::{MsgraphNoResponse, MsgraphSendError, MsgraphSendOutput},
172};
173
174#[derive(Debug)]
176pub enum MsgraphClientStdError {
177 Send(MsgraphSendError),
179 Io(io::Error),
181 #[cfg(any(
183 feature = "rustls-aws",
184 feature = "rustls-ring",
185 feature = "native-tls"
186 ))]
187 Tls(anyhow::Error),
188 #[cfg(any(
190 feature = "rustls-aws",
191 feature = "rustls-ring",
192 feature = "native-tls"
193 ))]
194 UrlMissingHost(String),
195 #[cfg(any(
197 feature = "rustls-aws",
198 feature = "rustls-ring",
199 feature = "native-tls"
200 ))]
201 UrlUnsupportedScheme {
202 url: String,
204 scheme: String,
206 },
207}
208
209impl fmt::Display for MsgraphClientStdError {
210 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
211 match self {
212 Self::Send(err) => err.fmt(f),
213 Self::Io(err) => err.fmt(f),
214 #[cfg(any(
215 feature = "rustls-aws",
216 feature = "rustls-ring",
217 feature = "native-tls"
218 ))]
219 Self::Tls(err) => err.fmt(f),
220 #[cfg(any(
221 feature = "rustls-aws",
222 feature = "rustls-ring",
223 feature = "native-tls"
224 ))]
225 Self::UrlMissingHost(url) => write!(f, "Microsoft Graph URL `{url}` has no host"),
226 #[cfg(any(
227 feature = "rustls-aws",
228 feature = "rustls-ring",
229 feature = "native-tls"
230 ))]
231 Self::UrlUnsupportedScheme { url, scheme } => write!(
232 f,
233 "Microsoft Graph URL `{url}` has unsupported scheme `{scheme}` (expected `http` or `https`)"
234 ),
235 }
236 }
237}
238
239impl Error for MsgraphClientStdError {
240 fn source(&self) -> Option<&(dyn Error + 'static)> {
241 match self {
242 Self::Send(err) => err.source(),
243 Self::Io(err) => err.source(),
244 #[cfg(any(
245 feature = "rustls-aws",
246 feature = "rustls-ring",
247 feature = "native-tls"
248 ))]
249 Self::Tls(err) => err.source(),
250 #[cfg(any(
251 feature = "rustls-aws",
252 feature = "rustls-ring",
253 feature = "native-tls"
254 ))]
255 _ => None,
256 }
257 }
258}
259
260impl From<MsgraphSendError> for MsgraphClientStdError {
261 fn from(err: MsgraphSendError) -> Self {
262 Self::Send(err)
263 }
264}
265
266impl From<io::Error> for MsgraphClientStdError {
267 fn from(err: io::Error) -> Self {
268 Self::Io(err)
269 }
270}
271
272#[cfg(any(
273 feature = "rustls-aws",
274 feature = "rustls-ring",
275 feature = "native-tls"
276))]
277impl From<anyhow::Error> for MsgraphClientStdError {
278 fn from(err: anyhow::Error) -> Self {
279 Self::Tls(err)
280 }
281}
282
283pub struct MsgraphClientStdConnectOptions {
286 #[cfg(any(
288 feature = "rustls-aws",
289 feature = "rustls-ring",
290 feature = "native-tls"
291 ))]
292 pub tls: Tls,
293 #[cfg(any(
296 feature = "rustls-aws",
297 feature = "rustls-ring",
298 feature = "native-tls"
299 ))]
300 pub proxy: Proxy,
301 pub user_id: String,
303}
304
305impl Default for MsgraphClientStdConnectOptions {
306 fn default() -> Self {
307 Self {
308 #[cfg(any(
309 feature = "rustls-aws",
310 feature = "rustls-ring",
311 feature = "native-tls"
312 ))]
313 tls: Tls::default(),
314 #[cfg(any(
315 feature = "rustls-aws",
316 feature = "rustls-ring",
317 feature = "native-tls"
318 ))]
319 proxy: Proxy::default(),
320 user_id: String::from("me"),
321 }
322 }
323}
324
325const READ_BUFFER_SIZE: usize = 16 * 1024;
326
327pub struct MsgraphClientStd {
330 pub stream: Box<dyn MsgraphStream>,
332 pub auth: HttpAuthBearer,
334 pub user_id: String,
336}
337
338impl MsgraphClientStd {
339 pub fn new<S: Read + Write + Send + 'static>(
341 stream: S,
342 token: impl ToString,
343 options: MsgraphClientStdConnectOptions,
344 ) -> Self {
345 Self {
346 stream: Box::new(stream),
347 auth: HttpAuthBearer::new(token.to_string()),
348 user_id: options.user_id,
349 }
350 }
351
352 #[cfg(any(
355 feature = "rustls-aws",
356 feature = "rustls-ring",
357 feature = "native-tls"
358 ))]
359 pub fn connect(
360 token: impl ToString,
361 options: MsgraphClientStdConnectOptions,
362 ) -> Result<Self, MsgraphClientStdError> {
363 let MsgraphClientStdConnectOptions {
364 tls,
365 proxy,
366 user_id,
367 } = options;
368
369 let url = Url::parse(MSGRAPH_API_BASE).expect("Microsoft Graph API base URL is valid");
370 let host = url
371 .host_str()
372 .ok_or_else(|| MsgraphClientStdError::UrlMissingHost(url.to_string()))?;
373
374 let stream = match url.scheme() {
375 "http" => {
376 let port = url.port().unwrap_or(80);
377 let opts = TcpConnectOptions {
378 proxy,
379 ..Default::default()
380 };
381
382 Stream::connect_tcp(host, port, opts)?
383 }
384 "https" => {
385 let port = url.port().unwrap_or(443);
386 let opts = TlsConnectOptions {
387 tls: tls.clone(),
388 proxy,
389 ..Default::default()
390 };
391
392 Stream::connect_tls(host, port, opts)?
393 }
394 scheme => {
395 return Err(MsgraphClientStdError::UrlUnsupportedScheme {
396 url: url.to_string(),
397 scheme: scheme.to_string(),
398 });
399 }
400 };
401
402 stream.set_read_timeout(Some(Duration::from_secs(30)))?;
403
404 Ok(Self {
405 stream: Box::new(stream),
406 auth: HttpAuthBearer::new(token.to_string()),
407 user_id,
408 })
409 }
410
411 pub fn set_stream<S: Read + Write + Send + 'static>(&mut self, stream: S) {
413 self.stream = Box::new(stream);
414 }
415
416 pub fn run<C, T>(
419 &mut self,
420 mut coroutine: C,
421 ) -> Result<MsgraphSendOutput<T>, MsgraphClientStdError>
422 where
423 C: MsgraphCoroutine<
424 Yield = MsgraphYield,
425 Return = Result<MsgraphSendOutput<T>, MsgraphSendError>,
426 >,
427 {
428 let mut buf = [0u8; READ_BUFFER_SIZE];
429 let mut arg: Option<&[u8]> = None;
430
431 loop {
432 match coroutine.resume(arg.take()) {
433 MsgraphCoroutineState::Complete(Ok(out)) => return Ok(out),
434 MsgraphCoroutineState::Complete(Err(err)) => return Err(err.into()),
435 MsgraphCoroutineState::Yielded(MsgraphYield::WantsRead) => {
436 let n = self.stream.read(&mut buf)?;
437 arg = Some(&buf[..n]);
438 }
439 MsgraphCoroutineState::Yielded(MsgraphYield::WantsWrite(bytes)) => {
440 self.stream.write_all(&bytes)?;
441 arg = None;
442 }
443 }
444 }
445 }
446
447 pub fn batch(
449 &mut self,
450 requests: &[MsgraphBatchRequest],
451 ) -> Result<MsgraphSendOutput<MsgraphBatchResponses>, MsgraphClientStdError> {
452 let coroutine = MsgraphBatch::new(&self.auth, requests)?;
453 self.run(coroutine)
454 }
455
456 pub fn page_get<T: DeserializeOwned>(
459 &mut self,
460 link: &str,
461 max_page_size: Option<u32>,
462 ) -> Result<MsgraphSendOutput<MsgraphPage<T>>, MsgraphClientStdError> {
463 let mut coroutine = MsgraphPageGet::new(&self.auth, link)?;
464 if let Some(size) = max_page_size {
465 coroutine = coroutine.max_page_size(size);
466 }
467 self.run(coroutine)
468 }
469
470 pub fn me(&mut self) -> Result<MsgraphSendOutput<MsgraphUser>, MsgraphClientStdError> {
472 let coroutine = MsgraphUserGet::new(&self.auth, &self.user_id)?;
473 self.run(coroutine)
474 }
475
476 pub fn mail_folders_list(
478 &mut self,
479 params: &MsgraphMailFoldersListParams,
480 ) -> Result<MsgraphSendOutput<MsgraphMailFoldersListResponse>, MsgraphClientStdError> {
481 let coroutine = MsgraphMailFoldersList::new(&self.auth, &self.user_id, params)?;
482 self.run(coroutine)
483 }
484
485 pub fn mail_folder_get(
487 &mut self,
488 id: &str,
489 ) -> Result<MsgraphSendOutput<MsgraphMailFolder>, MsgraphClientStdError> {
490 let coroutine = MsgraphMailFolderGet::new(&self.auth, &self.user_id, id)?;
491 self.run(coroutine)
492 }
493
494 pub fn mail_folder_create(
496 &mut self,
497 folder: &MsgraphMailFolder,
498 ) -> Result<MsgraphSendOutput<MsgraphMailFolder>, MsgraphClientStdError> {
499 let coroutine = MsgraphMailFolderCreate::new(&self.auth, &self.user_id, folder)?;
500 self.run(coroutine)
501 }
502
503 pub fn mail_folder_update(
505 &mut self,
506 id: &str,
507 folder: &MsgraphMailFolder,
508 ) -> Result<MsgraphSendOutput<MsgraphMailFolder>, MsgraphClientStdError> {
509 let coroutine = MsgraphMailFolderUpdate::new(&self.auth, &self.user_id, id, folder)?;
510 self.run(coroutine)
511 }
512
513 pub fn mail_folder_delete(
515 &mut self,
516 id: &str,
517 ) -> Result<MsgraphSendOutput<MsgraphNoResponse>, MsgraphClientStdError> {
518 let coroutine = MsgraphMailFolderDelete::new(&self.auth, &self.user_id, id)?;
519 self.run(coroutine)
520 }
521
522 pub fn mail_folder_permanent_delete(
524 &mut self,
525 id: &str,
526 ) -> Result<MsgraphSendOutput<MsgraphNoResponse>, MsgraphClientStdError> {
527 let coroutine = MsgraphMailFolderPermanentDelete::new(&self.auth, &self.user_id, id)?;
528 self.run(coroutine)
529 }
530
531 pub fn mail_folder_copy(
533 &mut self,
534 id: &str,
535 destination: &str,
536 ) -> Result<MsgraphSendOutput<MsgraphMailFolder>, MsgraphClientStdError> {
537 let coroutine = MsgraphMailFolderCopy::new(&self.auth, &self.user_id, id, destination)?;
538 self.run(coroutine)
539 }
540
541 pub fn mail_folder_move(
543 &mut self,
544 id: &str,
545 destination: &str,
546 ) -> Result<MsgraphSendOutput<MsgraphMailFolder>, MsgraphClientStdError> {
547 let coroutine = MsgraphMailFolderMove::new(&self.auth, &self.user_id, id, destination)?;
548 self.run(coroutine)
549 }
550
551 pub fn mail_child_folders_list(
553 &mut self,
554 id: &str,
555 params: &MsgraphMailFoldersListParams,
556 ) -> Result<MsgraphSendOutput<MsgraphMailFoldersListResponse>, MsgraphClientStdError> {
557 let coroutine = MsgraphMailChildFoldersList::new(&self.auth, &self.user_id, id, params)?;
558 self.run(coroutine)
559 }
560
561 pub fn contact_folders_list(
563 &mut self,
564 params: &MsgraphContactFoldersListParams,
565 ) -> Result<MsgraphSendOutput<MsgraphContactFoldersListResponse>, MsgraphClientStdError> {
566 let coroutine = MsgraphContactFoldersList::new(&self.auth, &self.user_id, params)?;
567 self.run(coroutine)
568 }
569
570 pub fn contact_folder_get(
572 &mut self,
573 id: &str,
574 ) -> Result<MsgraphSendOutput<MsgraphContactFolder>, MsgraphClientStdError> {
575 let coroutine = MsgraphContactFolderGet::new(&self.auth, &self.user_id, id)?;
576 self.run(coroutine)
577 }
578
579 pub fn contact_folder_create(
581 &mut self,
582 folder: &MsgraphContactFolder,
583 ) -> Result<MsgraphSendOutput<MsgraphContactFolder>, MsgraphClientStdError> {
584 let coroutine = MsgraphContactFolderCreate::new(&self.auth, &self.user_id, folder)?;
585 self.run(coroutine)
586 }
587
588 pub fn contact_folder_update(
590 &mut self,
591 id: &str,
592 folder: &MsgraphContactFolder,
593 ) -> Result<MsgraphSendOutput<MsgraphContactFolder>, MsgraphClientStdError> {
594 let coroutine = MsgraphContactFolderUpdate::new(&self.auth, &self.user_id, id, folder)?;
595 self.run(coroutine)
596 }
597
598 pub fn contact_folder_delete(
600 &mut self,
601 id: &str,
602 ) -> Result<MsgraphSendOutput<MsgraphNoResponse>, MsgraphClientStdError> {
603 let coroutine = MsgraphContactFolderDelete::new(&self.auth, &self.user_id, id)?;
604 self.run(coroutine)
605 }
606
607 pub fn contact_folder_permanent_delete(
609 &mut self,
610 id: &str,
611 ) -> Result<MsgraphSendOutput<MsgraphNoResponse>, MsgraphClientStdError> {
612 let coroutine = MsgraphContactFolderPermanentDelete::new(&self.auth, &self.user_id, id)?;
613 self.run(coroutine)
614 }
615
616 pub fn contact_child_folders_list(
618 &mut self,
619 id: &str,
620 params: &MsgraphContactFoldersListParams,
621 ) -> Result<MsgraphSendOutput<MsgraphContactFoldersListResponse>, MsgraphClientStdError> {
622 let coroutine = MsgraphContactChildFoldersList::new(&self.auth, &self.user_id, id, params)?;
623 self.run(coroutine)
624 }
625
626 pub fn contacts_list(
629 &mut self,
630 folder: Option<&str>,
631 params: &MsgraphContactsListParams,
632 ) -> Result<MsgraphSendOutput<MsgraphContactsListResponse>, MsgraphClientStdError> {
633 let coroutine = MsgraphContactsList::new(&self.auth, &self.user_id, folder, params)?;
634 self.run(coroutine)
635 }
636
637 pub fn contact_get(
639 &mut self,
640 id: &str,
641 expand: Option<&str>,
642 ) -> Result<MsgraphSendOutput<MsgraphContact>, MsgraphClientStdError> {
643 let coroutine = MsgraphContactGet::new(&self.auth, &self.user_id, id, expand)?;
644 self.run(coroutine)
645 }
646
647 pub fn contact_create(
650 &mut self,
651 folder: Option<&str>,
652 contact: &MsgraphContact,
653 ) -> Result<MsgraphSendOutput<MsgraphContact>, MsgraphClientStdError> {
654 let coroutine = MsgraphContactCreate::new(&self.auth, &self.user_id, folder, contact)?;
655 self.run(coroutine)
656 }
657
658 pub fn contact_update(
660 &mut self,
661 id: &str,
662 contact: &MsgraphContact,
663 ) -> Result<MsgraphSendOutput<MsgraphContact>, MsgraphClientStdError> {
664 let coroutine = MsgraphContactUpdate::new(&self.auth, &self.user_id, id, contact)?;
665 self.run(coroutine)
666 }
667
668 pub fn contact_delete(
670 &mut self,
671 id: &str,
672 ) -> Result<MsgraphSendOutput<MsgraphNoResponse>, MsgraphClientStdError> {
673 let coroutine = MsgraphContactDelete::new(&self.auth, &self.user_id, id)?;
674 self.run(coroutine)
675 }
676
677 pub fn contacts_delta(
680 &mut self,
681 folder: Option<&str>,
682 select: Option<&str>,
683 ) -> Result<MsgraphSendOutput<MsgraphContactsDeltaResponse>, MsgraphClientStdError> {
684 let coroutine = MsgraphContactsDelta::new(&self.auth, &self.user_id, folder, select)?;
685 self.run(coroutine)
686 }
687
688 pub fn contacts_delta_from_link(
691 &mut self,
692 link: &str,
693 ) -> Result<MsgraphSendOutput<MsgraphContactsDeltaResponse>, MsgraphClientStdError> {
694 let coroutine = MsgraphContactsDelta::from_link(&self.auth, link)?;
695 self.run(coroutine)
696 }
697
698 pub fn contacts_delta_with_page_size(
702 &mut self,
703 folder: Option<&str>,
704 select: Option<&str>,
705 max_page_size: Option<u32>,
706 ) -> Result<MsgraphSendOutput<MsgraphContactsDeltaResponse>, MsgraphClientStdError> {
707 let mut coroutine = MsgraphContactsDelta::new(&self.auth, &self.user_id, folder, select)?;
708 if let Some(size) = max_page_size {
709 coroutine = coroutine.max_page_size(size);
710 }
711 self.run(coroutine)
712 }
713
714 pub fn contacts_delta_from_link_with_page_size(
718 &mut self,
719 link: &str,
720 max_page_size: Option<u32>,
721 ) -> Result<MsgraphSendOutput<MsgraphContactsDeltaResponse>, MsgraphClientStdError> {
722 let mut coroutine = MsgraphContactsDelta::from_link(&self.auth, link)?;
723 if let Some(size) = max_page_size {
724 coroutine = coroutine.max_page_size(size);
725 }
726 self.run(coroutine)
727 }
728
729 pub fn calendars_list(
731 &mut self,
732 params: &MsgraphCalendarsListParams,
733 ) -> Result<MsgraphSendOutput<MsgraphCalendarsListResponse>, MsgraphClientStdError> {
734 let coroutine = MsgraphCalendarsList::new(&self.auth, &self.user_id, params)?;
735 self.run(coroutine)
736 }
737
738 pub fn calendar_get(
740 &mut self,
741 id: &str,
742 ) -> Result<MsgraphSendOutput<MsgraphCalendar>, MsgraphClientStdError> {
743 let coroutine = MsgraphCalendarGet::new(&self.auth, &self.user_id, id)?;
744 self.run(coroutine)
745 }
746
747 pub fn calendar_create(
749 &mut self,
750 calendar: &MsgraphCalendar,
751 ) -> Result<MsgraphSendOutput<MsgraphCalendar>, MsgraphClientStdError> {
752 let coroutine = MsgraphCalendarCreate::new(&self.auth, &self.user_id, calendar)?;
753 self.run(coroutine)
754 }
755
756 pub fn calendar_update(
758 &mut self,
759 id: &str,
760 calendar: &MsgraphCalendar,
761 ) -> Result<MsgraphSendOutput<MsgraphCalendar>, MsgraphClientStdError> {
762 let coroutine = MsgraphCalendarUpdate::new(&self.auth, &self.user_id, id, calendar)?;
763 self.run(coroutine)
764 }
765
766 pub fn calendar_delete(
768 &mut self,
769 id: &str,
770 ) -> Result<MsgraphSendOutput<MsgraphNoResponse>, MsgraphClientStdError> {
771 let coroutine = MsgraphCalendarDelete::new(&self.auth, &self.user_id, id)?;
772 self.run(coroutine)
773 }
774
775 pub fn calendar_permanent_delete(
777 &mut self,
778 id: &str,
779 ) -> Result<MsgraphSendOutput<MsgraphNoResponse>, MsgraphClientStdError> {
780 let coroutine = MsgraphCalendarPermanentDelete::new(&self.auth, &self.user_id, id)?;
781 self.run(coroutine)
782 }
783
784 pub fn events_list(
787 &mut self,
788 calendar: Option<&str>,
789 params: &MsgraphEventsListParams,
790 ) -> Result<MsgraphSendOutput<MsgraphEventsListResponse>, MsgraphClientStdError> {
791 let coroutine = MsgraphEventsList::new(&self.auth, &self.user_id, calendar, params)?;
792 self.run(coroutine)
793 }
794
795 pub fn events_list_from_link(
797 &mut self,
798 link: &str,
799 ) -> Result<MsgraphSendOutput<MsgraphEventsListResponse>, MsgraphClientStdError> {
800 let coroutine = MsgraphEventsList::from_link(&self.auth, link)?;
801 self.run(coroutine)
802 }
803
804 pub fn event_get(
807 &mut self,
808 id: &str,
809 select: Option<&str>,
810 expand: Option<&str>,
811 ) -> Result<MsgraphSendOutput<MsgraphEvent>, MsgraphClientStdError> {
812 let coroutine = MsgraphEventGet::new(&self.auth, &self.user_id, id, select, expand)?;
813 self.run(coroutine)
814 }
815
816 pub fn event_create(
819 &mut self,
820 calendar: Option<&str>,
821 event: &MsgraphEvent,
822 ) -> Result<MsgraphSendOutput<MsgraphEvent>, MsgraphClientStdError> {
823 let coroutine = MsgraphEventCreate::new(&self.auth, &self.user_id, calendar, event)?;
824 self.run(coroutine)
825 }
826
827 pub fn event_update(
829 &mut self,
830 id: &str,
831 event: &MsgraphEvent,
832 ) -> Result<MsgraphSendOutput<MsgraphEvent>, MsgraphClientStdError> {
833 let coroutine = MsgraphEventUpdate::new(&self.auth, &self.user_id, id, event)?;
834 self.run(coroutine)
835 }
836
837 pub fn event_delete(
839 &mut self,
840 id: &str,
841 ) -> Result<MsgraphSendOutput<MsgraphNoResponse>, MsgraphClientStdError> {
842 let coroutine = MsgraphEventDelete::new(&self.auth, &self.user_id, id)?;
843 self.run(coroutine)
844 }
845
846 pub fn event_instances(
848 &mut self,
849 id: &str,
850 start: &str,
851 end: &str,
852 params: &MsgraphEventsListParams,
853 ) -> Result<MsgraphSendOutput<MsgraphEventsListResponse>, MsgraphClientStdError> {
854 let coroutine =
855 MsgraphEventInstances::new(&self.auth, &self.user_id, id, start, end, params)?;
856 self.run(coroutine)
857 }
858
859 pub fn calendar_view(
861 &mut self,
862 calendar: Option<&str>,
863 start: &str,
864 end: &str,
865 params: &MsgraphEventsListParams,
866 ) -> Result<MsgraphSendOutput<MsgraphEventsListResponse>, MsgraphClientStdError> {
867 let coroutine =
868 MsgraphCalendarView::new(&self.auth, &self.user_id, calendar, start, end, params)?;
869 self.run(coroutine)
870 }
871
872 pub fn events_delta(
874 &mut self,
875 calendar: Option<&str>,
876 start: &str,
877 end: &str,
878 ) -> Result<MsgraphSendOutput<MsgraphEventsDeltaResponse>, MsgraphClientStdError> {
879 let coroutine = MsgraphEventsDelta::new(&self.auth, &self.user_id, calendar, start, end)?;
880 self.run(coroutine)
881 }
882
883 pub fn events_delta_from_link(
885 &mut self,
886 link: &str,
887 ) -> Result<MsgraphSendOutput<MsgraphEventsDeltaResponse>, MsgraphClientStdError> {
888 let coroutine = MsgraphEventsDelta::from_link(&self.auth, link)?;
889 self.run(coroutine)
890 }
891
892 pub fn events_delta_with_page_size(
896 &mut self,
897 calendar: Option<&str>,
898 start: &str,
899 end: &str,
900 max_page_size: Option<u32>,
901 ) -> Result<MsgraphSendOutput<MsgraphEventsDeltaResponse>, MsgraphClientStdError> {
902 let mut coroutine =
903 MsgraphEventsDelta::new(&self.auth, &self.user_id, calendar, start, end)?;
904 if let Some(size) = max_page_size {
905 coroutine = coroutine.max_page_size(size);
906 }
907 self.run(coroutine)
908 }
909
910 pub fn events_delta_from_link_with_page_size(
914 &mut self,
915 link: &str,
916 max_page_size: Option<u32>,
917 ) -> Result<MsgraphSendOutput<MsgraphEventsDeltaResponse>, MsgraphClientStdError> {
918 let mut coroutine = MsgraphEventsDelta::from_link(&self.auth, link)?;
919 if let Some(size) = max_page_size {
920 coroutine = coroutine.max_page_size(size);
921 }
922 self.run(coroutine)
923 }
924
925 pub fn todo_lists_list(
927 &mut self,
928 params: &MsgraphTodoListsListParams,
929 ) -> Result<MsgraphSendOutput<MsgraphTodoListsListResponse>, MsgraphClientStdError> {
930 let coroutine = MsgraphTodoListsList::new(&self.auth, &self.user_id, params)?;
931 self.run(coroutine)
932 }
933
934 pub fn todo_lists_list_from_link(
936 &mut self,
937 link: &str,
938 ) -> Result<MsgraphSendOutput<MsgraphTodoListsListResponse>, MsgraphClientStdError> {
939 let coroutine = MsgraphTodoListsList::from_link(&self.auth, link)?;
940 self.run(coroutine)
941 }
942
943 pub fn todo_list_get(
945 &mut self,
946 id: &str,
947 ) -> Result<MsgraphSendOutput<MsgraphTodoList>, MsgraphClientStdError> {
948 let coroutine = MsgraphTodoListGet::new(&self.auth, &self.user_id, id)?;
949 self.run(coroutine)
950 }
951
952 pub fn todo_list_create(
954 &mut self,
955 list: &MsgraphTodoList,
956 ) -> Result<MsgraphSendOutput<MsgraphTodoList>, MsgraphClientStdError> {
957 let coroutine = MsgraphTodoListCreate::new(&self.auth, &self.user_id, list)?;
958 self.run(coroutine)
959 }
960
961 pub fn todo_list_update(
963 &mut self,
964 id: &str,
965 list: &MsgraphTodoList,
966 ) -> Result<MsgraphSendOutput<MsgraphTodoList>, MsgraphClientStdError> {
967 let coroutine = MsgraphTodoListUpdate::new(&self.auth, &self.user_id, id, list)?;
968 self.run(coroutine)
969 }
970
971 pub fn todo_list_delete(
973 &mut self,
974 id: &str,
975 ) -> Result<MsgraphSendOutput<MsgraphNoResponse>, MsgraphClientStdError> {
976 let coroutine = MsgraphTodoListDelete::new(&self.auth, &self.user_id, id)?;
977 self.run(coroutine)
978 }
979
980 pub fn todo_lists_delta(
982 &mut self,
983 ) -> Result<MsgraphSendOutput<MsgraphTodoListsDeltaResponse>, MsgraphClientStdError> {
984 let coroutine = MsgraphTodoListsDelta::new(&self.auth, &self.user_id)?;
985 self.run(coroutine)
986 }
987
988 pub fn todo_lists_delta_from_link(
990 &mut self,
991 link: &str,
992 ) -> Result<MsgraphSendOutput<MsgraphTodoListsDeltaResponse>, MsgraphClientStdError> {
993 let coroutine = MsgraphTodoListsDelta::from_link(&self.auth, link)?;
994 self.run(coroutine)
995 }
996
997 pub fn todo_tasks_list(
999 &mut self,
1000 list_id: &str,
1001 params: &MsgraphTodoTasksListParams,
1002 ) -> Result<MsgraphSendOutput<MsgraphTodoTasksListResponse>, MsgraphClientStdError> {
1003 let coroutine = MsgraphTodoTasksList::new(&self.auth, &self.user_id, list_id, params)?;
1004 self.run(coroutine)
1005 }
1006
1007 pub fn todo_tasks_list_from_link(
1009 &mut self,
1010 link: &str,
1011 ) -> Result<MsgraphSendOutput<MsgraphTodoTasksListResponse>, MsgraphClientStdError> {
1012 let coroutine = MsgraphTodoTasksList::from_link(&self.auth, link)?;
1013 self.run(coroutine)
1014 }
1015
1016 pub fn todo_task_get(
1019 &mut self,
1020 list_id: &str,
1021 id: &str,
1022 select: Option<&str>,
1023 expand: Option<&str>,
1024 ) -> Result<MsgraphSendOutput<MsgraphTodoTask>, MsgraphClientStdError> {
1025 let coroutine =
1026 MsgraphTodoTaskGet::new(&self.auth, &self.user_id, list_id, id, select, expand)?;
1027 self.run(coroutine)
1028 }
1029
1030 pub fn todo_task_create(
1032 &mut self,
1033 list_id: &str,
1034 task: &MsgraphTodoTask,
1035 ) -> Result<MsgraphSendOutput<MsgraphTodoTask>, MsgraphClientStdError> {
1036 let coroutine = MsgraphTodoTaskCreate::new(&self.auth, &self.user_id, list_id, task)?;
1037 self.run(coroutine)
1038 }
1039
1040 pub fn todo_task_update(
1042 &mut self,
1043 list_id: &str,
1044 id: &str,
1045 task: &MsgraphTodoTask,
1046 ) -> Result<MsgraphSendOutput<MsgraphTodoTask>, MsgraphClientStdError> {
1047 let coroutine = MsgraphTodoTaskUpdate::new(&self.auth, &self.user_id, list_id, id, task)?;
1048 self.run(coroutine)
1049 }
1050
1051 pub fn todo_task_delete(
1053 &mut self,
1054 list_id: &str,
1055 id: &str,
1056 ) -> Result<MsgraphSendOutput<MsgraphNoResponse>, MsgraphClientStdError> {
1057 let coroutine = MsgraphTodoTaskDelete::new(&self.auth, &self.user_id, list_id, id)?;
1058 self.run(coroutine)
1059 }
1060
1061 pub fn todo_tasks_delta(
1064 &mut self,
1065 list_id: &str,
1066 select: Option<&str>,
1067 ) -> Result<MsgraphSendOutput<MsgraphTodoTasksDeltaResponse>, MsgraphClientStdError> {
1068 let coroutine = MsgraphTodoTasksDelta::new(&self.auth, &self.user_id, list_id, select)?;
1069 self.run(coroutine)
1070 }
1071
1072 pub fn todo_tasks_delta_from_link(
1074 &mut self,
1075 link: &str,
1076 ) -> Result<MsgraphSendOutput<MsgraphTodoTasksDeltaResponse>, MsgraphClientStdError> {
1077 let coroutine = MsgraphTodoTasksDelta::from_link(&self.auth, link)?;
1078 self.run(coroutine)
1079 }
1080
1081 pub fn checklist_items_list(
1084 &mut self,
1085 list_id: &str,
1086 task_id: &str,
1087 ) -> Result<MsgraphSendOutput<MsgraphChecklistItemsListResponse>, MsgraphClientStdError> {
1088 let coroutine =
1089 MsgraphChecklistItemsList::new(&self.auth, &self.user_id, list_id, task_id)?;
1090 self.run(coroutine)
1091 }
1092
1093 pub fn messages_list(
1096 &mut self,
1097 folder: Option<&str>,
1098 params: &MsgraphMessagesListParams,
1099 ) -> Result<MsgraphSendOutput<MsgraphMessagesListResponse>, MsgraphClientStdError> {
1100 let coroutine = MsgraphMessagesList::new(&self.auth, &self.user_id, folder, params)?;
1101 self.run(coroutine)
1102 }
1103
1104 pub fn message_get(
1107 &mut self,
1108 id: &str,
1109 select: Option<&str>,
1110 expand: Option<&str>,
1111 ) -> Result<MsgraphSendOutput<MsgraphMessage>, MsgraphClientStdError> {
1112 let coroutine = MsgraphMessageGet::new(&self.auth, &self.user_id, id, select, expand)?;
1113 self.run(coroutine)
1114 }
1115
1116 pub fn message_get_raw(
1118 &mut self,
1119 id: &str,
1120 ) -> Result<MsgraphSendOutput<Vec<u8>>, MsgraphClientStdError> {
1121 let coroutine = MsgraphMessageGetRaw::new(&self.auth, &self.user_id, id)?;
1122 self.run(coroutine)
1123 }
1124
1125 pub fn message_create(
1128 &mut self,
1129 folder: Option<&str>,
1130 message: &MsgraphMessage,
1131 ) -> Result<MsgraphSendOutput<MsgraphMessage>, MsgraphClientStdError> {
1132 let coroutine = MsgraphMessageCreate::new(&self.auth, &self.user_id, folder, message)?;
1133 self.run(coroutine)
1134 }
1135
1136 pub fn message_create_mime(
1139 &mut self,
1140 folder: Option<&str>,
1141 raw: &[u8],
1142 ) -> Result<MsgraphSendOutput<MsgraphMessage>, MsgraphClientStdError> {
1143 let coroutine = MsgraphMessageCreateMime::new(&self.auth, &self.user_id, folder, raw)?;
1144 self.run(coroutine)
1145 }
1146
1147 pub fn message_update(
1149 &mut self,
1150 id: &str,
1151 message: &MsgraphMessage,
1152 ) -> Result<MsgraphSendOutput<MsgraphMessage>, MsgraphClientStdError> {
1153 let coroutine = MsgraphMessageUpdate::new(&self.auth, &self.user_id, id, message)?;
1154 self.run(coroutine)
1155 }
1156
1157 pub fn message_delete(
1159 &mut self,
1160 id: &str,
1161 ) -> Result<MsgraphSendOutput<MsgraphNoResponse>, MsgraphClientStdError> {
1162 let coroutine = MsgraphMessageDelete::new(&self.auth, &self.user_id, id)?;
1163 self.run(coroutine)
1164 }
1165
1166 pub fn message_permanent_delete(
1168 &mut self,
1169 id: &str,
1170 ) -> Result<MsgraphSendOutput<MsgraphNoResponse>, MsgraphClientStdError> {
1171 let coroutine = MsgraphMessagePermanentDelete::new(&self.auth, &self.user_id, id)?;
1172 self.run(coroutine)
1173 }
1174
1175 pub fn message_move(
1177 &mut self,
1178 id: &str,
1179 destination: &str,
1180 ) -> Result<MsgraphSendOutput<MsgraphMessage>, MsgraphClientStdError> {
1181 let coroutine = MsgraphMessageMove::new(&self.auth, &self.user_id, id, destination)?;
1182 self.run(coroutine)
1183 }
1184
1185 pub fn message_copy(
1187 &mut self,
1188 id: &str,
1189 destination: &str,
1190 ) -> Result<MsgraphSendOutput<MsgraphMessage>, MsgraphClientStdError> {
1191 let coroutine = MsgraphMessageCopy::new(&self.auth, &self.user_id, id, destination)?;
1192 self.run(coroutine)
1193 }
1194
1195 pub fn messages_delta(
1198 &mut self,
1199 folder: Option<&str>,
1200 select: Option<&str>,
1201 ) -> Result<MsgraphSendOutput<MsgraphMessagesDeltaResponse>, MsgraphClientStdError> {
1202 let coroutine = MsgraphMessagesDelta::new(&self.auth, &self.user_id, folder, select)?;
1203 self.run(coroutine)
1204 }
1205
1206 pub fn messages_delta_from_link(
1209 &mut self,
1210 link: &str,
1211 ) -> Result<MsgraphSendOutput<MsgraphMessagesDeltaResponse>, MsgraphClientStdError> {
1212 let coroutine = MsgraphMessagesDelta::from_link(&self.auth, link)?;
1213 self.run(coroutine)
1214 }
1215
1216 pub fn messages_delta_with_params(
1219 &mut self,
1220 folder: Option<&str>,
1221 params: &MsgraphMessagesDeltaParams,
1222 ) -> Result<MsgraphSendOutput<MsgraphMessagesDeltaResponse>, MsgraphClientStdError> {
1223 let coroutine =
1224 MsgraphMessagesDelta::with_params(&self.auth, &self.user_id, folder, params)?;
1225 self.run(coroutine)
1226 }
1227
1228 pub fn messages_delta_from_link_with_page_size(
1232 &mut self,
1233 link: &str,
1234 max_page_size: Option<u32>,
1235 ) -> Result<MsgraphSendOutput<MsgraphMessagesDeltaResponse>, MsgraphClientStdError> {
1236 let mut coroutine = MsgraphMessagesDelta::from_link(&self.auth, link)?;
1237 if let Some(size) = max_page_size {
1238 coroutine = coroutine.max_page_size(size);
1239 }
1240 self.run(coroutine)
1241 }
1242
1243 pub fn attachment_create(
1245 &mut self,
1246 message_id: &str,
1247 name: &str,
1248 content: &[u8],
1249 content_type: Option<&str>,
1250 ) -> Result<MsgraphSendOutput<MsgraphAttachment>, MsgraphClientStdError> {
1251 let coroutine = MsgraphAttachmentCreate::new(
1252 &self.auth,
1253 &self.user_id,
1254 message_id,
1255 name,
1256 content,
1257 content_type,
1258 )?;
1259 self.run(coroutine)
1260 }
1261
1262 pub fn attachments_list(
1264 &mut self,
1265 message_id: &str,
1266 ) -> Result<MsgraphSendOutput<MsgraphAttachmentsListResponse>, MsgraphClientStdError> {
1267 let coroutine = MsgraphAttachmentsList::new(&self.auth, &self.user_id, message_id)?;
1268 self.run(coroutine)
1269 }
1270
1271 pub fn attachment_get_raw(
1273 &mut self,
1274 message_id: &str,
1275 attachment_id: &str,
1276 ) -> Result<MsgraphSendOutput<Vec<u8>>, MsgraphClientStdError> {
1277 let coroutine =
1278 MsgraphAttachmentGetRaw::new(&self.auth, &self.user_id, message_id, attachment_id)?;
1279 self.run(coroutine)
1280 }
1281
1282 pub fn attachment_delete(
1284 &mut self,
1285 message_id: &str,
1286 attachment_id: &str,
1287 ) -> Result<MsgraphSendOutput<MsgraphNoResponse>, MsgraphClientStdError> {
1288 let coroutine =
1289 MsgraphAttachmentDelete::new(&self.auth, &self.user_id, message_id, attachment_id)?;
1290 self.run(coroutine)
1291 }
1292
1293 pub fn message_send(
1295 &mut self,
1296 id: &str,
1297 ) -> Result<MsgraphSendOutput<MsgraphNoResponse>, MsgraphClientStdError> {
1298 let coroutine = MsgraphMessageSend::new(&self.auth, &self.user_id, id)?;
1299 self.run(coroutine)
1300 }
1301
1302 pub fn mail_send(
1304 &mut self,
1305 message: &MsgraphMessage,
1306 save_to_sent_items: bool,
1307 ) -> Result<MsgraphSendOutput<MsgraphNoResponse>, MsgraphClientStdError> {
1308 let coroutine =
1309 MsgraphMailSend::new(&self.auth, &self.user_id, message, save_to_sent_items)?;
1310 self.run(coroutine)
1311 }
1312
1313 pub fn mail_send_mime(
1316 &mut self,
1317 raw: &[u8],
1318 ) -> Result<MsgraphSendOutput<MsgraphNoResponse>, MsgraphClientStdError> {
1319 let coroutine = MsgraphMailSendMime::new(&self.auth, &self.user_id, raw)?;
1320 self.run(coroutine)
1321 }
1322}
1323
1324impl fmt::Debug for MsgraphClientStd {
1325 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1326 f.debug_struct("MsgraphClientStd")
1327 .field("auth", &self.auth)
1328 .field("user_id", &self.user_id)
1329 .finish_non_exhaustive()
1330 }
1331}
1332
1333pub trait MsgraphStream: Read + Write + Send + Any {
1336 fn as_any_mut(&mut self) -> &mut dyn Any;
1338}
1339
1340impl<T: Read + Write + Send + Any> MsgraphStream for T {
1341 fn as_any_mut(&mut self) -> &mut dyn Any {
1342 self
1343 }
1344}