use lettre::address::Address;
#[allow(missing_docs)]
pub enum Category {
To,
Cc,
Bcc,
}
#[allow(missing_docs)]
pub struct Recipient {
pub name: String, pub email: String,
pub category: Category,
}
impl Recipient {
pub fn new(name: &str, email: &str, category: Category) -> Self {
Self {
name: name.to_owned(),
email: email.to_owned(),
category,
}
}
pub fn address(email: &str) -> Self {
Self {
name: "".to_owned(),
email: email.to_owned(),
category: Category::To,
}
}
pub(crate) fn get_address(&self) -> Address {
self.email
.parse::<Address>()
.expect("Invalid email address")
}
pub(crate) fn get_name(&self) -> Option<String> {
if self.name.is_empty() {
None
} else {
Some(self.name.clone())
}
}
}