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
use crate::{unmatched_quotes, unwrap};
use rusty_yaml::Yaml;
use std::fmt::{Display, Error, Formatter};
use std::process::exit;
pub struct MailNotifier {
all_recipients: Vec<String>,
success_recipients: Vec<String>,
failure_recipients: Vec<String>,
from_address: String,
smtp_relay_host: String,
smtp_port: String,
smtp_user: String,
lookup: String,
smtp_password: String,
}
impl Display for MailNotifier {
fn fmt(&self, f: &mut Formatter) -> Result<(), Error> {
writeln!(
f,
r#"
# The mail notifier responsible for all info
all = reporters.MailNotifier(fromaddr="{from_address}",
sendToInterestedUsers=True,
extraRecipients={all_recipients},
lookup="{lookup}",
relayhost="{relay_host}", smtpPort={port},
smtpUser="{user}", buildSetSummary=True,
# addLogs=True,
mode="all",
smtpPassword="{password}")
c['services'].append(all)
# The mail notifier responsible for failures
failures = reporters.MailNotifier(fromaddr="{from_address}",
sendToInterestedUsers=True,
extraRecipients={failure_recipients},
lookup="{lookup}",
relayhost="{relay_host}", smtpPort={port},
smtpUser="{user}", buildSetSummary=True,
# addLogs=True,
mode="failing",
smtpPassword="{password}")
c['services'].append(failures)
# The mail notifier responsible for successes
successes = reporters.MailNotifier(fromaddr="{from_address}",
sendToInterestedUsers=True,
extraRecipients={success_recipients},
lookup="{lookup}",
relayhost="{relay_host}", smtpPort={port},
smtpUser="{user}", buildSetSummary=True,
# addLogs=True,
mode="passing",
smtpPassword="{password}")
c['services'].append(successes)
"#,
all_recipients = format!("{:?}", self.all_recipients),
success_recipients = format!("{:?}", self.success_recipients),
failure_recipients = format!("{:?}", self.failure_recipients),
from_address = self.from_address,
relay_host = self.smtp_relay_host,
password = self.smtp_password,
user = self.smtp_user,
port = self.smtp_port,
lookup = self.lookup,
)
}
}
impl From<Yaml> for MailNotifier {
fn from(yaml: Yaml) -> Self {
if let Some(line) = unmatched_quotes(&yaml) {
error!(
"There was a problem creating the mail notifier: unmatched quotes in the line '{}'",
line.trim()
);
exit(1);
}
for section in [
"extra-recipients",
"from-address",
"smtp-relay-host",
"smtp-port",
"lookup",
"smtp-password",
]
.iter()
{
if !yaml.has_section(section) {
error!(
"There was a problem creating the mail notifier: '{}' section not specified.",
section
);
exit(1);
}
}
let extra_recipients = yaml.get_section("extra-recipients").unwrap();
for section in ["all", "failure", "success"].iter() {
if !extra_recipients.has_section(section) {
error!("There was a problem creating the mail notifier: '{}' section not specified in the 'extra-recipients' subsection.", section);
exit(1);
}
}
let mut all_recipients = vec![];
for recipient in extra_recipients.get_section("all").unwrap() {
all_recipients.push(recipient.to_string());
}
let mut success_recipients = vec![];
for recipient in extra_recipients.get_section("success").unwrap() {
success_recipients.push(recipient.to_string());
}
let mut failure_recipients = vec![];
for recipient in extra_recipients.get_section("failure").unwrap() {
failure_recipients.push(recipient.to_string());
}
let from_address = unwrap(&yaml, "from-address");
let smtp_relay_host = unwrap(&yaml, "smtp-relay-host");
let smtp_port = unwrap(&yaml, "smtp-port");
let smtp_password = unwrap(&yaml, "smtp-password");
let lookup = unwrap(&yaml, "lookup");
Self {
all_recipients,
success_recipients,
failure_recipients,
from_address: from_address.clone(),
smtp_relay_host,
smtp_port,
smtp_user: from_address,
lookup,
smtp_password,
}
}
}