io_msgraph/v1/rest/users/messages/
delta.rs1use alloc::{format, string::String, vec::Vec};
19
20use io_http::rfc6750::bearer::HttpAuthBearer;
21use log::{debug, trace};
22use serde::{Deserialize, Serialize};
23use url::Url;
24
25use crate::{
26 coroutine::*,
27 msgraph_try,
28 v1::{
29 rest::users::{contacts::delta::MsgraphRemoved, messages::MsgraphMessage},
30 send::{MSGRAPH_API_BASE, MsgraphSend, MsgraphSendError, MsgraphSendOutput, user_path},
31 },
32};
33
34#[derive(Debug, Clone, Default, Deserialize, Serialize, Eq, PartialEq)]
39pub struct MsgraphMessagesDeltaResponse {
40 #[serde(default)]
42 pub value: Vec<MsgraphMessageDelta>,
43 #[serde(default, rename = "@odata.nextLink")]
45 pub next_link: Option<String>,
46 #[serde(default, rename = "@odata.deltaLink")]
48 pub delta_link: Option<String>,
49}
50
51#[derive(Debug, Clone, Default, Deserialize, Serialize, Eq, PartialEq)]
54pub struct MsgraphMessageDelta {
55 #[serde(flatten)]
57 pub message: MsgraphMessage,
58 #[serde(default, rename = "@removed", skip_serializing_if = "Option::is_none")]
60 pub removed: Option<MsgraphRemoved>,
61}
62
63pub struct MsgraphMessagesDelta {
67 send: MsgraphSend<MsgraphMessagesDeltaResponse>,
68}
69
70impl MsgraphMessagesDelta {
71 pub fn new(
77 auth: &HttpAuthBearer,
78 user_id: &str,
79 folder: Option<&str>,
80 select: Option<&str>,
81 ) -> Result<Self, MsgraphSendError> {
82 debug!("prepare microsoft graph messages delta");
83 trace!("folder: {folder:?}");
84
85 let user = user_path(user_id);
86 let path = match folder {
87 Some(folder) => format!("{user}/mailFolders/{folder}/messages/delta"),
88 None => format!("{user}/messages/delta"),
89 };
90 let mut url = Url::parse(MSGRAPH_API_BASE)?.join(&path)?;
91 if let Some(select) = select {
92 url.query_pairs_mut().append_pair("$select", select);
93 }
94
95 let send = MsgraphSend::get(auth, url);
96
97 Ok(Self { send })
98 }
99
100 pub fn from_link(auth: &HttpAuthBearer, link: &str) -> Result<Self, MsgraphSendError> {
106 debug!("prepare microsoft graph messages delta from link");
107 trace!("link: {link:?}");
108
109 let url = Url::parse(link)?;
110 let send = MsgraphSend::get(auth, url);
111
112 Ok(Self { send })
113 }
114}
115
116impl MsgraphCoroutine for MsgraphMessagesDelta {
117 type Yield = MsgraphYield;
118 type Return = Result<MsgraphSendOutput<MsgraphMessagesDeltaResponse>, MsgraphSendError>;
119
120 fn resume(&mut self, arg: Option<&[u8]>) -> MsgraphCoroutineState<Self::Yield, Self::Return> {
121 let out = msgraph_try!(&mut self.send, arg);
122 debug!("messages delta page received");
123 trace!("out: {out:?}");
124 MsgraphCoroutineState::Complete(Ok(out))
125 }
126}