1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
use serde::{Serialize, Deserialize};
pub const PROVIDER_OVERVIEW_URL: &'static str = "https://providers.delta.chat";
#[derive(Serialize, Deserialize, Debug, PartialEq)]
pub enum StatusState {
OK = 1,
PREPARATION = 2,
BROKEN = 3,
}
#[derive(Serialize, Deserialize, Debug, PartialEq)]
pub struct Status {
pub state: StatusState,
pub date: &'static str,
}
#[derive(Serialize, Deserialize, Debug, PartialEq)]
pub struct Provider {
pub overview_page: &'static str,
pub name: &'static str,
pub status: Status,
pub markdown: &'static str,
}
#[derive(Serialize, Deserialize, Debug, PartialEq)]
struct DomainDBEntry {
domain: &'static str,
list_index: u32,
}
include!(concat!(env!("OUT_DIR"), "/data.rs"));
pub fn get_domain_from_email(valid_email_address: &str) -> &str {
valid_email_address.split('@').last().unwrap()
}
pub fn get_provider_info(domain: &str) -> Option<&Provider> {
let domain_search_res: Option<&DomainDBEntry> = DOMAIN_DB.iter().find(|e| e.domain == domain);
let provider_id: u32 = domain_search_res?.list_index;
Some(&DATABASE[provider_id as usize])
}
mod tests {
#[allow(unused_imports)]
use super::*;
#[test]
fn main() {
println!("{:#?}", get_provider_info("mailbox.org"));
}
#[test]
fn test_example_domain() {
assert_eq!(
Some(&Provider {
overview_page: "example.com",
name: "Example",
status: Status {
state: StatusState::PREPARATION,
date: "2018-09",
},
markdown: "\n...",
}),
get_provider_info("example.org")
);
}
#[test]
fn test_get_domain_from_email() {
assert_eq!(
"secure.mailbox.org",
get_domain_from_email("testacc.test@secure.mailbox.org")
);
assert_eq!("t.d", get_domain_from_email("0.!#$%&'*+-/=?^_`{|}~@t.d"));
assert_eq!("b-b", get_domain_from_email("d@b-b"))
}
}