mirror of
https://github.com/chatmail/core.git
synced 2026-05-22 16:26:31 +03:00
feat: add wildcard pattern support to provider database
This commit is contained in:
@@ -220,9 +220,9 @@ if __name__ == "__main__":
|
|||||||
|
|
||||||
process_dir(Path(sys.argv[1]))
|
process_dir(Path(sys.argv[1]))
|
||||||
|
|
||||||
out_all += "pub(crate) static PROVIDER_DATA: Lazy<HashMap<&'static str, &'static Provider>> = Lazy::new(|| HashMap::from([\n"
|
out_all += "pub(crate) static PROVIDER_DATA: [(&str, &Provider); " + str(len(domains_set)) + "] = [\n";
|
||||||
out_all += out_domains
|
out_all += out_domains
|
||||||
out_all += "]));\n\n"
|
out_all += "];\n\n"
|
||||||
|
|
||||||
out_all += "pub(crate) static PROVIDER_IDS: Lazy<HashMap<&'static str, &'static Provider>> = Lazy::new(|| HashMap::from([\n"
|
out_all += "pub(crate) static PROVIDER_IDS: Lazy<HashMap<&'static str, &'static Provider>> = Lazy::new(|| HashMap::from([\n"
|
||||||
out_all += out_ids
|
out_all += out_ids
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ set -euo pipefail
|
|||||||
export TZ=UTC
|
export TZ=UTC
|
||||||
|
|
||||||
# Provider database revision.
|
# Provider database revision.
|
||||||
REV=18f714cf73d0bdfb8b013fa344494ab80c92b477
|
REV=2f3db24107e4802c2df0aa0a40f0e144006c0a9b
|
||||||
|
|
||||||
CORE_ROOT="$PWD"
|
CORE_ROOT="$PWD"
|
||||||
TMP="$(mktemp -d)"
|
TMP="$(mktemp -d)"
|
||||||
|
|||||||
@@ -215,8 +215,18 @@ pub async fn get_provider_info(
|
|||||||
|
|
||||||
/// Finds a provider in offline database based on domain.
|
/// Finds a provider in offline database based on domain.
|
||||||
pub fn get_provider_by_domain(domain: &str) -> Option<&'static Provider> {
|
pub fn get_provider_by_domain(domain: &str) -> Option<&'static Provider> {
|
||||||
if let Some(provider) = PROVIDER_DATA.get(domain.to_lowercase().as_str()) {
|
let domain = domain.to_lowercase();
|
||||||
return Some(*provider);
|
for (pattern, provider) in PROVIDER_DATA {
|
||||||
|
if let Some(suffix) = pattern.strip_prefix('*') {
|
||||||
|
// Wildcard domain pattern.
|
||||||
|
//
|
||||||
|
// For example, `suffix` is ".hermes.radio" for "*.hermes.radio" pattern.
|
||||||
|
if domain.ends_with(suffix) {
|
||||||
|
return Some(provider);
|
||||||
|
}
|
||||||
|
} else if pattern == domain {
|
||||||
|
return Some(provider);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
None
|
None
|
||||||
@@ -226,20 +236,33 @@ pub fn get_provider_by_domain(domain: &str) -> Option<&'static Provider> {
|
|||||||
///
|
///
|
||||||
/// For security reasons, only Gmail can be configured this way.
|
/// For security reasons, only Gmail can be configured this way.
|
||||||
pub async fn get_provider_by_mx(context: &Context, domain: &str) -> Option<&'static Provider> {
|
pub async fn get_provider_by_mx(context: &Context, domain: &str) -> Option<&'static Provider> {
|
||||||
if let Ok(resolver) = get_resolver() {
|
let Ok(resolver) = get_resolver() else {
|
||||||
|
warn!(context, "Cannot get a resolver to check MX records.");
|
||||||
|
return None;
|
||||||
|
};
|
||||||
|
|
||||||
let mut fqdn: String = domain.to_string();
|
let mut fqdn: String = domain.to_string();
|
||||||
if !fqdn.ends_with('.') {
|
if !fqdn.ends_with('.') {
|
||||||
fqdn.push('.');
|
fqdn.push('.');
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Ok(mx_domains) = resolver.mx_lookup(fqdn).await {
|
let Ok(mx_domains) = resolver.mx_lookup(fqdn).await else {
|
||||||
for (provider_domain, provider) in &*PROVIDER_DATA {
|
warn!(context, "Cannot resolve MX records for {domain:?}.");
|
||||||
|
return None;
|
||||||
|
};
|
||||||
|
|
||||||
|
for (provider_domain_pattern, provider) in PROVIDER_DATA {
|
||||||
if provider.id != "gmail" {
|
if provider.id != "gmail" {
|
||||||
// MX lookup is limited to Gmail for security reasons
|
// MX lookup is limited to Gmail for security reasons
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
let provider_fqdn = provider_domain.to_string() + ".";
|
if provider_domain_pattern.starts_with('*') {
|
||||||
|
// Skip wildcard patterns.
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
let provider_fqdn = provider_domain_pattern.to_string() + ".";
|
||||||
let provider_fqdn_dot = ".".to_string() + &provider_fqdn;
|
let provider_fqdn_dot = ".".to_string() + &provider_fqdn;
|
||||||
|
|
||||||
for mx_domain in mx_domains.iter() {
|
for mx_domain in mx_domains.iter() {
|
||||||
@@ -250,10 +273,6 @@ pub async fn get_provider_by_mx(context: &Context, domain: &str) -> Option<&'sta
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
} else {
|
|
||||||
warn!(context, "cannot get a resolver to check MX records.");
|
|
||||||
}
|
|
||||||
|
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -593,7 +593,7 @@ static P_GMX_NET: Provider = Provider {
|
|||||||
oauth2_authorizer: None,
|
oauth2_authorizer: None,
|
||||||
};
|
};
|
||||||
|
|
||||||
// hermes.radio.md: ac.hermes.radio, ac1.hermes.radio, ac2.hermes.radio, ac3.hermes.radio, ac4.hermes.radio, ac5.hermes.radio, ac6.hermes.radio, ac7.hermes.radio, ac8.hermes.radio, ac9.hermes.radio, ac10.hermes.radio, ac11.hermes.radio, ac12.hermes.radio, ac13.hermes.radio, ac14.hermes.radio, ac15.hermes.radio, ka.hermes.radio, ka1.hermes.radio, ka2.hermes.radio, ka3.hermes.radio, ka4.hermes.radio, ka5.hermes.radio, ka6.hermes.radio, ka7.hermes.radio, ka8.hermes.radio, ka9.hermes.radio, ka10.hermes.radio, ka11.hermes.radio, ka12.hermes.radio, ka13.hermes.radio, ka14.hermes.radio, ka15.hermes.radio, ec.hermes.radio, ec1.hermes.radio, ec2.hermes.radio, ec3.hermes.radio, ec4.hermes.radio, ec5.hermes.radio, ec6.hermes.radio, ec7.hermes.radio, ec8.hermes.radio, ec9.hermes.radio, ec10.hermes.radio, ec11.hermes.radio, ec12.hermes.radio, ec13.hermes.radio, ec14.hermes.radio, ec15.hermes.radio, hermes.radio
|
// hermes.radio.md: *.hermes.radio, *.aco-connexion.org
|
||||||
static P_HERMES_RADIO: Provider = Provider {
|
static P_HERMES_RADIO: Provider = Provider {
|
||||||
id: "hermes.radio",
|
id: "hermes.radio",
|
||||||
status: Status::Ok,
|
status: Status::Ok,
|
||||||
@@ -1608,8 +1608,7 @@ static P_ZOHO: Provider = Provider {
|
|||||||
oauth2_authorizer: None,
|
oauth2_authorizer: None,
|
||||||
};
|
};
|
||||||
|
|
||||||
pub(crate) static PROVIDER_DATA: Lazy<HashMap<&'static str, &'static Provider>> = Lazy::new(|| {
|
pub(crate) static PROVIDER_DATA: [(&str, &Provider); 318] = [
|
||||||
HashMap::from([
|
|
||||||
("163.com", &P_163),
|
("163.com", &P_163),
|
||||||
("aktivix.org", &P_AKTIVIX_ORG),
|
("aktivix.org", &P_AKTIVIX_ORG),
|
||||||
("aol.com", &P_AOL),
|
("aol.com", &P_AOL),
|
||||||
@@ -1765,55 +1764,8 @@ pub(crate) static PROVIDER_DATA: Lazy<HashMap<&'static str, &'static Provider>>
|
|||||||
("gmx.info", &P_GMX_NET),
|
("gmx.info", &P_GMX_NET),
|
||||||
("gmx.biz", &P_GMX_NET),
|
("gmx.biz", &P_GMX_NET),
|
||||||
("gmx.com", &P_GMX_NET),
|
("gmx.com", &P_GMX_NET),
|
||||||
("ac.hermes.radio", &P_HERMES_RADIO),
|
("*.hermes.radio", &P_HERMES_RADIO),
|
||||||
("ac1.hermes.radio", &P_HERMES_RADIO),
|
("*.aco-connexion.org", &P_HERMES_RADIO),
|
||||||
("ac2.hermes.radio", &P_HERMES_RADIO),
|
|
||||||
("ac3.hermes.radio", &P_HERMES_RADIO),
|
|
||||||
("ac4.hermes.radio", &P_HERMES_RADIO),
|
|
||||||
("ac5.hermes.radio", &P_HERMES_RADIO),
|
|
||||||
("ac6.hermes.radio", &P_HERMES_RADIO),
|
|
||||||
("ac7.hermes.radio", &P_HERMES_RADIO),
|
|
||||||
("ac8.hermes.radio", &P_HERMES_RADIO),
|
|
||||||
("ac9.hermes.radio", &P_HERMES_RADIO),
|
|
||||||
("ac10.hermes.radio", &P_HERMES_RADIO),
|
|
||||||
("ac11.hermes.radio", &P_HERMES_RADIO),
|
|
||||||
("ac12.hermes.radio", &P_HERMES_RADIO),
|
|
||||||
("ac13.hermes.radio", &P_HERMES_RADIO),
|
|
||||||
("ac14.hermes.radio", &P_HERMES_RADIO),
|
|
||||||
("ac15.hermes.radio", &P_HERMES_RADIO),
|
|
||||||
("ka.hermes.radio", &P_HERMES_RADIO),
|
|
||||||
("ka1.hermes.radio", &P_HERMES_RADIO),
|
|
||||||
("ka2.hermes.radio", &P_HERMES_RADIO),
|
|
||||||
("ka3.hermes.radio", &P_HERMES_RADIO),
|
|
||||||
("ka4.hermes.radio", &P_HERMES_RADIO),
|
|
||||||
("ka5.hermes.radio", &P_HERMES_RADIO),
|
|
||||||
("ka6.hermes.radio", &P_HERMES_RADIO),
|
|
||||||
("ka7.hermes.radio", &P_HERMES_RADIO),
|
|
||||||
("ka8.hermes.radio", &P_HERMES_RADIO),
|
|
||||||
("ka9.hermes.radio", &P_HERMES_RADIO),
|
|
||||||
("ka10.hermes.radio", &P_HERMES_RADIO),
|
|
||||||
("ka11.hermes.radio", &P_HERMES_RADIO),
|
|
||||||
("ka12.hermes.radio", &P_HERMES_RADIO),
|
|
||||||
("ka13.hermes.radio", &P_HERMES_RADIO),
|
|
||||||
("ka14.hermes.radio", &P_HERMES_RADIO),
|
|
||||||
("ka15.hermes.radio", &P_HERMES_RADIO),
|
|
||||||
("ec.hermes.radio", &P_HERMES_RADIO),
|
|
||||||
("ec1.hermes.radio", &P_HERMES_RADIO),
|
|
||||||
("ec2.hermes.radio", &P_HERMES_RADIO),
|
|
||||||
("ec3.hermes.radio", &P_HERMES_RADIO),
|
|
||||||
("ec4.hermes.radio", &P_HERMES_RADIO),
|
|
||||||
("ec5.hermes.radio", &P_HERMES_RADIO),
|
|
||||||
("ec6.hermes.radio", &P_HERMES_RADIO),
|
|
||||||
("ec7.hermes.radio", &P_HERMES_RADIO),
|
|
||||||
("ec8.hermes.radio", &P_HERMES_RADIO),
|
|
||||||
("ec9.hermes.radio", &P_HERMES_RADIO),
|
|
||||||
("ec10.hermes.radio", &P_HERMES_RADIO),
|
|
||||||
("ec11.hermes.radio", &P_HERMES_RADIO),
|
|
||||||
("ec12.hermes.radio", &P_HERMES_RADIO),
|
|
||||||
("ec13.hermes.radio", &P_HERMES_RADIO),
|
|
||||||
("ec14.hermes.radio", &P_HERMES_RADIO),
|
|
||||||
("ec15.hermes.radio", &P_HERMES_RADIO),
|
|
||||||
("hermes.radio", &P_HERMES_RADIO),
|
|
||||||
("hey.com", &P_HEY_COM),
|
("hey.com", &P_HEY_COM),
|
||||||
("i.ua", &P_I_UA),
|
("i.ua", &P_I_UA),
|
||||||
("i3.net", &P_I3_NET),
|
("i3.net", &P_I3_NET),
|
||||||
@@ -1975,8 +1927,7 @@ pub(crate) static PROVIDER_DATA: Lazy<HashMap<&'static str, &'static Provider>>
|
|||||||
("zohomail.eu", &P_ZOHO),
|
("zohomail.eu", &P_ZOHO),
|
||||||
("zohomail.com", &P_ZOHO),
|
("zohomail.com", &P_ZOHO),
|
||||||
("zoho.com", &P_ZOHO),
|
("zoho.com", &P_ZOHO),
|
||||||
])
|
];
|
||||||
});
|
|
||||||
|
|
||||||
pub(crate) static PROVIDER_IDS: Lazy<HashMap<&'static str, &'static Provider>> = Lazy::new(|| {
|
pub(crate) static PROVIDER_IDS: Lazy<HashMap<&'static str, &'static Provider>> = Lazy::new(|| {
|
||||||
HashMap::from([
|
HashMap::from([
|
||||||
@@ -2050,4 +2001,4 @@ pub(crate) static PROVIDER_IDS: Lazy<HashMap<&'static str, &'static Provider>> =
|
|||||||
});
|
});
|
||||||
|
|
||||||
pub static _PROVIDER_UPDATED: Lazy<chrono::NaiveDate> =
|
pub static _PROVIDER_UPDATED: Lazy<chrono::NaiveDate> =
|
||||||
Lazy::new(|| chrono::NaiveDate::from_ymd_opt(2023, 11, 5).unwrap());
|
Lazy::new(|| chrono::NaiveDate::from_ymd_opt(2024, 2, 5).unwrap());
|
||||||
|
|||||||
Reference in New Issue
Block a user