Skip to main content

rusted_mail/models/
jmap.rs

1//! JMAP session, mailbox, query, email, and mutation models.
2
3use super::{Deserialize, Serialize};
4
5#[derive(Debug, Serialize)]
6#[serde(rename_all = "camelCase")]
7pub struct OpenSessionResponse {
8    pub session_id: i64,
9}
10
11#[derive(Debug, Serialize)]
12#[serde(rename_all = "camelCase")]
13pub struct JmapOpenSessionResponse {
14    pub session_id: i64,
15    pub default_account_id: String,
16}
17
18#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
19#[serde(rename_all = "camelCase")]
20pub struct JmapSessionInfo {
21    pub session_id: i64,
22    pub username: String,
23    pub session_url: String,
24    pub default_account_id: String,
25    pub state: String,
26    pub api_url: String,
27    pub download_url: String,
28    pub upload_url: String,
29    pub event_source_url: String,
30    pub capabilities: Vec<String>,
31    pub accounts: Vec<JmapAccountInfo>,
32}
33
34#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
35#[serde(rename_all = "camelCase")]
36pub struct JmapAccountInfo {
37    pub id: String,
38    pub name: String,
39    pub is_personal: bool,
40    pub is_read_only: bool,
41    pub capabilities: Vec<String>,
42}
43
44#[derive(Debug, Clone, Deserialize)]
45#[serde(rename_all = "camelCase")]
46pub struct JmapMailboxQueryRequest {
47    pub role: Option<String>,
48    pub name: Option<String>,
49    pub parent_id: Option<String>,
50    pub is_subscribed: Option<bool>,
51    #[serde(default)]
52    pub sort_by_name: bool,
53}
54
55#[derive(Debug, Clone, Deserialize)]
56#[serde(rename_all = "camelCase")]
57pub struct JmapMailboxCreateRequest {
58    pub name: String,
59    pub parent_id: Option<String>,
60    pub role: Option<String>,
61}
62
63#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
64#[serde(rename_all = "camelCase")]
65pub struct JmapMailbox {
66    pub id: String,
67    pub name: Option<String>,
68    pub parent_id: Option<String>,
69    pub role: Option<String>,
70    pub sort_order: u32,
71    pub total_emails: usize,
72    pub unread_emails: usize,
73    pub total_threads: usize,
74    pub unread_threads: usize,
75    pub is_subscribed: bool,
76    pub rights: Option<JmapMailboxRights>,
77}
78
79#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
80#[serde(rename_all = "camelCase")]
81pub struct JmapMailboxRights {
82    pub may_read_items: bool,
83    pub may_add_items: bool,
84    pub may_remove_items: bool,
85    pub may_set_seen: bool,
86    pub may_set_keywords: bool,
87    pub may_create_child: bool,
88    pub may_rename: bool,
89    pub may_delete: bool,
90    pub may_submit: bool,
91}
92
93#[derive(Debug, Clone, Deserialize)]
94#[serde(rename_all = "camelCase")]
95pub struct JmapEmailQueryRequest {
96    pub in_mailbox: Option<String>,
97    pub text: Option<String>,
98    pub from: Option<String>,
99    pub to: Option<String>,
100    pub subject: Option<String>,
101    pub body: Option<String>,
102    pub has_keyword: Option<String>,
103    pub not_keyword: Option<String>,
104    pub has_attachment: Option<bool>,
105    pub after: Option<i64>,
106    pub before: Option<i64>,
107    pub min_size: Option<u32>,
108    pub max_size: Option<u32>,
109    #[serde(default)]
110    pub sort: Vec<JmapEmailSort>,
111}
112
113#[derive(Debug, Clone, Copy, Deserialize)]
114#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
115pub enum JmapEmailSort {
116    ReceivedAt,
117    SentAt,
118    From,
119    To,
120    Subject,
121    Size,
122}
123
124#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
125#[serde(rename_all = "camelCase")]
126pub struct JmapQueryResult {
127    pub account_id: String,
128    pub query_state: String,
129    pub can_calculate_changes: bool,
130    pub position: i32,
131    pub total: Option<usize>,
132    pub limit: Option<usize>,
133    pub ids: Vec<String>,
134}
135
136#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
137#[serde(rename_all = "camelCase")]
138pub struct JmapEmail {
139    pub id: String,
140    pub blob_id: Option<String>,
141    pub thread_id: Option<String>,
142    pub mailbox_ids: Vec<String>,
143    pub keywords: Vec<String>,
144    pub size: usize,
145    pub received_at: Option<i64>,
146    pub sent_at: Option<i64>,
147    pub message_id: Vec<String>,
148    pub in_reply_to: Vec<String>,
149    pub references: Vec<String>,
150    pub from: Vec<JmapEmailAddress>,
151    pub to: Vec<JmapEmailAddress>,
152    pub cc: Vec<JmapEmailAddress>,
153    pub bcc: Vec<JmapEmailAddress>,
154    pub reply_to: Vec<JmapEmailAddress>,
155    pub subject: Option<String>,
156    pub preview: Option<String>,
157    pub has_attachment: bool,
158    pub text_body: Vec<JmapEmailBodyPart>,
159    pub html_body: Vec<JmapEmailBodyPart>,
160    pub attachments: Vec<JmapEmailBodyPart>,
161}
162
163#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
164#[serde(rename_all = "camelCase")]
165pub struct JmapEmailAddress {
166    pub name: Option<String>,
167    pub email: String,
168}
169
170#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
171#[serde(rename_all = "camelCase")]
172pub struct JmapEmailBodyPart {
173    pub part_id: Option<String>,
174    pub blob_id: Option<String>,
175    pub size: usize,
176    pub name: Option<String>,
177    pub content_type: Option<String>,
178    pub charset: Option<String>,
179    pub disposition: Option<String>,
180    pub content_id: Option<String>,
181}
182
183#[derive(Debug, Clone, Deserialize)]
184#[serde(rename_all = "camelCase")]
185pub struct JmapEmailImportRequest {
186    pub raw_base64: String,
187    #[serde(default)]
188    pub mailbox_ids: Vec<String>,
189    #[serde(default)]
190    pub keywords: Vec<String>,
191    pub received_at: Option<i64>,
192}
193
194#[derive(Debug, Clone, Deserialize)]
195#[serde(rename_all = "camelCase")]
196pub struct JmapEmailSetMailboxesRequest {
197    #[serde(default)]
198    pub mailbox_ids: Vec<String>,
199}
200
201#[derive(Debug, Clone, Deserialize)]
202#[serde(rename_all = "camelCase")]
203pub struct JmapEmailSetKeywordsRequest {
204    #[serde(default)]
205    pub keywords: Vec<String>,
206}