diff --git a/src/error.rs b/src/error.rs index 80d75bc..7bf7e3a 100644 --- a/src/error.rs +++ b/src/error.rs @@ -9,17 +9,17 @@ //! Error and result type for SMTP clients -use std::error::Error; +use std::error::Error as StdError; use std::io; use std::fmt::{Display, Formatter}; use std::fmt; use response::{Severity, Response}; -use self::SmtpError::*; +use self::Error::*; /// An enum of all error kinds. #[derive(Debug)] -pub enum SmtpError { +pub enum Error { /// Transient SMTP error, 4xx reply code /// /// [RFC 5321, section 4.2.1](https://tools.ietf.org/html/rfc5321#section-4.2.1) @@ -34,13 +34,13 @@ pub enum SmtpError { IoError(io::Error), } -impl Display for SmtpError { +impl Display for Error { fn fmt(&self, fmt: &mut Formatter) -> Result<(), fmt::Error> { fmt.write_str(self.description()) } } -impl Error for SmtpError { +impl StdError for Error { fn description(&self) -> &str { match *self { TransientError(_) => "a transient error occured during the SMTP transaction", @@ -50,22 +50,22 @@ impl Error for SmtpError { } } - fn cause(&self) -> Option<&Error> { + fn cause(&self) -> Option<&StdError> { match *self { - IoError(ref err) => Some(&*err as &Error), + IoError(ref err) => Some(&*err as &StdError), _ => None, } } } -impl From for SmtpError { - fn from(err: io::Error) -> SmtpError { +impl From for Error { + fn from(err: io::Error) -> Error { IoError(err) } } -impl From for SmtpError { - fn from(response: Response) -> SmtpError { +impl From for Error { + fn from(response: Response) -> Error { match response.severity() { Severity::TransientNegativeCompletion => TransientError(response), Severity::PermanentNegativeCompletion => PermanentError(response), @@ -74,14 +74,14 @@ impl From for SmtpError { } } -impl From<&'static str> for SmtpError { - fn from(string: &'static str) -> SmtpError { +impl From<&'static str> for Error { + fn from(string: &'static str) -> Error { ClientError(string.to_string()) } } /// SMTP result type -pub type SmtpResult = Result; +pub type SmtpResult = Result; #[cfg(test)] mod test { diff --git a/src/response.rs b/src/response.rs index 7519f32..dbc154a 100644 --- a/src/response.rs +++ b/src/response.rs @@ -15,7 +15,7 @@ use std::result::Result as RResult; use self::Severity::*; use self::Category::*; -use error::{SmtpResult, SmtpError}; +use error::{SmtpResult, Error}; /// First digit indicates severity #[derive(PartialEq,Eq,Copy,Clone,Debug)] @@ -115,10 +115,10 @@ pub struct Code { } impl FromStr for Code { - type Err = SmtpError; + type Err = Error; #[inline] - fn from_str(s: &str) -> RResult { + fn from_str(s: &str) -> RResult { if s.len() == 3 { match (s[0..1].parse::(), s[1..2].parse::(), s[2..3].parse::()) { (Ok(severity), Ok(category), Ok(detail)) => Ok(Code {severity: severity, category: category, detail: detail}), @@ -166,7 +166,7 @@ impl ResponseParser { } /// Parses a line and return a `bool` indicating if there are more lines to come - pub fn read_line(&mut self, line: &str) -> RResult { + pub fn read_line(&mut self, line: &str) -> RResult { if line.len() < 3 { return Err(From::from("Could not parse reply code, line too short")); @@ -176,7 +176,6 @@ impl ResponseParser { self.code = Some(try!(line[0..3].parse::())); } else { if self.code.as_ref().unwrap().code() != line[0..3] { - println!("pouet"); return Err(From::from("Could not parse reply code")); } } @@ -238,12 +237,6 @@ impl Response { self.message.clone() } - /// Gets the first line beginning with the given string - /// TODO testing - pub fn get_line_beginning_with(&self, start: &str) -> Option { - self.message.iter().find(|&x| (*x).starts_with(start)).map(|s| s.to_string()) - } - /// Returns the severity (i.e. 1st digit) pub fn severity(&self) -> Severity { self.code.severity @@ -401,7 +394,6 @@ mod test { "SIZE 42".to_string(), "AUTH PLAIN CRAM-MD5".to_string()], } ); - } #[test] diff --git a/src/sender/mod.rs b/src/sender/mod.rs index f9ff9f0..c56dbda 100644 --- a/src/sender/mod.rs +++ b/src/sender/mod.rs @@ -14,7 +14,7 @@ use std::net::{SocketAddr, ToSocketAddrs}; use SMTP_PORT; use extension::Extension; -use error::{SmtpResult, SmtpError}; +use error::{SmtpResult, Error}; use sendable_email::SendableEmail; use sender::server_info::ServerInfo; use client::Client; @@ -183,7 +183,7 @@ impl Sender { }); }, Err(error) => match error { - SmtpError::PermanentError(ref response) if response.has_code(550) => { + Error::PermanentError(ref response) if response.has_code(550) => { match self.client.helo(&self.client_info.hello_name) { Ok(response) => {self.server_info = Some( ServerInfo{