diff --git a/CHANGELOG.md b/CHANGELOG.md index 3126aad47..76265b970 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,6 +20,7 @@ - speed up loading of chat messages #3171 - clear more columns when message expires due to `delete_device_after` setting #3181 - do not try to use stale SMTP connections #3180 +- Slightly improve finding the correct server after logging in #3207 - retry message sending automatically if loop is not interrupted #3183 ### Changes diff --git a/src/configure/server_params.rs b/src/configure/server_params.rs index 094921332..9ecaa5e1c 100644 --- a/src/configure/server_params.rs +++ b/src/configure/server_params.rs @@ -52,10 +52,8 @@ impl ServerParams { fn expand_hostnames(self, param_domain: &str) -> Vec { if self.hostname.is_empty() { vec![ - Self { - hostname: param_domain.to_string(), - ..self.clone() - }, + // Try "imap.ex.org"/"smtp.ex.org" and "mail.ex.org" first because if a server exists + // under this address, it's likely the correct one. Self { hostname: match self.protocol { Protocol::Imap => "imap.".to_string() + param_domain, @@ -65,6 +63,12 @@ impl ServerParams { }, Self { hostname: "mail.".to_string() + param_domain, + ..self.clone() + }, + // Try "ex.org" last because if it's wrong and the server is configured to + // not answer at all, configuration may be stuck for several minutes. + Self { + hostname: param_domain.to_string(), ..self }, ] @@ -296,5 +300,48 @@ mod tests { strict_tls: Some(true) }], ); + + // Test that "example.net" is tried after "*.example.net". + let v = expand_param_vector( + vec![ServerParams { + protocol: Protocol::Imap, + hostname: "".to_string(), + port: 10480, + socket: Socket::Ssl, + username: "foobar".to_string(), + strict_tls: Some(true), + }], + "foobar@example.net", + "example.net", + ); + assert_eq!( + v, + vec![ + ServerParams { + protocol: Protocol::Imap, + hostname: "imap.example.net".to_string(), + port: 10480, + socket: Socket::Ssl, + username: "foobar".to_string(), + strict_tls: Some(true) + }, + ServerParams { + protocol: Protocol::Imap, + hostname: "mail.example.net".to_string(), + port: 10480, + socket: Socket::Ssl, + username: "foobar".to_string(), + strict_tls: Some(true) + }, + ServerParams { + protocol: Protocol::Imap, + hostname: "example.net".to_string(), + port: 10480, + socket: Socket::Ssl, + username: "foobar".to_string(), + strict_tls: Some(true) + } + ], + ); } }