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_unsubscribe`.
71///
72/// The message, and optionally which of its routes to use. The address or link comes from
73/// the message's own `List-Unsubscribe` header, never from the caller.
74#[derive(Debug, Default, Deserialize, JsonSchema)]
75pub struct UnsubscribeParams {
76    /// Opaque message id from `mail_search` or `mail_get_message`.
77    pub id: String,
78    /// Which of the message's own routes to use: `one_click` or `mailto`. Omit to let the
79    /// server choose, which prefers one-click. A route the message does not offer is an error.
80    #[serde(default)]
81    pub method: Option<UnsubscribeMethodParam>,
82}
83
84/// A route a caller may pick. A web link is never followed, so it is not a choice.
85#[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize, JsonSchema)]
86#[serde(rename_all = "snake_case")]
87pub enum UnsubscribeMethodParam {
88    /// POST to the sender's https link (RFC 8058).
89    OneClick,
90    /// Email the address in the sender's own mailto.
91    Mailto,
92}
93
94/// Arguments for `mail_get_message`.
95#[derive(Debug, Default, Deserialize, JsonSchema)]
96pub struct GetMessageParams {
97    /// Opaque message id.
98    pub id: String,
99    /// Unicode scalar offset into the body. Omitted means the start.
100    #[serde(default)]
101    pub offset: u64,
102}
103
104/// Arguments for `mail_get_attachment`.
105#[derive(Debug, Default, Deserialize, JsonSchema)]
106pub struct GetAttachmentParams {
107    /// Opaque message id.
108    pub id: String,
109    /// Part identifier from `mail_get_message`.
110    pub part: String,
111    /// Unicode scalar offset into a text part. Omitted means the start.
112    #[serde(default)]
113    pub offset: u64,
114}
115
116/// Arguments for `mail_save_attachment`.
117#[derive(Debug, Default, Deserialize, JsonSchema)]
118pub struct SaveAttachmentParams {
119    /// Opaque message id.
120    pub id: String,
121    /// Part identifier from `mail_get_message`.
122    pub part: String,
123}
124
125/// Arguments for `mail_move`.
126#[derive(Debug, Default, Deserialize, JsonSchema)]
127pub struct MoveParams {
128    /// Opaque message id.
129    pub id: String,
130    /// Mailbox path. Set this or `role`, not both.
131    #[serde(default)]
132    pub mailbox: Option<String>,
133    /// Role: inbox, archive, trash, junk, sent, drafts, or notes.
134    #[serde(default)]
135    pub role: Option<String>,
136}
137
138/// Arguments for `mail_set_flags`.
139#[derive(Debug, Default, Deserialize, JsonSchema)]
140pub struct FlagParams {
141    /// Opaque message id.
142    pub id: String,
143    /// Seen flag. Omit to leave it unchanged.
144    #[serde(default)]
145    pub seen: Option<bool>,
146    /// Flagged flag. Omit to leave it unchanged.
147    #[serde(default)]
148    pub flagged: Option<bool>,
149}
150
151#[derive(Debug, Serialize, JsonSchema)]
152pub(crate) struct MailboxOut {
153    pub(crate) path: String,
154    pub(crate) role: String,
155    pub(crate) total: u32,
156    pub(crate) unread: u32,
157}
158
159#[derive(Debug, Serialize, JsonSchema)]
160pub(crate) struct MailboxListOut {
161    pub(crate) mailboxes: Vec<MailboxOut>,
162}
163
164#[derive(Debug, Serialize, JsonSchema)]
165pub(crate) struct SearchHitOut {
166    pub(crate) id: String,
167    pub(crate) from: String,
168    pub(crate) subject: String,
169    pub(crate) date: String,
170    pub(crate) unread: bool,
171    pub(crate) flagged: bool,
172}
173
174#[derive(Debug, Serialize, JsonSchema)]
175pub(crate) struct SearchOut {
176    pub(crate) messages: Vec<SearchHitOut>,
177    pub(crate) next_cursor: Option<String>,
178    pub(crate) warnings: u32,
179}
180
181#[derive(Debug, Serialize, JsonSchema)]
182pub(crate) struct AttachmentInfoOut {
183    pub(crate) part: String,
184    pub(crate) content_type: String,
185    pub(crate) size: u64,
186    pub(crate) name: String,
187}
188
189#[derive(Debug, Serialize, JsonSchema)]
190pub(crate) struct MessageOut {
191    pub(crate) id: String,
192    pub(crate) from: String,
193    pub(crate) to: Vec<String>,
194    pub(crate) subject: String,
195    pub(crate) date: String,
196    pub(crate) body: String,
197    pub(crate) attachments: Vec<AttachmentInfoOut>,
198    pub(crate) unsubscribe: UnsubscribeOut,
199    pub(crate) next_offset: Option<u64>,
200}
201
202/// Whether the sender offers a way to unsubscribe, and which.
203#[derive(Debug, Serialize, JsonSchema)]
204pub(crate) struct UnsubscribeOut {
205    /// True when the sender's headers offer at least one way to unsubscribe.
206    pub(crate) available: bool,
207    /// What the sender offers, best first: `one_click` (a link that accepts a POST),
208    /// `mailto` (an email address) or `link` (a page for a browser).
209    pub(crate) methods: Vec<UnsubscribeMethodOut>,
210}
211
212#[derive(Debug, Clone, Copy, Serialize, JsonSchema)]
213#[serde(rename_all = "snake_case")]
214pub(crate) enum UnsubscribeMethodOut {
215    OneClick,
216    Mailto,
217    Link,
218}
219
220#[derive(Debug, Serialize, JsonSchema)]
221pub(crate) struct AttachmentOut {
222    pub(crate) content_type: String,
223    pub(crate) name: String,
224    pub(crate) size: u64,
225    pub(crate) text: Option<String>,
226    pub(crate) bytes_base64: Option<String>,
227    pub(crate) next_offset: Option<u64>,
228}
229
230#[derive(Debug, Serialize, JsonSchema)]
231pub(crate) struct SavedAttachmentOut {
232    pub(crate) path: String,
233    pub(crate) size: u64,
234    pub(crate) content_type: String,
235}
236
237#[derive(Debug, Serialize, JsonSchema)]
238pub(crate) struct IdOut {
239    pub(crate) id: String,
240}
241
242#[derive(Debug, Serialize, JsonSchema)]
243pub(crate) struct SendOut {
244    pub(crate) id: Option<String>,
245    pub(crate) warning: Option<String>,
246}
247
248#[derive(Debug, Clone, Copy, Serialize, JsonSchema)]
249#[serde(rename_all = "snake_case")]
250pub(crate) enum UnsubscribeStatus {
251    /// An unsubscribe email was sent.
252    Emailed,
253    /// The sender's server accepted a one-click unsubscribe request.
254    OneClick,
255    /// Only a web link is on offer, and nothing was sent.
256    LinkOnly,
257}
258
259#[derive(Debug, Serialize, JsonSchema)]
260pub(crate) struct UnsubscribedOut {
261    pub(crate) status: UnsubscribeStatus,
262    /// Id of the copy in Sent Messages, when an email was sent and the copy was saved.
263    pub(crate) id: Option<String>,
264    /// Set when the email was sent but the Sent copy was not saved.
265    pub(crate) warning: Option<String>,
266    /// The sender's web links, as the sender wrote them. Empty when an email was sent.
267    pub(crate) links: Vec<String>,
268    /// What happened and what is left to do.
269    pub(crate) note: String,
270}
271
272#[derive(Debug, Serialize, JsonSchema)]
273pub(crate) struct MoveOut {
274    pub(crate) moved: bool,
275}
276
277#[derive(Debug, Serialize, JsonSchema)]
278pub(crate) struct FlagsOut {
279    pub(crate) updated: bool,
280}
281
282#[derive(Debug, Clone, Copy, Serialize, JsonSchema)]
283#[serde(rename_all = "lowercase")]
284pub(crate) enum ServiceState {
285    On,
286    Off,
287}
288
289#[derive(Debug, Serialize, JsonSchema)]
290pub(crate) struct ServiceOut {
291    pub(crate) name: String,
292    pub(crate) status: ServiceState,
293    pub(crate) reason: Option<String>,
294}
295
296#[derive(Debug, Serialize, JsonSchema)]
297pub(crate) struct AccountStatusOut {
298    pub(crate) apple_id: String,
299    pub(crate) services: Vec<ServiceOut>,
300    pub(crate) version: &'static str,
301}