configure: try multiple servers for each protocol

LoginParamNew structure, which contained possible IMAP and SMTP
configurations to try is replaced with uniform vectors of ServerParams
structures. These vectors are initialized from provider database, online
Mozilla or Outlook XML configuration or user entered parameters.

During configuration, vectors of ServerParams are expanded to replace
unknown values with all possible variants, which are tried one by one
until configuration succeeds or all variants for a particular protocol
(IMAP or SMTP) are exhausted.

ServerParams structure is moved into configure submodule, and all
dependencies on it outside of this submodule are removed.
This commit is contained in:
Alexander Krotov
2020-08-23 00:00:00 +03:00
committed by link2xt
parent 927c7eb59d
commit 4481ab18f5
7 changed files with 500 additions and 640 deletions

View File

@@ -3,10 +3,7 @@
use std::borrow::Cow;
use std::fmt;
use crate::{
context::Context,
provider::{Protocol, Socket, UsernamePattern},
};
use crate::{context::Context, provider::Socket};
#[derive(Copy, Clone, Debug, Display, FromPrimitive, PartialEq, Eq)]
#[repr(i32)]
@@ -31,39 +28,6 @@ impl Default for CertificateChecks {
}
}
#[derive(Debug)]
pub struct ServerParams {
pub protocol: Protocol,
pub socket: Socket,
pub hostname: String,
pub port: u16,
pub username_pattern: UsernamePattern,
}
pub type ImapServers = Vec<ServerParams>;
pub type SmtpServers = Vec<ServerParams>;
#[derive(Debug)]
pub struct LoginParamNew {
pub addr: String,
pub imap: ImapServers,
pub smtp: SmtpServers,
}
impl ServerParams {
pub fn apply_username_pattern(&self, addr: String) -> String {
match self.username_pattern {
UsernamePattern::EMAIL => addr,
UsernamePattern::EMAILLOCALPART => {
if let Some(at) = addr.find('@') {
return addr.split_at(at).0.to_string();
}
addr
}
}
}
}
/// Login parameters for a single server, either IMAP or SMTP
#[derive(Default, Debug, Clone)]
pub struct ServerLoginParam {
@@ -87,11 +51,6 @@ pub struct LoginParam {
}
impl LoginParam {
/// Create a new `LoginParam` with default values.
pub fn new() -> Self {
Default::default()
}
/// Read the login parameters from the database.
pub async fn from_database(context: &Context, prefix: impl AsRef<str>) -> Self {
let prefix = prefix.as_ref();