use crate::common::*;
use std::net::{Ipv4Addr, Ipv6Addr};
#[derive(Eq, PartialEq, Debug, Clone)]
pub enum SmtpHost {
Domain(String),
Ipv4(Ipv4Addr),
Ipv6(Ipv6Addr),
Invalid { label: String, literal: String },
Other { label: String, literal: String },
}
impl SmtpHost {
pub fn domain(&self) -> String {
match self {
SmtpHost::Domain(s) => s.clone(),
SmtpHost::Ipv4(ip) => format!("{}", ip),
SmtpHost::Ipv6(ip) => format!("{}", ip),
SmtpHost::Invalid { label, literal } => format!("{}:{}", label, literal),
SmtpHost::Other { label, literal } => format!("{}:{}", label, literal),
}
}
}
impl fmt::Display for SmtpHost {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
use self::SmtpHost::*;
match *self {
Domain(ref h) => f.write_str(h),
Ipv4(ref h) => write!(f, "[{}]", h),
Ipv6(ref h) => write!(f, "[IPv6:{}]", h),
Invalid {
ref label,
ref literal,
} => write!(f, "[{}:{}]", label, literal),
Other {
ref label,
ref literal,
} => write!(f, "[{}:{}]", label, literal),
}
}
}