From 2932c1ed3540a34e67be39917ba8ba237b57c5f3 Mon Sep 17 00:00:00 2001 From: Hocuri Date: Sun, 10 Apr 2022 12:16:00 +0200 Subject: [PATCH] Configure: Try "imap.*"/"smtp.*"/"mail.*" first (#3207) * Configure: Try "imap.*"/"smtp.*"/"mail.*" first Fix half of #3158. 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. 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. * Changelog * Add test --- CHANGELOG.md | 1 + src/configure/server_params.rs | 55 +++++++++++++++++++++++++++++++--- 2 files changed, 52 insertions(+), 4 deletions(-) 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) + } + ], + ); } }