Prefer TLS over STARTTLS during autoconfiguration

This commit is contained in:
link2xt
2023-02-10 10:12:35 +00:00
parent 386b5bb848
commit c9b2ad4ffa
2 changed files with 46 additions and 9 deletions

View File

@@ -99,15 +99,6 @@ impl ServerParams {
// Try common secure combinations.
vec![
// Try STARTTLS
Self {
socket: Socket::Starttls,
port: match self.protocol {
Protocol::Imap => 143,
Protocol::Smtp => 587,
},
..self.clone()
},
// Try TLS
Self {
socket: Socket::Ssl,
@@ -115,6 +106,15 @@ impl ServerParams {
Protocol::Imap => 993,
Protocol::Smtp => 465,
},
..self.clone()
},
// Try STARTTLS
Self {
socket: Socket::Starttls,
port: match self.protocol {
Protocol::Imap => 143,
Protocol::Smtp => 587,
},
..self
},
]
@@ -343,5 +343,41 @@ mod tests {
}
],
);
// Test that TLS is preferred to STARTTLS
// when the port and security are not set.
let v = expand_param_vector(
vec![ServerParams {
protocol: Protocol::Smtp,
hostname: "example.net".to_string(),
port: 0,
socket: Socket::Automatic,
username: "foobar".to_string(),
strict_tls: Some(true),
}],
"foobar@example.net",
"example.net",
);
assert_eq!(
v,
vec![
ServerParams {
protocol: Protocol::Smtp,
hostname: "example.net".to_string(),
port: 465,
socket: Socket::Ssl,
username: "foobar".to_string(),
strict_tls: Some(true)
},
ServerParams {
protocol: Protocol::Smtp,
hostname: "example.net".to_string(),
port: 587,
socket: Socket::Starttls,
username: "foobar".to_string(),
strict_tls: Some(true)
},
],
);
}
}