Skip to content

Commit 955c843

Browse files
author
Alexander Krotov
committed
Introduce ServerLoginParam
This splits LoginParam into IMAP and SMTP parts.
1 parent 06f677f commit 955c843

File tree

7 files changed

+208
-193
lines changed

7 files changed

+208
-193
lines changed

src/configure/auto_mozilla.rs

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,10 @@ fn parse_xml(in_emailaddr: &str, xml_raw: &str) -> Result<LoginParam, Error> {
8383
buf.clear();
8484
}
8585

86-
if moz_ac.out.mail_server.is_empty()
87-
|| moz_ac.out.mail_port == 0
88-
|| moz_ac.out.send_server.is_empty()
89-
|| moz_ac.out.send_port == 0
86+
if moz_ac.out.imap.server.is_empty()
87+
|| moz_ac.out.imap.port == 0
88+
|| moz_ac.out.smtp.server.is_empty()
89+
|| moz_ac.out.smtp.port == 0
9090
{
9191
Err(Error::IncompleteAutoconfig(moz_ac.out))
9292
} else {
@@ -130,37 +130,37 @@ fn moz_autoconfigure_text_cb<B: std::io::BufRead>(
130130

131131
match moz_ac.tag_server {
132132
MozServer::Imap => match moz_ac.tag_config {
133-
MozConfigTag::Hostname => moz_ac.out.mail_server = val,
134-
MozConfigTag::Port => moz_ac.out.mail_port = val.parse().unwrap_or_default(),
135-
MozConfigTag::Username => moz_ac.out.mail_user = val,
133+
MozConfigTag::Hostname => moz_ac.out.imap.server = val,
134+
MozConfigTag::Port => moz_ac.out.imap.port = val.parse().unwrap_or_default(),
135+
MozConfigTag::Username => moz_ac.out.imap.user = val,
136136
MozConfigTag::Sockettype => {
137137
let val_lower = val.to_lowercase();
138138
if val_lower == "ssl" {
139-
moz_ac.out.mail_security = Socket::SSL;
139+
moz_ac.out.imap.security = Socket::SSL;
140140
}
141141
if val_lower == "starttls" {
142-
moz_ac.out.mail_security = Socket::STARTTLS;
142+
moz_ac.out.imap.security = Socket::STARTTLS;
143143
}
144144
if val_lower == "plain" {
145-
moz_ac.out.mail_security = Socket::Plain;
145+
moz_ac.out.imap.security = Socket::Plain;
146146
}
147147
}
148148
_ => {}
149149
},
150150
MozServer::Smtp => match moz_ac.tag_config {
151-
MozConfigTag::Hostname => moz_ac.out.send_server = val,
152-
MozConfigTag::Port => moz_ac.out.send_port = val.parse().unwrap_or_default(),
153-
MozConfigTag::Username => moz_ac.out.send_user = val,
151+
MozConfigTag::Hostname => moz_ac.out.smtp.server = val,
152+
MozConfigTag::Port => moz_ac.out.smtp.port = val.parse().unwrap_or_default(),
153+
MozConfigTag::Username => moz_ac.out.smtp.user = val,
154154
MozConfigTag::Sockettype => {
155155
let val_lower = val.to_lowercase();
156156
if val_lower == "ssl" {
157-
moz_ac.out.send_security = Socket::SSL;
157+
moz_ac.out.smtp.security = Socket::SSL;
158158
}
159159
if val_lower == "starttls" {
160-
moz_ac.out.send_security = Socket::STARTTLS;
160+
moz_ac.out.smtp.security = Socket::STARTTLS;
161161
}
162162
if val_lower == "plain" {
163-
moz_ac.out.send_security = Socket::Plain;
163+
moz_ac.out.smtp.security = Socket::Plain;
164164
}
165165
}
166166
_ => {}
@@ -314,9 +314,9 @@ mod tests {
314314
</webMail>
315315
</clientConfig>";
316316
let res = parse_xml("[email protected]", xml_raw).expect("XML parsing failed");
317-
assert_eq!(res.mail_server, "outlook.office365.com");
318-
assert_eq!(res.mail_port, 993);
319-
assert_eq!(res.send_server, "smtp.office365.com");
320-
assert_eq!(res.send_port, 587);
317+
assert_eq!(res.imap.server, "outlook.office365.com");
318+
assert_eq!(res.imap.port, 993);
319+
assert_eq!(res.smtp.server, "smtp.office365.com");
320+
assert_eq!(res.smtp.port, 587);
321321
}
322322
}

src/configure/auto_outlook.rs

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ struct OutlookAutodiscover {
1515
pub out_smtp_set: bool,
1616
pub config_type: Option<String>,
1717
pub config_server: String,
18-
pub config_port: i32,
18+
pub config_port: u16,
1919
pub config_ssl: String,
2020
pub config_redirecturl: Option<String>,
2121
}
@@ -98,10 +98,10 @@ fn parse_xml(xml_raw: &str) -> Result<ParsingResult, Error> {
9898
let res = if outlk_ad.config_redirecturl.is_none()
9999
|| outlk_ad.config_redirecturl.as_ref().unwrap().is_empty()
100100
{
101-
if outlk_ad.out.mail_server.is_empty()
102-
|| outlk_ad.out.mail_port == 0
103-
|| outlk_ad.out.send_server.is_empty()
104-
|| outlk_ad.out.send_port == 0
101+
if outlk_ad.out.imap.server.is_empty()
102+
|| outlk_ad.out.imap.port == 0
103+
|| outlk_ad.out.smtp.server.is_empty()
104+
|| outlk_ad.out.smtp.port == 0
105105
{
106106
return Err(Error::IncompleteAutoconfig(outlk_ad.out));
107107
}
@@ -142,23 +142,23 @@ fn outlk_autodiscover_endtag_cb(event: &BytesEnd, outlk_ad: &mut OutlookAutodisc
142142
let ssl_on = outlk_ad.config_ssl == "on";
143143
let ssl_off = outlk_ad.config_ssl == "off";
144144
if type_ == "imap" && !outlk_ad.out_imap_set {
145-
outlk_ad.out.mail_server =
145+
outlk_ad.out.imap.server =
146146
std::mem::replace(&mut outlk_ad.config_server, String::new());
147-
outlk_ad.out.mail_port = port;
147+
outlk_ad.out.imap.port = port;
148148
if ssl_on {
149-
outlk_ad.out.mail_security = Socket::SSL
149+
outlk_ad.out.imap.security = Socket::SSL
150150
} else if ssl_off {
151-
outlk_ad.out.mail_security = Socket::Plain
151+
outlk_ad.out.imap.security = Socket::Plain
152152
}
153153
outlk_ad.out_imap_set = true
154154
} else if type_ == "smtp" && !outlk_ad.out_smtp_set {
155-
outlk_ad.out.send_server =
155+
outlk_ad.out.smtp.server =
156156
std::mem::replace(&mut outlk_ad.config_server, String::new());
157-
outlk_ad.out.send_port = outlk_ad.config_port;
157+
outlk_ad.out.smtp.port = outlk_ad.config_port;
158158
if ssl_on {
159-
outlk_ad.out.send_security = Socket::SSL
159+
outlk_ad.out.smtp.security = Socket::SSL
160160
} else if ssl_off {
161-
outlk_ad.out.send_security = Socket::Plain
161+
outlk_ad.out.smtp.security = Socket::Plain
162162
}
163163
outlk_ad.out_smtp_set = true
164164
}
@@ -229,10 +229,10 @@ mod tests {
229229

230230
match res {
231231
ParsingResult::LoginParam(lp) => {
232-
assert_eq!(lp.mail_server, "example.com");
233-
assert_eq!(lp.mail_port, 993);
234-
assert_eq!(lp.send_server, "smtp.example.com");
235-
assert_eq!(lp.send_port, 25);
232+
assert_eq!(lp.imap.server, "example.com");
233+
assert_eq!(lp.imap.port, 993);
234+
assert_eq!(lp.smtp.server, "smtp.example.com");
235+
assert_eq!(lp.smtp.port, 25);
236236
}
237237
ParsingResult::RedirectUrl(_) => {
238238
panic!("RedirectUrl is not expected");

0 commit comments

Comments
 (0)