Support for external email addresses on mailing lists (closes #152)
This commit is contained in:
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user