use crate::config::AccountConfig;
use crate::secret::Secret;
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum MailProvider {
Gmail,
ICloud,
Yahoo,
Fastmail,
Custom,
}
impl MailProvider {
pub fn all() -> &'static [(&'static str, MailProvider)] {
&[
("Gmail", MailProvider::Gmail),
("iCloud", MailProvider::ICloud),
("Yahoo", MailProvider::Yahoo),
("Fastmail", MailProvider::Fastmail),
("Custom", MailProvider::Custom),
]
}
pub fn from_name(name: &str) -> Option<MailProvider> {
match name.to_lowercase().as_str() {
"gmail" | "google" => Some(MailProvider::Gmail),
"icloud" | "apple" => Some(MailProvider::ICloud),
"yahoo" => Some(MailProvider::Yahoo),
"fastmail" => Some(MailProvider::Fastmail),
"custom" => Some(MailProvider::Custom),
_ => None,
}
}
pub fn name(&self) -> &'static str {
match self {
MailProvider::Gmail => "Gmail",
MailProvider::ICloud => "iCloud",
MailProvider::Yahoo => "Yahoo",
MailProvider::Fastmail => "Fastmail",
MailProvider::Custom => "Custom",
}
}
pub fn host(&self) -> &'static str {
match self {
MailProvider::Gmail => "imap.gmail.com",
MailProvider::ICloud => "imap.mail.me.com",
MailProvider::Yahoo => "imap.mail.yahoo.com",
MailProvider::Fastmail => "imap.fastmail.com",
MailProvider::Custom => "",
}
}
pub fn port(&self) -> u16 {
993
}
pub fn default_config(&self, username: &str) -> AccountConfig {
let password = Some(Secret::new_keyring(format!("mail.{}", username)));
AccountConfig {
host: self.host().to_string(),
port: self.port(),
username: username.to_string(),
password,
tls: true,
max_connections: None,
}
}
}