Skip to main content

agentmail/types/
drafts.rs

1use super::Attachment;
2use serde::{Deserialize, Serialize};
3
4/// Request body for [`Client::create_draft`]. At least one recipient or a
5/// reply/forward-of reference and one of `text`/`html` are required by the
6/// API.
7#[derive(Clone, Debug, Default, Serialize)]
8pub struct CreateDraft {
9    /// Primary recipients.
10    #[serde(skip_serializing_if = "Vec::is_empty")]
11    pub to: Vec<String>,
12    /// Carbon-copy recipients.
13    #[serde(skip_serializing_if = "Vec::is_empty")]
14    pub cc: Vec<String>,
15    /// Blind-carbon-copy recipients.
16    #[serde(skip_serializing_if = "Vec::is_empty")]
17    pub bcc: Vec<String>,
18    /// Subject line.
19    #[serde(skip_serializing_if = "Option::is_none")]
20    pub subject: Option<String>,
21    /// Plain-text body.
22    #[serde(skip_serializing_if = "Option::is_none")]
23    pub text: Option<String>,
24    /// HTML body.
25    #[serde(skip_serializing_if = "Option::is_none")]
26    pub html: Option<String>,
27    /// Message id this draft is in reply to.
28    #[serde(skip_serializing_if = "Option::is_none")]
29    pub in_reply_to: Option<String>,
30    /// When creating a reply draft, set true to reply to all recipients of
31    /// the referenced message.
32    #[serde(skip_serializing_if = "Option::is_none")]
33    pub reply_all: Option<bool>,
34    /// Message id this draft is a forward of.
35    #[serde(skip_serializing_if = "Option::is_none")]
36    pub forward_of: Option<String>,
37    /// Labels to attach to the draft.
38    #[serde(skip_serializing_if = "Vec::is_empty")]
39    pub labels: Vec<String>,
40    /// Schedule send at this RFC 3339 timestamp.
41    #[serde(skip_serializing_if = "Option::is_none")]
42    pub send_at: Option<String>,
43}
44/// Request body for [`Client::update_draft`]. Every field is optional;
45/// omitted fields are left unchanged on the server. Pass `Some(vec![])`
46/// to clear a recipient field; pass `None` to leave it alone.
47#[derive(Clone, Debug, Default, Serialize)]
48pub struct UpdateDraft {
49    /// Primary recipients.
50    #[serde(skip_serializing_if = "Option::is_none")]
51    pub to: Option<Vec<String>>,
52    /// Carbon-copy recipients.
53    #[serde(skip_serializing_if = "Option::is_none")]
54    pub cc: Option<Vec<String>>,
55    /// Blind-carbon-copy recipients.
56    #[serde(skip_serializing_if = "Option::is_none")]
57    pub bcc: Option<Vec<String>>,
58    /// Subject line.
59    #[serde(skip_serializing_if = "Option::is_none")]
60    pub subject: Option<String>,
61    /// Plain-text body.
62    #[serde(skip_serializing_if = "Option::is_none")]
63    pub text: Option<String>,
64    /// HTML body.
65    #[serde(skip_serializing_if = "Option::is_none")]
66    pub html: Option<String>,
67    /// Labels to add.
68    #[serde(skip_serializing_if = "Option::is_none")]
69    pub add_labels: Option<Vec<String>>,
70    /// Labels to remove.
71    #[serde(skip_serializing_if = "Option::is_none")]
72    pub remove_labels: Option<Vec<String>>,
73    /// Schedule send at this RFC 3339 timestamp.
74    #[serde(skip_serializing_if = "Option::is_none")]
75    pub send_at: Option<String>,
76}
77/// A draft message, as the API returns it. List items are a subset of the
78/// full get-draft shape; every optional field defaults so both parse.
79#[derive(Clone, Debug, Deserialize)]
80pub struct Draft {
81    /// Unique draft id.
82    pub draft_id: String,
83    /// Inbox the draft belongs to.
84    #[serde(default)]
85    pub inbox_id: Option<String>,
86    /// Primary recipients.
87    #[serde(default)]
88    pub to: Vec<String>,
89    /// Carbon-copy recipients.
90    #[serde(default)]
91    pub cc: Vec<String>,
92    /// Blind-carbon-copy recipients.
93    #[serde(default)]
94    pub bcc: Vec<String>,
95    /// Subject line.
96    #[serde(default)]
97    pub subject: Option<String>,
98    /// Plain-text body.
99    #[serde(default)]
100    pub text: Option<String>,
101    /// HTML body.
102    #[serde(default)]
103    pub html: Option<String>,
104    /// Labels on the draft.
105    #[serde(default)]
106    pub labels: Vec<String>,
107    /// Message id this draft is replying to.
108    #[serde(default)]
109    pub in_reply_to: Option<String>,
110    /// Whether the draft was created as a reply-all.
111    #[serde(default)]
112    pub reply_all: Option<bool>,
113    /// Message id this draft is forwarding.
114    #[serde(default)]
115    pub forward_of: Option<String>,
116    /// Scheduled send time (RFC 3339).
117    #[serde(default)]
118    pub send_at: Option<String>,
119    /// Timestamp the draft was created (RFC 3339).
120    #[serde(default)]
121    pub created_at: Option<String>,
122    /// Timestamp the draft was last updated (RFC 3339).
123    #[serde(default)]
124    pub updated_at: Option<String>,
125    /// Sender address (available in get responses).
126    #[serde(default)]
127    pub from: Option<String>,
128    /// Attachments on the draft.
129    #[serde(default)]
130    pub attachments: Vec<Attachment>,
131}
132/// One page of drafts from [`Client::list_drafts_page`].
133#[derive(Clone, Debug, Deserialize)]
134pub struct DraftList {
135    /// Total drafts in the inbox (not just this page).
136    pub count: u64,
137    /// This page of drafts.
138    #[serde(default)]
139    pub drafts: Vec<Draft>,
140    /// Cursor for the next page; `None` on the last page.
141    #[serde(default)]
142    pub next_page_token: Option<String>,
143}