diff --git a/src/smtp/client.rs b/src/smtp/client.rs index fea323f..935662b 100644 --- a/src/smtp/client.rs +++ b/src/smtp/client.rs @@ -82,7 +82,13 @@ struct SmtpServerInfo { impl Show for SmtpServerInfo{ fn fmt(&self, f: &mut Formatter) -> fmt::Result { f.buf.write( - format!("{} with {}", self.name, self.esmtp_features).as_bytes() + format!("{} with {}", + self.name, + match self.esmtp_features.clone() { + Some(features) => features.to_str(), + None => format!("no supported features") + } + ).as_bytes() ) } } @@ -511,7 +517,8 @@ impl Writer for SmtpClient { #[cfg(test)] mod test { - use super::{SmtpResponse}; + use super::{SmtpResponse, SmtpServerInfo}; + use commands; #[test] fn test_smtp_response_fmt() { @@ -532,6 +539,12 @@ mod test { message: StrBuf::from_str("response message") }) ); + assert!(from_str::>("200-response\r\nmessage") == + Some(SmtpResponse{ + code: 200, + message: StrBuf::from_str("response\r\nmessage") + }) + ); assert!(from_str::>("2000response message") == None); assert!(from_str::>("20a response message") == None); } @@ -542,5 +555,28 @@ mod test { Ok(SmtpResponse{code: 200, message: "message"})); assert!(SmtpResponse{code: 400, message: "message"}.with_code(vec!(200)) == Err(SmtpResponse{code: 400, message: "message"})); + assert!(SmtpResponse{code: 200, message: "message"}.with_code(vec!(200, 300)) == + Ok(SmtpResponse{code: 200, message: "message"})); + } + + #[test] + fn test_smtp_server_info_fmt() { + assert!(format!("{}", SmtpServerInfo{ + name: "name", + esmtp_features: Some(vec!(commands::EightBitMime)) + }) == ~"name with [8BITMIME]"); + assert!(format!("{}", SmtpServerInfo{ + name: "name", + esmtp_features: Some(vec!(commands::EightBitMime, commands::Size(42))) + }) == ~"name with [8BITMIME, SIZE=42]"); + assert!(format!("{}", SmtpServerInfo{ + name: "name", + esmtp_features: None + }) == ~"name with no supported features"); + } + + #[test] + fn test_smtp_server_info_parse_esmtp_response() { + } }