From 4bd27f2ca4de544c5a8f4b87b3c83887b5c3d9d5 Mon Sep 17 00:00:00 2001 From: Alexis Mousset Date: Sat, 28 Feb 2015 16:30:58 +0100 Subject: [PATCH] esmtp_features does not need to be an Option --- src/client/mod.rs | 13 +------------ src/client/server_info.rs | 38 ++++++++++++++++---------------------- 2 files changed, 17 insertions(+), 34 deletions(-) diff --git a/src/client/mod.rs b/src/client/mod.rs index beeb009..f3b9a09 100644 --- a/src/client/mod.rs +++ b/src/client/mod.rs @@ -301,7 +301,7 @@ impl Client { self.server_info = Some( ServerInfo{ name: get_first_word(result.message.as_ref().unwrap().as_slice()).to_string(), - esmtp_features: None, + esmtp_features: vec!(), } ); Ok(result) @@ -339,7 +339,6 @@ impl Client { }; // Checks message encoding according to the server's capability - // TODO : Add an encoding check. let options = match server_info.supports_feature(Extension::EightBitMime) { Some(extension) => Some(vec![extension.client_mail_option().unwrap().to_string()]), None => None, @@ -394,16 +393,6 @@ impl Client { } } - // Get maximum message size if defined and compare to the message size - if let Some(Extension::Size(max)) = server_info.supports_feature(Extension::Size(0)) { - if message_content.len() > max { - close_and_return_err!(Response{ - code: 552, - message: Some("Message exceeds fixed maximum message size".to_string()), - }, self); - } - } - let result = self.send_message(message_content); if result.is_ok() { diff --git a/src/client/server_info.rs b/src/client/server_info.rs index f1b6d3e..577f2d0 100644 --- a/src/client/server_info.rs +++ b/src/client/server_info.rs @@ -24,17 +24,16 @@ pub struct ServerInfo { /// ESMTP features supported by the server /// /// It contains the features supported by the server and known by the `Extension` module. - /// The `None` value means the server does not support ESMTP. - pub esmtp_features: Option>, + pub esmtp_features: Vec, } impl Display for ServerInfo { fn fmt(&self, f: &mut Formatter) -> fmt::Result { write!(f, "{} with {}", self.name, - match self.esmtp_features { - Some(ref features) => format! ("{:?}", features), - None => "no supported features".to_string(), + match self.esmtp_features.is_empty() { + true => "no supported features".to_string(), + false => format! ("{:?}", self.esmtp_features), } ) } @@ -43,17 +42,12 @@ impl Display for ServerInfo { impl ServerInfo { /// Checks if the server supports an ESMTP feature pub fn supports_feature(&self, keyword: Extension) -> Option { - match self.esmtp_features { - Some(ref esmtp_features) => { - for feature in esmtp_features.iter() { - if keyword.same_extension_as(feature) { - return Some(*feature); - } - } - None - }, - None => None, + for feature in self.esmtp_features.iter() { + if keyword.same_extension_as(feature) { + return Some(*feature); + } } + None } } @@ -66,15 +60,15 @@ mod test { fn test_fmt() { assert_eq!(format!("{}", ServerInfo{ name: "name".to_string(), - esmtp_features: Some(vec![Extension::EightBitMime]) + esmtp_features: vec![Extension::EightBitMime] }), "name with [EightBitMime]".to_string()); assert_eq!(format!("{}", ServerInfo{ name: "name".to_string(), - esmtp_features: Some(vec![Extension::EightBitMime, Extension::Size(42)]) + esmtp_features: vec![Extension::EightBitMime, Extension::Size(42)] }), "name with [EightBitMime, Size(42)]".to_string()); assert_eq!(format!("{}", ServerInfo{ name: "name".to_string(), - esmtp_features: None + esmtp_features: vec!() }), "name with no supported features".to_string()); } @@ -82,19 +76,19 @@ mod test { fn test_supports_feature() { assert_eq!(ServerInfo{ name: "name".to_string(), - esmtp_features: Some(vec![Extension::EightBitMime]) + esmtp_features: vec![Extension::EightBitMime] }.supports_feature(Extension::EightBitMime), Some(Extension::EightBitMime)); assert_eq!(ServerInfo{ name: "name".to_string(), - esmtp_features: Some(vec![Extension::Size(42), Extension::EightBitMime]) + esmtp_features: vec![Extension::Size(42), Extension::EightBitMime] }.supports_feature(Extension::EightBitMime), Some(Extension::EightBitMime)); assert_eq!(ServerInfo{ name: "name".to_string(), - esmtp_features: Some(vec![Extension::Size(42), Extension::EightBitMime]) + esmtp_features: vec![Extension::Size(42), Extension::EightBitMime] }.supports_feature(Extension::Size(0)), Some(Extension::Size(42))); assert!(ServerInfo{ name: "name".to_string(), - esmtp_features: Some(vec![Extension::EightBitMime]) + esmtp_features: vec![Extension::EightBitMime] }.supports_feature(Extension::Size(42)).is_none()); } }