diff --git a/src/client/mod.rs b/src/client/mod.rs index c3b740b..bd09e64 100644 --- a/src/client/mod.rs +++ b/src/client/mod.rs @@ -160,7 +160,7 @@ impl Client { /// * If `message` is `None`, the given command will be formatted and sent to the server /// * If `message` is `Some(str)`, the `str` string will be sent to the server fn send_server(&mut self, command: Command, message: Option<&str>) -> SmtpResult { - if !self.state.is_command_possible(command.clone()) { + if !self.state.is_command_allowed(command.clone()) { fail_with_err!(Response{code: 503, message: Some("Bad sequence of commands".to_string())} self); } diff --git a/src/client/stream.rs b/src/client/stream.rs index dbdc686..17dac5f 100644 --- a/src/client/stream.rs +++ b/src/client/stream.rs @@ -32,7 +32,7 @@ pub trait ClientStream { } impl ClientStream for TcpStream { - /// Sends a string to the server and get the response + /// Sends a string to the server and gets the response fn send_and_get_response(&mut self, string: &str, end: &str) -> SmtpResult { try!(self.write_str(format!("{}{}", escape_dot(string), end).as_slice())); diff --git a/src/command.rs b/src/command.rs index cb82a90..d8b7e27 100644 --- a/src/command.rs +++ b/src/command.rs @@ -33,9 +33,9 @@ pub enum Command { ExtendedHello(String), /// Hello command Hello(String), - /// Mail command, takes optionnal options + /// Mail command, takes optional options Mail(String, Option>), - /// Recipient command, takes optionnal options + /// Recipient command, takes optional options Recipient(String, Option>), /// Data command Data, @@ -43,11 +43,11 @@ pub enum Command { Message, /// Reset command Reset, - /// Verify command, takes optionnal options + /// Verify command, takes optional options Verify(String), - /// Expand command, takes optionnal options + /// Expand command, takes optional options Expand(String), - /// Help command, takes optionnal options + /// Help command, takes optional options Help(Option), /// Noop command Noop, diff --git a/src/response.rs b/src/response.rs index 1a46fb7..6a8f9dc 100644 --- a/src/response.rs +++ b/src/response.rs @@ -18,12 +18,12 @@ use common::remove_trailing_crlf; /// Contains an SMTP reply, with separed code and message /// -/// We do accept messages containing only a code, to comply with RFC5321 +/// The text message is optional, only the code is mandatory #[deriving(PartialEq,Eq,Clone)] pub struct Response { /// Server response code pub code: u16, - /// Server response string (optionnal) + /// Server response string (optional) pub message: Option } diff --git a/src/transaction.rs b/src/transaction.rs index 252ba62..592b161 100644 --- a/src/transaction.rs +++ b/src/transaction.rs @@ -54,8 +54,9 @@ impl TransactionState { pub fn new() -> TransactionState { Unconnected } - /// TODO - pub fn is_command_possible(&self, command: Command) -> bool { + + /// Tests if the given command is allowed in the current state + pub fn is_command_allowed(&self, command: Command) -> bool { match (*self, command) { (Unconnected, command::Connect) => true, (Unconnected, _) => false, @@ -81,7 +82,9 @@ impl TransactionState { } } - /// TODO + /// Returns the state resulting of the given command + /// + /// A `None` return value means the comand is not allowed. pub fn next_state(&mut self, command: Command) -> Option { match (*self, command) { (Unconnected, command::Connect) => Some(Connected), @@ -120,11 +123,11 @@ mod test { } #[test] - fn test_is_command_possible() { - assert!(!super::Unconnected.is_command_possible(command::Noop)); - assert!(!super::DataSent.is_command_possible(command::Noop)); - assert!(super::HelloSent.is_command_possible(command::Mail("".to_string(), None))); - assert!(!super::MailSent.is_command_possible(command::Mail("".to_string(), None))); + fn test_is_command_allowed() { + assert!(!super::Unconnected.is_command_allowed(command::Noop)); + assert!(!super::DataSent.is_command_allowed(command::Noop)); + assert!(super::HelloSent.is_command_allowed(command::Mail("".to_string(), None))); + assert!(!super::MailSent.is_command_allowed(command::Mail("".to_string(), None))); } #[test]