1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
use super::{Address, EmailSubmission, Envelope, SetArguments, UndoStatus};
use crate::{core::set::SetObject, email::Email, Get, Set};
use ahash::AHashMap;
impl EmailSubmission<Set> {
pub fn identity_id(&mut self, identity_id: impl Into<String>) -> &mut Self {
self.identity_id = Some(identity_id.into());
self
}
pub fn email_id(&mut self, email_id: impl Into<String>) -> &mut Self {
self.email_id = Some(email_id.into());
self
}
pub fn envelope<S, T, U>(&mut self, mail_from: S, rcpt_to: T) -> &mut Self
where
S: Into<Address>,
T: IntoIterator<Item = U>,
U: Into<Address>,
{
self.envelope = Some(Envelope::new(mail_from, rcpt_to));
self
}
pub fn undo_status(&mut self, undo_status: UndoStatus) -> &mut Self {
self.undo_status = Some(undo_status);
self
}
}
impl SetObject for EmailSubmission<Set> {
type SetArguments = SetArguments;
fn new(_create_id: Option<usize>) -> Self {
EmailSubmission {
_create_id,
_state: Default::default(),
id: None,
identity_id: None,
email_id: None,
thread_id: None,
envelope: None,
send_at: None,
undo_status: None,
delivery_status: None,
dsn_blob_ids: None,
mdn_blob_ids: None,
}
}
fn create_id(&self) -> Option<String> {
self._create_id.map(|id| format!("c{}", id))
}
}
impl SetObject for EmailSubmission<Get> {
type SetArguments = SetArguments;
fn new(_create_id: Option<usize>) -> Self {
unimplemented!()
}
fn create_id(&self) -> Option<String> {
None
}
}
impl Envelope {
pub fn new<S, T, U>(mail_from: S, rcpt_to: T) -> Envelope
where
S: Into<Address>,
T: IntoIterator<Item = U>,
U: Into<Address>,
{
Envelope {
mail_from: mail_from.into(),
rcpt_to: rcpt_to.into_iter().map(|s| s.into()).collect(),
}
}
}
impl Address<Set> {
pub fn new(email: impl Into<String>) -> Address<Set> {
Address {
_state: Default::default(),
email: email.into(),
parameters: None,
}
}
pub fn parameter(
mut self,
parameter: impl Into<String>,
value: Option<impl Into<String>>,
) -> Self {
self.parameters
.get_or_insert_with(AHashMap::new)
.insert(parameter.into(), value.map(|s| s.into()));
self
}
}
impl From<String> for Address {
fn from(email: String) -> Self {
Address {
_state: Default::default(),
email,
parameters: None,
}
}
}
impl From<&str> for Address {
fn from(email: &str) -> Self {
Address {
_state: Default::default(),
email: email.to_string(),
parameters: None,
}
}
}
impl From<Address<Set>> for Address<Get> {
fn from(addr: Address<Set>) -> Self {
Address {
_state: Default::default(),
email: addr.email,
parameters: addr.parameters,
}
}
}
impl From<Address<Get>> for Address<Set> {
fn from(addr: Address<Get>) -> Self {
Address {
_state: Default::default(),
email: addr.email,
parameters: addr.parameters,
}
}
}
impl SetArguments {
pub fn on_success_update_email(&mut self, id: impl Into<String>) -> &mut Email<Set> {
self.on_success_update_email_(format!("#{}", id.into()))
}
pub fn on_success_update_email_id(&mut self, id: impl Into<String>) -> &mut Email<Set> {
self.on_success_update_email_(id)
}
fn on_success_update_email_(&mut self, id: impl Into<String>) -> &mut Email<Set> {
let id = id.into();
self.on_success_update_email
.get_or_insert_with(AHashMap::new)
.insert(id.clone(), Email::new(None));
self.on_success_update_email
.as_mut()
.unwrap()
.get_mut(&id)
.unwrap()
}
pub fn on_success_destroy_email(&mut self, id: impl Into<String>) -> &mut Self {
self.on_success_destroy_email
.get_or_insert_with(Vec::new)
.push(format!("#{}", id.into()));
self
}
pub fn on_success_destroy_email_id(&mut self, id: impl Into<String>) -> &mut Self {
self.on_success_destroy_email
.get_or_insert_with(Vec::new)
.push(id.into());
self
}
}