io_msgraph/v1/rest/users/mail_folders/
list.rs1use alloc::format;
6
7use io_http::rfc6750::bearer::HttpAuthBearer;
8use log::{debug, trace};
9use serde::Serialize;
10use url::Url;
11
12use crate::{
13 coroutine::*,
14 msgraph_try,
15 v1::{
16 query::to_query_pairs,
17 rest::users::mail_folders::MsgraphMailFoldersListResponse,
18 send::{MSGRAPH_API_BASE, MsgraphSend, MsgraphSendError, MsgraphSendOutput, user_path},
19 },
20};
21
22#[derive(Debug, Clone, Default, Serialize, Eq, PartialEq)]
24pub struct MsgraphMailFoldersListParams<'a> {
25 #[serde(rename = "$top")]
27 pub top: Option<u32>,
28 #[serde(rename = "$skip")]
30 pub skip: Option<u32>,
31 #[serde(rename = "$select")]
33 pub select: Option<&'a str>,
34 #[serde(rename = "includeHiddenFolders")]
36 pub include_hidden_folders: Option<bool>,
37}
38
39pub struct MsgraphMailFoldersList {
41 send: MsgraphSend<MsgraphMailFoldersListResponse>,
42}
43
44impl MsgraphMailFoldersList {
45 pub fn new(
48 auth: &HttpAuthBearer,
49 user_id: &str,
50 params: &MsgraphMailFoldersListParams,
51 ) -> Result<Self, MsgraphSendError> {
52 debug!("prepare microsoft graph mail folders listing");
53 trace!("params: {params:?}");
54
55 let user = user_path(user_id);
56 let mut url = Url::parse(MSGRAPH_API_BASE)?.join(&format!("{user}/mailFolders"))?;
57 url.query_pairs_mut().extend_pairs(to_query_pairs(params));
58
59 let send = MsgraphSend::get(auth, url);
60
61 Ok(Self { send })
62 }
63}
64
65impl MsgraphCoroutine for MsgraphMailFoldersList {
66 type Yield = MsgraphYield;
67 type Return = Result<MsgraphSendOutput<MsgraphMailFoldersListResponse>, MsgraphSendError>;
68
69 fn resume(&mut self, arg: Option<&[u8]>) -> MsgraphCoroutineState<Self::Yield, Self::Return> {
70 let out = msgraph_try!(&mut self.send, arg);
71 debug!("mail folders listed");
72 trace!("out: {out:?}");
73 MsgraphCoroutineState::Complete(Ok(out))
74 }
75}