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
use crate::delivery_result::DeliveryResult;
use crate::recipient_status::{InternalRecipientStatus, RecipientStatus};
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct InternalMessageStatus {
pub message_id: String,
pub recipients: Vec<InternalRecipientStatus>,
pub attempts_remaining: u8,
}
impl InternalMessageStatus {
pub fn as_message_status(&self) -> MessageStatus {
MessageStatus {
message_id: self.message_id.clone(),
recipient_status: self.recipients
.iter()
.map(|r| RecipientStatus {
recipient: r.email_addr.clone(),
result: r.result.clone(),
})
.collect(),
}
}
}
#[derive(Debug, Serialize, Deserialize)]
pub struct MessageStatus {
pub message_id: String,
pub recipient_status: Vec<RecipientStatus>,
}
impl MessageStatus {
pub fn succeeded(&self) -> bool {
self.recipient_status.iter().all(|r| match r.result {
DeliveryResult::Delivered(_) => true,
_ => false,
})
}
pub fn completed(&self) -> bool {
self.recipient_status.iter().all(|r| r.result.completed())
}
}