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 page::MsgraphPage,
17 query::to_query_pairs,
18 rest::users::mail_folders::MsgraphMailFolder,
19 send::{MSGRAPH_API_BASE, MsgraphSend, MsgraphSendError, MsgraphSendOutput, user_path},
20 },
21};
22
23pub type MsgraphMailFoldersListResponse = MsgraphPage<MsgraphMailFolder>;
25
26#[derive(Debug, Clone, Default, Serialize, Eq, PartialEq)]
28pub struct MsgraphMailFoldersListParams<'a> {
29 #[serde(rename = "$top")]
31 pub top: Option<u32>,
32 #[serde(rename = "$skip")]
34 pub skip: Option<u32>,
35 #[serde(rename = "$select")]
37 pub select: Option<&'a str>,
38 #[serde(rename = "includeHiddenFolders")]
40 pub include_hidden_folders: Option<bool>,
41}
42
43pub struct MsgraphMailFoldersList {
45 send: MsgraphSend<MsgraphMailFoldersListResponse>,
46}
47
48impl MsgraphMailFoldersList {
49 pub fn new(
52 auth: &HttpAuthBearer,
53 user_id: &str,
54 params: &MsgraphMailFoldersListParams,
55 ) -> Result<Self, MsgraphSendError> {
56 debug!("prepare microsoft graph mail folders listing");
57 trace!("params: {params:?}");
58
59 let user = user_path(user_id)?;
60 let mut url = Url::parse(MSGRAPH_API_BASE)?.join(&format!("{user}/mailFolders"))?;
61 url.query_pairs_mut().extend_pairs(to_query_pairs(params));
62
63 let send = MsgraphSend::get(auth, url);
64
65 Ok(Self { send })
66 }
67}
68
69impl MsgraphCoroutine for MsgraphMailFoldersList {
70 type Yield = MsgraphYield;
71 type Return = Result<MsgraphSendOutput<MsgraphMailFoldersListResponse>, MsgraphSendError>;
72
73 fn resume(&mut self, arg: Option<&[u8]>) -> MsgraphCoroutineState<Self::Yield, Self::Return> {
74 let out = msgraph_try!(&mut self.send, arg);
75 debug!("mail folders listed");
76 trace!("out: {out:?}");
77 MsgraphCoroutineState::Complete(Ok(out))
78 }
79}