Files
husk-milter/src/mail.rs
T
Malte Meiboom bf53af50ec Add introducer add command
- Create a command to add an introducer (with domains).
- Add a module for escaping regular expressions used in certifications
- Add some helper functions.
2026-05-04 22:55:02 +02:00

39 lines
818 B
Rust

//
// Husk milter
//
// mail functions
//
use std::ffi::CString;
use sequoia_openpgp::packet::UserID;
pub fn to_userid(rcpt: &CString) -> Option<UserID> {
match rcpt.to_str() {
Ok(s) => Some(UserID::from(s)),
_ => None
}
}
pub fn to_email(rcpt: &CString) -> Option<String> {
if let Some(u) = to_userid(rcpt) {
if let Ok(Some(e)) = u.email() { Some(e.to_string()) }
else { None }
} else { None }
}
/// Checks if the parameter has a valid email format.
pub fn is_email(email: &str) -> bool {
let uid = UserID::from(email);
if let Ok(Some(e)) = uid.email() {
e == email
} else {
false
}
}
/// Checks if the parameter has a valid domain format.
pub fn is_domain(domain: &str) -> bool {
is_email(format!("test@{}", domain).as_str())
}