Skip to main content

io_jmap/rfc8621/
email.rs

1//! JMAP for Mail: Email (RFC 8621 §4).
2
3use alloc::{collections::BTreeMap, string::String, vec::Vec};
4
5use serde::{Deserialize, Serialize};
6
7pub mod changes;
8pub mod copy;
9pub mod get;
10pub mod import;
11pub mod parse;
12pub mod query;
13pub mod set;
14
15/// The email has been read.
16pub const JMAP_KEYWORD_SEEN: &str = "$seen";
17
18/// The email has been flagged for follow-up.
19pub const JMAP_KEYWORD_FLAGGED: &str = "$flagged";
20
21/// The email has been replied to.
22pub const JMAP_KEYWORD_ANSWERED: &str = "$answered";
23
24/// The email is a draft.
25pub const JMAP_KEYWORD_DRAFT: &str = "$draft";
26
27/// A JMAP Email object (RFC 8621 §4.1).
28#[derive(Clone, Debug, Default, Serialize, Deserialize)]
29#[serde(rename_all = "camelCase")]
30pub struct JmapEmail {
31    /// The server-assigned email id.
32    pub id: Option<String>,
33    /// Blob ID for the raw RFC 5322 message.
34    pub blob_id: Option<String>,
35    /// The id of the thread the email belongs to.
36    pub thread_id: Option<String>,
37    /// `{ mailbox-id -> true }` for each mailbox containing the email.
38    pub mailbox_ids: Option<BTreeMap<String, bool>>,
39    /// `{ keyword -> true }`. Standard: `$seen`, `$flagged`, `$answered`,
40    /// `$draft`.
41    pub keywords: Option<BTreeMap<String, bool>>,
42    /// Size of the raw RFC 5322 message, in bytes.
43    pub size: Option<u64>,
44    /// RFC 3339 receive time.
45    pub received_at: Option<String>,
46    /// The `Message-ID` header values.
47    pub message_id: Option<Vec<String>>,
48    /// The `In-Reply-To` header values.
49    pub in_reply_to: Option<Vec<String>>,
50    /// The `References` header values.
51    pub references: Option<Vec<String>>,
52    /// The `Sender` header addresses.
53    pub sender: Option<Vec<JmapEmailAddress>>,
54    /// The `From` header addresses.
55    pub from: Option<Vec<JmapEmailAddress>>,
56    /// The `To` header addresses.
57    pub to: Option<Vec<JmapEmailAddress>>,
58    /// The `Cc` header addresses.
59    pub cc: Option<Vec<JmapEmailAddress>>,
60    /// The `Bcc` header addresses.
61    pub bcc: Option<Vec<JmapEmailAddress>>,
62    /// The `Reply-To` header addresses.
63    pub reply_to: Option<Vec<JmapEmailAddress>>,
64    /// The `Subject` header value.
65    pub subject: Option<String>,
66    /// `Date` header as an RFC 3339 string.
67    pub sent_at: Option<String>,
68    /// The full MIME structure of the message.
69    pub body_structure: Option<JmapEmailBodyPart>,
70    /// `{ part-id -> body }` for text parts.
71    pub body_values: Option<BTreeMap<String, JmapEmailBodyValue>>,
72    /// The text/plain parts to display as the message body.
73    pub text_body: Option<Vec<JmapEmailBodyPart>>,
74    /// The text/html parts to display as the message body.
75    pub html_body: Option<Vec<JmapEmailBodyPart>>,
76    /// The parts to display as attachments.
77    pub attachments: Option<Vec<JmapEmailBodyPart>>,
78    /// Whether any part is an attachment.
79    pub has_attachment: Option<bool>,
80    /// Short plaintext preview (up to 256 chars).
81    pub preview: Option<String>,
82    /// Raw headers in order of appearance.
83    pub headers: Option<Vec<JmapEmailHeader>>,
84}
85
86/// An email address (name + email pair).
87#[derive(Clone, Debug, Serialize, Deserialize)]
88#[serde(rename_all = "camelCase")]
89pub struct JmapEmailAddress {
90    /// The display name, when present.
91    pub name: Option<String>,
92    /// The address itself (local@domain).
93    pub email: String,
94}
95
96/// A raw email header name-value pair.
97#[derive(Clone, Debug, Serialize, Deserialize)]
98#[serde(rename_all = "camelCase")]
99pub struct JmapEmailHeader {
100    /// Field name, without trailing colon.
101    pub name: String,
102    /// Raw value, with leading whitespace preserved.
103    pub value: String,
104}
105
106/// A MIME body part descriptor.
107#[derive(Clone, Debug, Default, Serialize, Deserialize)]
108#[serde(rename_all = "camelCase")]
109pub struct JmapEmailBodyPart {
110    /// Part id, scoped to the message.
111    pub part_id: Option<String>,
112    /// Blob id to download the decoded part content.
113    pub blob_id: Option<String>,
114    /// Size of the decoded part content, in bytes.
115    pub size: Option<u64>,
116    /// Filename from `Content-Disposition` or `Content-Type`.
117    pub name: Option<String>,
118    /// The `Content-Type` media type.
119    pub r#type: Option<String>,
120    /// The `Content-Type` charset parameter.
121    pub charset: Option<String>,
122    /// `inline` or `attachment`.
123    pub disposition: Option<String>,
124    /// The `Content-Id` value, without angle brackets.
125    pub cid: Option<String>,
126    /// The `Content-Language` values.
127    pub language: Option<Vec<String>>,
128    /// The `Content-Location` value.
129    pub location: Option<String>,
130    /// Sub-parts (multipart only).
131    pub sub_parts: Option<Vec<JmapEmailBodyPart>>,
132    /// Raw headers of the part.
133    pub headers: Option<Vec<JmapEmailHeader>>,
134}
135
136/// The text content of a body part.
137#[derive(Clone, Debug, Serialize, Deserialize)]
138#[serde(rename_all = "camelCase")]
139pub struct JmapEmailBodyValue {
140    /// The decoded text content.
141    pub value: String,
142    /// Charset or encoding problem during decode.
143    pub is_encoding_problem: bool,
144    /// Whether the value was truncated.
145    pub is_truncated: bool,
146}
147
148/// [`JmapEmail`] properties requestable in `Email/get` (RFC 8621 §4.1).
149#[derive(Clone, Debug, Serialize)]
150#[serde(rename_all = "camelCase")]
151pub enum JmapEmailProperty {
152    /// The `id` property.
153    Id,
154    /// The `blobId` property.
155    BlobId,
156    /// The `threadId` property.
157    ThreadId,
158    /// The `mailboxIds` property.
159    MailboxIds,
160    /// The `keywords` property.
161    Keywords,
162    /// The `size` property.
163    Size,
164    /// The `receivedAt` property.
165    ReceivedAt,
166    /// The `messageId` property.
167    MessageId,
168    /// The `inReplyTo` property.
169    InReplyTo,
170    /// The `references` property.
171    References,
172    /// The `sender` property.
173    Sender,
174    /// The `from` property.
175    From,
176    /// The `to` property.
177    To,
178    /// The `cc` property.
179    Cc,
180    /// The `bcc` property.
181    Bcc,
182    /// The `replyTo` property.
183    ReplyTo,
184    /// The `subject` property.
185    Subject,
186    /// The `sentAt` property.
187    SentAt,
188    /// The `bodyStructure` property.
189    BodyStructure,
190    /// The `bodyValues` property.
191    BodyValues,
192    /// The `textBody` property.
193    TextBody,
194    /// The `htmlBody` property.
195    HtmlBody,
196    /// The `attachments` property.
197    Attachments,
198    /// The `hasAttachment` property.
199    HasAttachment,
200    /// The `preview` property.
201    Preview,
202    /// The `headers` property.
203    Headers,
204}