Skip to main content

io_msgraph/v1/rest/users/messages/attachments/
list.rs

1//! List a Microsoft Graph message's attachments
2//! (`GET /me/messages/{id}/attachments`).
3//!
4//! <https://learn.microsoft.com/en-us/graph/api/message-list-attachments>
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        rest::users::messages::attachments::MsgraphAttachmentsListResponse,
17        send::{MSGRAPH_API_BASE, MsgraphSend, MsgraphSendError, MsgraphSendOutput, user_path},
18    },
19};
20
21/// Lists the attachments of a Microsoft Graph message.
22pub struct MsgraphAttachmentsList {
23    send: MsgraphSend<MsgraphAttachmentsListResponse>,
24}
25
26impl MsgraphAttachmentsList {
27    /// Lists the attachments of the message `message_id`.
28    pub fn new(
29        auth: &HttpAuthBearer,
30        user_id: &str,
31        message_id: &str,
32    ) -> Result<Self, MsgraphSendError> {
33        debug!("prepare microsoft graph attachments listing");
34        trace!("message_id: {message_id:?}");
35
36        let user = user_path(user_id);
37        let url = Url::parse(MSGRAPH_API_BASE)?
38            .join(&format!("{user}/messages/{message_id}/attachments"))?;
39        let send = MsgraphSend::get(auth, url);
40
41        Ok(Self { send })
42    }
43}
44
45impl MsgraphCoroutine for MsgraphAttachmentsList {
46    type Yield = MsgraphYield;
47    type Return = Result<MsgraphSendOutput<MsgraphAttachmentsListResponse>, MsgraphSendError>;
48
49    fn resume(&mut self, arg: Option<&[u8]>) -> MsgraphCoroutineState<Self::Yield, Self::Return> {
50        let out = msgraph_try!(&mut self.send, arg);
51        debug!("attachments listed");
52        trace!("out: {out:?}");
53        MsgraphCoroutineState::Complete(Ok(out))
54    }
55}