io_msgraph/v1/rest/users/messages/
copy.rs1use alloc::format;
7
8use io_http::rfc6750::bearer::HttpAuthBearer;
9use log::{debug, trace};
10use serde::Serialize;
11use url::Url;
12
13use crate::{
14 coroutine::*,
15 msgraph_try,
16 v1::{
17 rest::users::messages::MsgraphMessage,
18 send::{
19 MSGRAPH_API_BASE, MsgraphSend, MsgraphSendError, MsgraphSendOutput, path_segment,
20 user_path,
21 },
22 },
23};
24
25#[derive(Debug, Serialize)]
26#[serde(rename_all = "camelCase")]
27struct MsgraphMessageCopyRequest<'a> {
28 destination_id: &'a str,
29}
30
31pub struct MsgraphMessageCopy {
33 send: MsgraphSend<MsgraphMessage>,
34}
35
36impl MsgraphMessageCopy {
37 pub fn new(
40 auth: &HttpAuthBearer,
41 user_id: &str,
42 id: &str,
43 destination: &str,
44 ) -> Result<Self, MsgraphSendError> {
45 debug!("prepare microsoft graph message copy");
46 trace!("id: {id:?}");
47 trace!("destination: {destination:?}");
48
49 let user = user_path(user_id)?;
50 let url = Url::parse(MSGRAPH_API_BASE)?
51 .join(&format!("{user}/messages/{}/copy", path_segment(id)?))?;
52 let body = MsgraphMessageCopyRequest {
53 destination_id: destination,
54 };
55 let send = MsgraphSend::post_json(auth, url, &body)?;
56
57 Ok(Self { send })
58 }
59}
60
61impl MsgraphCoroutine for MsgraphMessageCopy {
62 type Yield = MsgraphYield;
63 type Return = Result<MsgraphSendOutput<MsgraphMessage>, MsgraphSendError>;
64
65 fn resume(&mut self, arg: Option<&[u8]>) -> MsgraphCoroutineState<Self::Yield, Self::Return> {
66 let out = msgraph_try!(&mut self.send, arg);
67 debug!("message copied");
68 trace!("out: {out:?}");
69 MsgraphCoroutineState::Complete(Ok(out))
70 }
71}