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