Support for external email addresses on mailing lists (closes #152)

This commit is contained in:
mdecimus
2024-11-13 19:38:54 +13:00
parent 77de725ca8
commit b2bac5d5aa
45 changed files with 813 additions and 643 deletions

View File

@@ -248,3 +248,39 @@ impl ServerCertVerifier for DummyVerifier {
]
}
}
// Basic email sanitizer
pub fn sanitize_email(email: &str) -> Option<String> {
let mut result = String::with_capacity(email.len());
let mut found_local = false;
let mut found_domain = false;
let mut last_ch = char::from(0);
for ch in email.chars() {
if !ch.is_whitespace() {
if ch == '@' {
if !result.is_empty() && !found_local {
found_local = true;
} else {
return None;
}
} else if ch == '.' {
if !(last_ch.is_alphanumeric() || last_ch == '-' || last_ch == '_') {
return None;
} else if found_local {
found_domain = true;
}
}
last_ch = ch;
for ch in ch.to_lowercase() {
result.push(ch);
}
}
}
if found_domain && last_ch != '.' && psl::domain(result.as_bytes()).is_some() {
Some(result)
} else {
None
}
}