diff --git a/src/email.rs b/src/email.rs index c222001..4a2b4a9 100644 --- a/src/email.rs +++ b/src/email.rs @@ -17,9 +17,9 @@ use uuid::Uuid; use sendable_email::SendableEmail; -/// Converts an adress or an address with an alias to an `Address` +/// Converts an adress or an address with an alias to a `Address` pub trait ToHeader { - /// Converts to an `Header` struct + /// Converts to a `Header` struct fn to_header(&self) -> Header; } @@ -36,9 +36,9 @@ impl<'a> ToHeader for (&'a str, &'a str) { } } -/// Converts an adress or an address with an alias to an `Mailbox` +/// Converts an adress or an address with an alias to a `Mailbox` pub trait ToMailbox { - /// Converts to an `Mailbox` struct + /// Converts to a `Mailbox` struct fn to_mailbox(&self) -> Mailbox; } diff --git a/src/response.rs b/src/response.rs index eff7fe1..592d41a 100644 --- a/src/response.rs +++ b/src/response.rs @@ -7,7 +7,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -//! SMTP response, containing a mandatory return code, and an optional text message +//! SMTP response, containing a mandatory return code and an optional text message use std::str::FromStr; use std::fmt::{Display, Formatter, Result}; @@ -163,7 +163,7 @@ impl Response { format!("{}{}{}", self.severity, self.category, self.detail) } - /// Checls code equality + /// Tests code equality pub fn has_code(&self, code: u16) -> bool { self.code() == format!("{}", code) } @@ -172,9 +172,11 @@ impl Response { pub fn first_word(&self) -> Option { match self.message.is_empty() { true => None, - false => Some(self.message[0].split(" ").next().unwrap().to_string()), + false => match self.message[0].split_whitespace().next() { + Some(word) => Some(word.to_string()), + None => None, + } } - } } @@ -273,6 +275,12 @@ mod test { 1, vec!["me".to_string(), "8BITMIME".to_string(), "SIZE 42".to_string()] ).severity(), Severity::PositiveCompletion); + assert_eq!(Response::new( + "5".parse::().unwrap(), + "4".parse::().unwrap(), + 1, + vec!["me".to_string(), "8BITMIME".to_string(), "SIZE 42".to_string()] + ).severity(), Severity::PermanentNegativeCompletion); } #[test] @@ -341,5 +349,23 @@ mod test { 1, vec![] ).first_word(), None); + assert_eq!(Response::new( + "2".parse::().unwrap(), + "4".parse::().unwrap(), + 1, + vec![" ".to_string()] + ).first_word(), None); + assert_eq!(Response::new( + "2".parse::().unwrap(), + "4".parse::().unwrap(), + 1, + vec![" ".to_string()] + ).first_word(), None); + assert_eq!(Response::new( + "2".parse::().unwrap(), + "4".parse::().unwrap(), + 1, + vec!["".to_string()] + ).first_word(), None); } }