use std::fmt;
use std::fmt::{Display, Formatter};
use extension::Extension;
#[derive(Clone,Debug)]
pub struct ServerInfo {
pub name: String,
pub esmtp_features: Vec<Extension>,
}
impl Display for ServerInfo {
fn fmt(&self, f: &mut Formatter) -> fmt::Result {
write!(f, "{} with {}",
self.name,
match self.esmtp_features.is_empty() {
true => "no supported features".to_string(),
false => format! ("{:?}", self.esmtp_features),
}
)
}
}
impl ServerInfo {
pub fn supports_feature(&self, keyword: Extension) -> bool {
self.esmtp_features.contains(&keyword)
}
}
#[cfg(test)]
mod test {
use super::ServerInfo;
use extension::Extension;
#[test]
fn test_fmt() {
assert_eq!(format!("{}", ServerInfo{
name: "name".to_string(),
esmtp_features: vec![Extension::EightBitMime]
}), "name with [EightBitMime]".to_string());
assert_eq!(format!("{}", ServerInfo{
name: "name".to_string(),
esmtp_features: vec![Extension::EightBitMime]
}), "name with [EightBitMime]".to_string());
assert_eq!(format!("{}", ServerInfo{
name: "name".to_string(),
esmtp_features: vec![]
}), "name with no supported features".to_string());
}
#[test]
fn test_supports_feature() {
assert!(ServerInfo{
name: "name".to_string(),
esmtp_features: vec![Extension::EightBitMime]
}.supports_feature(Extension::EightBitMime));
assert!(ServerInfo{
name: "name".to_string(),
esmtp_features: vec![Extension::PlainAuthentication, Extension::EightBitMime]
}.supports_feature(Extension::EightBitMime));
assert_eq!(ServerInfo{
name: "name".to_string(),
esmtp_features: vec![Extension::EightBitMime]
}.supports_feature(Extension::PlainAuthentication), false);
}
}