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::list::{
18            MsgraphMailFoldersListParams, MsgraphMailFoldersListResponse,
19        },
20        send::{
21            MSGRAPH_API_BASE, MsgraphSend, MsgraphSendError, MsgraphSendOutput, path_segment,
22            user_path,
23        },
24    },
25};
26
27/// Lists the child folders of a Microsoft Graph mail folder.
28pub struct MsgraphMailChildFoldersList {
29    send: MsgraphSend<MsgraphMailFoldersListResponse>,
30}
31
32impl MsgraphMailChildFoldersList {
33    /// Lists the child folders of the mail folder `id`, filtered by
34    /// the OData `params`.
35    pub fn new(
36        auth: &HttpAuthBearer,
37        user_id: &str,
38        id: &str,
39        params: &MsgraphMailFoldersListParams,
40    ) -> Result<Self, MsgraphSendError> {
41        debug!("prepare microsoft graph child folders listing");
42        trace!("id: {id:?}");
43        trace!("params: {params:?}");
44
45        let user = user_path(user_id)?;
46        let mut url = Url::parse(MSGRAPH_API_BASE)?.join(&format!(
47            "{user}/mailFolders/{}/childFolders",
48            path_segment(id)?
49        ))?;
50        url.query_pairs_mut().extend_pairs(to_query_pairs(params));
51
52        let send = MsgraphSend::get(auth, url);
53
54        Ok(Self { send })
55    }
56}
57
58impl MsgraphCoroutine for MsgraphMailChildFoldersList {
59    type Yield = MsgraphYield;
60    type Return = Result<MsgraphSendOutput<MsgraphMailFoldersListResponse>, MsgraphSendError>;
61
62    fn resume(&mut self, arg: Option<&[u8]>) -> MsgraphCoroutineState<Self::Yield, Self::Return> {
63        let out = msgraph_try!(&mut self.send, arg);
64        debug!("child folders listed");
65        trace!("out: {out:?}");
66        MsgraphCoroutineState::Complete(Ok(out))
67    }
68}