Skip to main content

ibridge_server/
dto.rs

1// SPDX-License-Identifier: Apache-2.0
2
3//! Tool arguments and structured results.
4
5use schemars::JsonSchema;
6use serde::{Deserialize, Serialize};
7
8fn default_page_limit() -> u32 {
9    25
10}
11
12/// Arguments for `mail_search`.
13#[derive(Debug, Default, Deserialize, JsonSchema)]
14pub struct SearchParams {
15    /// Mailbox path. Omit to use `role` or the inbox.
16    #[serde(default)]
17    pub mailbox: Option<String>,
18    /// Well-known role: inbox, sent, drafts, trash, junk, archive, notes.
19    #[serde(default)]
20    pub role: Option<String>,
21    /// From header contains this text.
22    #[serde(default)]
23    pub from: Option<String>,
24    /// To header contains this text.
25    #[serde(default)]
26    pub to: Option<String>,
27    /// Subject contains this text.
28    #[serde(default)]
29    pub subject: Option<String>,
30    /// Body or subject contains this text.
31    #[serde(default)]
32    pub text: Option<String>,
33    /// Messages on or after this date.
34    #[serde(default)]
35    pub since: Option<String>,
36    /// Messages before this date.
37    #[serde(default)]
38    pub before: Option<String>,
39    /// When set, only unseen messages.
40    #[serde(default)]
41    pub unread: Option<bool>,
42    /// When set, only flagged messages.
43    #[serde(default)]
44    pub flagged: Option<bool>,
45    /// Page size. Omitted means 25. More than 100 is rejected.
46    #[serde(default = "default_page_limit")]
47    pub limit: u32,
48    /// Cursor from the previous page.
49    #[serde(default)]
50    pub cursor: Option<String>,
51}
52
53/// Arguments for `mail_send` and `mail_create_draft`.
54#[derive(Debug, Default, Deserialize, JsonSchema)]
55pub struct SendParams {
56    /// Recipients.
57    pub to: Vec<String>,
58    /// Subject.
59    pub subject: String,
60    /// Body as text.
61    pub body: String,
62    /// From address when it is not the signed-in Apple ID.
63    #[serde(default)]
64    pub from: Option<String>,
65    /// Opaque id of the message this one replies to.
66    #[serde(default)]
67    pub reply_to_id: Option<String>,
68}
69
70/// Arguments for `mail_get_message`.
71#[derive(Debug, Default, Deserialize, JsonSchema)]
72pub struct GetMessageParams {
73    /// Opaque message id.
74    pub id: String,
75    /// Unicode scalar offset into the body. Omitted means the start.
76    #[serde(default)]
77    pub offset: u64,
78}
79
80/// Arguments for `mail_get_attachment`.
81#[derive(Debug, Default, Deserialize, JsonSchema)]
82pub struct GetAttachmentParams {
83    /// Opaque message id.
84    pub id: String,
85    /// Part identifier from `mail_get_message`.
86    pub part: String,
87    /// Unicode scalar offset into a text part. Omitted means the start.
88    #[serde(default)]
89    pub offset: u64,
90}
91
92/// Arguments for `mail_save_attachment`.
93#[derive(Debug, Default, Deserialize, JsonSchema)]
94pub struct SaveAttachmentParams {
95    /// Opaque message id.
96    pub id: String,
97    /// Part identifier from `mail_get_message`.
98    pub part: String,
99}
100
101/// Arguments for `mail_move`.
102#[derive(Debug, Default, Deserialize, JsonSchema)]
103pub struct MoveParams {
104    /// Opaque message id.
105    pub id: String,
106    /// Mailbox path. Set this or `role`, not both.
107    #[serde(default)]
108    pub mailbox: Option<String>,
109    /// Role: inbox, archive, trash, junk, sent, drafts, or notes.
110    #[serde(default)]
111    pub role: Option<String>,
112}
113
114/// Arguments for `mail_set_flags`.
115#[derive(Debug, Default, Deserialize, JsonSchema)]
116pub struct FlagParams {
117    /// Opaque message id.
118    pub id: String,
119    /// Seen flag. Omit to leave it unchanged.
120    #[serde(default)]
121    pub seen: Option<bool>,
122    /// Flagged flag. Omit to leave it unchanged.
123    #[serde(default)]
124    pub flagged: Option<bool>,
125}
126
127#[derive(Debug, Serialize, JsonSchema)]
128pub(crate) struct MailboxOut {
129    pub(crate) path: String,
130    pub(crate) role: String,
131    pub(crate) total: u32,
132    pub(crate) unread: u32,
133}
134
135#[derive(Debug, Serialize, JsonSchema)]
136pub(crate) struct MailboxListOut {
137    pub(crate) mailboxes: Vec<MailboxOut>,
138}
139
140#[derive(Debug, Serialize, JsonSchema)]
141pub(crate) struct SearchHitOut {
142    pub(crate) id: String,
143    pub(crate) from: String,
144    pub(crate) subject: String,
145    pub(crate) date: String,
146    pub(crate) unread: bool,
147    pub(crate) flagged: bool,
148}
149
150#[derive(Debug, Serialize, JsonSchema)]
151pub(crate) struct SearchOut {
152    pub(crate) messages: Vec<SearchHitOut>,
153    pub(crate) next_cursor: Option<String>,
154    pub(crate) warnings: u32,
155}
156
157#[derive(Debug, Serialize, JsonSchema)]
158pub(crate) struct AttachmentInfoOut {
159    pub(crate) part: String,
160    pub(crate) content_type: String,
161    pub(crate) size: u64,
162    pub(crate) name: String,
163}
164
165#[derive(Debug, Serialize, JsonSchema)]
166pub(crate) struct MessageOut {
167    pub(crate) id: String,
168    pub(crate) from: String,
169    pub(crate) to: Vec<String>,
170    pub(crate) subject: String,
171    pub(crate) date: String,
172    pub(crate) body: String,
173    pub(crate) attachments: Vec<AttachmentInfoOut>,
174    pub(crate) next_offset: Option<u64>,
175}
176
177#[derive(Debug, Serialize, JsonSchema)]
178pub(crate) struct AttachmentOut {
179    pub(crate) content_type: String,
180    pub(crate) name: String,
181    pub(crate) size: u64,
182    pub(crate) text: Option<String>,
183    pub(crate) bytes_base64: Option<String>,
184    pub(crate) next_offset: Option<u64>,
185}
186
187#[derive(Debug, Serialize, JsonSchema)]
188pub(crate) struct SavedAttachmentOut {
189    pub(crate) path: String,
190    pub(crate) size: u64,
191    pub(crate) content_type: String,
192}
193
194#[derive(Debug, Serialize, JsonSchema)]
195pub(crate) struct IdOut {
196    pub(crate) id: String,
197}
198
199#[derive(Debug, Serialize, JsonSchema)]
200pub(crate) struct SendOut {
201    pub(crate) id: Option<String>,
202    pub(crate) warning: Option<String>,
203}
204
205#[derive(Debug, Serialize, JsonSchema)]
206pub(crate) struct MoveOut {
207    pub(crate) moved: bool,
208}
209
210#[derive(Debug, Serialize, JsonSchema)]
211pub(crate) struct FlagsOut {
212    pub(crate) updated: bool,
213}
214
215#[derive(Debug, Clone, Copy, Serialize, JsonSchema)]
216#[serde(rename_all = "lowercase")]
217pub(crate) enum ServiceState {
218    On,
219    Off,
220}
221
222#[derive(Debug, Serialize, JsonSchema)]
223pub(crate) struct ServiceOut {
224    pub(crate) name: String,
225    pub(crate) status: ServiceState,
226    pub(crate) reason: Option<String>,
227}
228
229#[derive(Debug, Serialize, JsonSchema)]
230pub(crate) struct AccountStatusOut {
231    pub(crate) apple_id: String,
232    pub(crate) services: Vec<ServiceOut>,
233    pub(crate) version: &'static str,
234}