Skip to main content

io_msgraph/v1/rest/users/mail_folders/
child_folders.rs

1//! List the child folders of a Microsoft Graph mail folder
2//! (`GET /me/mailFolders/{id}/childFolders`).
3//!
4//! <https://learn.microsoft.com/en-us/graph/api/mailfolder-list-childfolders>
5
6use alloc::format;
7
8use io_http::rfc6750::bearer::HttpAuthBearer;
9use log::{debug, trace};
10use url::Url;
11
12use crate::{
13    coroutine::*,
14    msgraph_try,
15    v1::{
16        query::to_query_pairs,
17        rest::users::mail_folders::{
18            MsgraphMailFoldersListResponse, list::MsgraphMailFoldersListParams,
19        },
20        send::{MSGRAPH_API_BASE, MsgraphSend, MsgraphSendError, MsgraphSendOutput, user_path},
21    },
22};
23
24/// Lists the child folders of a Microsoft Graph mail folder.
25pub struct MsgraphMailChildFoldersList {
26    send: MsgraphSend<MsgraphMailFoldersListResponse>,
27}
28
29impl MsgraphMailChildFoldersList {
30    /// Lists the child folders of the mail folder `id`, filtered by
31    /// the OData `params`.
32    pub fn new(
33        auth: &HttpAuthBearer,
34        user_id: &str,
35        id: &str,
36        params: &MsgraphMailFoldersListParams,
37    ) -> Result<Self, MsgraphSendError> {
38        debug!("prepare microsoft graph child folders listing");
39        trace!("id: {id:?}");
40        trace!("params: {params:?}");
41
42        let user = user_path(user_id);
43        let mut url =
44            Url::parse(MSGRAPH_API_BASE)?.join(&format!("{user}/mailFolders/{id}/childFolders"))?;
45        url.query_pairs_mut().extend_pairs(to_query_pairs(params));
46
47        let send = MsgraphSend::get(auth, url);
48
49        Ok(Self { send })
50    }
51}
52
53impl MsgraphCoroutine for MsgraphMailChildFoldersList {
54    type Yield = MsgraphYield;
55    type Return = Result<MsgraphSendOutput<MsgraphMailFoldersListResponse>, MsgraphSendError>;
56
57    fn resume(&mut self, arg: Option<&[u8]>) -> MsgraphCoroutineState<Self::Yield, Self::Return> {
58        let out = msgraph_try!(&mut self.send, arg);
59        debug!("child folders listed");
60        trace!("out: {out:?}");
61        MsgraphCoroutineState::Complete(Ok(out))
62    }
63}