io_msgraph/v1/rest/users/messages/attachments/
list.rs1use 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 page::MsgraphPage,
17 rest::users::messages::attachments::MsgraphAttachment,
18 send::{
19 MSGRAPH_API_BASE, MsgraphSend, MsgraphSendError, MsgraphSendOutput, path_segment,
20 user_path,
21 },
22 },
23};
24
25pub type MsgraphAttachmentsListResponse = MsgraphPage<MsgraphAttachment>;
27
28pub struct MsgraphAttachmentsList {
30 send: MsgraphSend<MsgraphAttachmentsListResponse>,
31}
32
33impl MsgraphAttachmentsList {
34 pub fn new(
36 auth: &HttpAuthBearer,
37 user_id: &str,
38 message_id: &str,
39 ) -> Result<Self, MsgraphSendError> {
40 debug!("prepare microsoft graph attachments listing");
41 trace!("message_id: {message_id:?}");
42
43 let user = user_path(user_id)?;
44 let url = Url::parse(MSGRAPH_API_BASE)?.join(&format!(
45 "{user}/messages/{}/attachments",
46 path_segment(message_id)?
47 ))?;
48 let send = MsgraphSend::get(auth, url);
49
50 Ok(Self { send })
51 }
52}
53
54impl MsgraphCoroutine for MsgraphAttachmentsList {
55 type Yield = MsgraphYield;
56 type Return = Result<MsgraphSendOutput<MsgraphAttachmentsListResponse>, MsgraphSendError>;
57
58 fn resume(&mut self, arg: Option<&[u8]>) -> MsgraphCoroutineState<Self::Yield, Self::Return> {
59 let out = msgraph_try!(&mut self.send, arg);
60 debug!("attachments listed");
61 trace!("out: {out:?}");
62 MsgraphCoroutineState::Complete(Ok(out))
63 }
64}