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