io_msgraph/v1/rest/users/mail_folders/
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::mail_folders::MsgraphMailFolder,
18 send::{
19 MSGRAPH_API_BASE, MsgraphSend, MsgraphSendError, MsgraphSendOutput, path_segment,
20 user_path,
21 },
22 },
23};
24
25#[derive(Debug, Serialize)]
27#[serde(rename_all = "camelCase")]
28struct MsgraphMailFolderCopyRequest<'a> {
29 destination_id: &'a str,
30}
31
32pub struct MsgraphMailFolderCopy {
34 send: MsgraphSend<MsgraphMailFolder>,
35}
36
37impl MsgraphMailFolderCopy {
38 pub fn new(
41 auth: &HttpAuthBearer,
42 user_id: &str,
43 id: &str,
44 destination: &str,
45 ) -> Result<Self, MsgraphSendError> {
46 debug!("prepare microsoft graph mail folder copy");
47 trace!("id: {id:?}");
48 trace!("destination: {destination:?}");
49
50 let user = user_path(user_id)?;
51 let url = Url::parse(MSGRAPH_API_BASE)?
52 .join(&format!("{user}/mailFolders/{}/copy", path_segment(id)?))?;
53 let body = MsgraphMailFolderCopyRequest {
54 destination_id: destination,
55 };
56 let send = MsgraphSend::post_json(auth, url, &body)?;
57
58 Ok(Self { send })
59 }
60}
61
62impl MsgraphCoroutine for MsgraphMailFolderCopy {
63 type Yield = MsgraphYield;
64 type Return = Result<MsgraphSendOutput<MsgraphMailFolder>, MsgraphSendError>;
65
66 fn resume(&mut self, arg: Option<&[u8]>) -> MsgraphCoroutineState<Self::Yield, Self::Return> {
67 let out = msgraph_try!(&mut self.send, arg);
68 debug!("mail folder copied");
69 trace!("out: {out:?}");
70 MsgraphCoroutineState::Complete(Ok(out))
71 }
72}