diff --git a/src/provider/data.rs b/src/provider/data.rs index 898905b2a..2e386a36b 100644 --- a/src/provider/data.rs +++ b/src/provider/data.rs @@ -2,11 +2,11 @@ use crate::provider::*; use crate::provider::Protocol::*; use crate::provider::Socket::*; use crate::provider::UsernamePattern::*; +use std::collections::HashMap; lazy_static::lazy_static! { - pub static ref PROVIDER_DATA: Vec = vec![ - Provider { - domains: "nauta.cu", + // nauta.cu + static ref P1: Provider = Provider { status: Status::OK, before_login_hint: "", after_login_hint: "", @@ -15,33 +15,45 @@ lazy_static::lazy_static! { Server { protocol: IMAP, socket: STARTTLS, hostname: "imap.nauta.cu", port: 143, username_pattern: EMAIL }, Server { protocol: SMTP, socket: STARTTLS, hostname: "smtp.nauta.cu", port: 25, username_pattern: EMAIL }, ], - }, - Provider { - domains: "outlook.com hotmail.com live.com", + }; + + // outlook.com, hotmail.com, live.com + static ref P2: Provider = Provider { status: Status::BROKEN, before_login_hint: "Outlook-e-mail-addresses will not work as expected as these servers remove some important transport information.\n\nHopefully sooner or later there will be a fix; for now, we suggest to use another e-mail-address or try Delta Chat again when the issue is fixed.", after_login_hint: "", overview_page: "https://provider.delta.chat/outlook.com", server: vec![ ], - }, - Provider { - domains: "testrun.org", + }; + + // testrun.org + static ref P3: Provider = Provider { status: Status::OK, before_login_hint: "", after_login_hint: "testrun.org is not Delta Chat :)", overview_page: "", server: vec![ ], - }, - Provider { - domains: "gmail.com googlemail.com", + }; + + // gmail.com, googlemail.com + static ref P4: Provider = Provider { status: Status::PREPARATION, before_login_hint: "For Gmail Accounts, you need to create an App-Password if you have \"2-Step Verification\" enabled. If this setting is not available, you need to enable \"Less secure apps\".", after_login_hint: "", overview_page: "https://provider.delta.chat/gmail.com", server: vec![ ], - }, - ]; + }; + + pub static ref PROVIDER_DATA: HashMap<&'static str, &'static Provider> = [ + ("nauta.cu", &*P1), + ("outlook.com", &*P2), + ("hotmail.com", &*P2), + ("live.com", &*P2), + ("testrun.org", &*P3), + ("gmail.com", &*P4), + ("googlemail.com", &*P4), + ].iter().copied().collect(); } diff --git a/src/provider/mod.rs b/src/provider/mod.rs index caa729061..dba595ce6 100644 --- a/src/provider/mod.rs +++ b/src/provider/mod.rs @@ -57,7 +57,6 @@ impl Server { #[derive(Debug)] pub struct Provider { - pub domains: &'static str, pub status: Status, pub before_login_hint: &'static str, pub after_login_hint: &'static str, @@ -91,12 +90,8 @@ pub fn get_provider_info(addr: &str) -> Option<&Provider> { } .to_lowercase(); - for record in PROVIDER_DATA.iter() { - for record_domain in record.domains.split(' ') { - if record_domain == domain { - return Some(record); - } - } + if let Some(provider) = PROVIDER_DATA.get(domain.as_str()) { + return Some(*provider); } None