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