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
use crate::{Client, Result};
use serde::{Deserialize, Serialize};
#[derive(Debug, Deserialize)]
#[serde(rename_all = "PascalCase")]
pub struct DeliveryStat {
pub name: String,
#[serde(rename = "Type")]
pub bounce_type: Option<String>,
pub count: i64,
}
#[derive(Debug, Deserialize)]
#[serde(rename_all = "PascalCase")]
pub struct DeliveryStatsResponse {
pub inactive_mails: i64,
pub bounces: Vec<DeliveryStat>,
}
#[derive(Debug, Serialize, Default)]
#[serde(rename_all = "camelCase")]
pub struct BouncesQueryParamaters {
pub count: u16,
pub offset: u16,
#[serde(rename = "type")]
pub bounce_type: Option<String>,
pub inactive: Option<bool>,
pub email_filter: Option<String>,
pub tag: Option<String>,
pub message_id: Option<String>,
#[serde(rename = "fromdate")]
pub from_date: Option<String>,
#[serde(rename = "todate")]
pub to_date: Option<String>,
pub message_stream: Option<String>,
}
impl BouncesQueryParamaters {
pub fn new(count: u16, offset: u16) -> BouncesQueryParamaters {
BouncesQueryParamaters{
count,
offset,
..Default::default()
}
}
}
#[derive(Debug, Deserialize)]
#[serde(rename_all = "PascalCase")]
pub struct BouncedEmail {
#[serde(rename = "ID")]
pub id: String,
#[serde(rename = "Type")]
pub bounce_type: String,
pub type_code: String,
pub name: String,
pub tag: String,
#[serde(rename = "MessageID")]
pub message_id: String,
#[serde(rename = "ServerID")]
pub server_id: String,
pub message_stream: String,
pub description: String,
pub details: String,
pub email: String,
pub from: String,
pub bounced_at: String,
pub dump_available: bool,
pub inactive: bool,
pub can_activate: bool,
pub subject: String,
pub content: String,
}
#[derive(Debug, Deserialize)]
#[serde(rename_all = "PascalCase")]
pub struct BouncedEmailsReponse {
pub total_count: u16,
pub bounces: Vec<BouncedEmail>,
}
#[derive(Debug, Deserialize)]
#[serde(rename_all = "PascalCase")]
pub struct BounceDumpResponse {
pub body: String,
}
#[derive(Debug, Deserialize)]
#[serde(rename_all = "PascalCase")]
pub struct ActivateBounceResponse {
pub message: String,
pub bounce: BouncedEmail,
}
impl Client {
pub async fn get_delivery_stats(&self) -> Result<DeliveryStatsResponse> {
Ok(self.get("/deliverystats").await?)
}
pub async fn get_bounces(
&self,
query: &BouncesQueryParamaters,
) -> Result<BouncedEmailsReponse> {
Ok(self.get_with_query("/bounces", query).await?)
}
pub async fn get_bounce(&self, bounce_id: &str) -> Result<BouncedEmail> {
Ok(self
.get(format!("/bounces/{:}", bounce_id).as_str())
.await?)
}
pub async fn get_bounce_dump(&self, bounce_id: &str) -> Result<BounceDumpResponse> {
Ok(self
.get(format!("/bounces/{:}/dump", bounce_id).as_str())
.await?)
}
pub async fn activate_bounce(&self, bounce_id: &str) -> Result<ActivateBounceResponse> {
Ok(self
.put(format!("/bounces/{:}/activate", bounce_id).as_str())
.await?)
}
}