Merge pull request #161 from amousset/interface-response
feat(transport): Avoid useless methods in response and code
This commit is contained in:
@@ -85,7 +85,7 @@ impl From<io::Error> for Error {
|
||||
|
||||
impl From<Response> for Error {
|
||||
fn from(response: Response) -> Error {
|
||||
match response.severity() {
|
||||
match response.code.severity {
|
||||
Severity::TransientNegativeCompletion => Transient(response),
|
||||
Severity::PermanentNegativeCompletion => Permanent(response),
|
||||
_ => Client("Unknown error code"),
|
||||
|
||||
@@ -105,7 +105,7 @@ impl ServerInfo {
|
||||
|
||||
let mut features: HashSet<Extension> = HashSet::new();
|
||||
|
||||
for line in response.message() {
|
||||
for line in response.message.as_slice() {
|
||||
let splitted: Vec<&str> = line.split_whitespace().collect();
|
||||
match splitted[0] {
|
||||
"8BITMIME" => {
|
||||
|
||||
@@ -534,7 +534,7 @@ impl EmailTransport<SmtpResult> for SmtpTransport {
|
||||
.as_ref()
|
||||
.ok()
|
||||
.unwrap()
|
||||
.message()
|
||||
.message
|
||||
.iter()
|
||||
.next()
|
||||
.unwrap_or(&"no response".to_string())
|
||||
|
||||
@@ -128,11 +128,11 @@ impl Display for Detail {
|
||||
#[derive(PartialEq, Eq, Copy, Clone, Debug)]
|
||||
pub struct Code {
|
||||
/// First digit of the response code
|
||||
severity: Severity,
|
||||
pub severity: Severity,
|
||||
/// Second digit of the response code
|
||||
category: Category,
|
||||
pub category: Category,
|
||||
/// Third digit
|
||||
detail: Detail,
|
||||
pub detail: Detail,
|
||||
}
|
||||
|
||||
impl Display for Code {
|
||||
@@ -244,10 +244,10 @@ impl ResponseParser {
|
||||
#[derive(PartialEq, Eq, Clone, Debug)]
|
||||
pub struct Response {
|
||||
/// Response code
|
||||
code: Code,
|
||||
pub code: Code,
|
||||
/// Server response string (optional)
|
||||
/// Handle multiline responses
|
||||
message: Vec<String>,
|
||||
pub message: Vec<String>,
|
||||
}
|
||||
|
||||
impl Response {
|
||||
@@ -267,31 +267,6 @@ impl Response {
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns the message
|
||||
pub fn message(&self) -> Vec<String> {
|
||||
self.message.clone()
|
||||
}
|
||||
|
||||
/// Returns the response code
|
||||
pub fn code(&self) -> Code {
|
||||
self.code
|
||||
}
|
||||
|
||||
/// Returns the severity (i.e. 1st digit)
|
||||
pub fn severity(&self) -> Severity {
|
||||
self.code.severity
|
||||
}
|
||||
|
||||
/// Returns the category (i.e. 2nd digit)
|
||||
pub fn category(&self) -> Category {
|
||||
self.code.category
|
||||
}
|
||||
|
||||
/// Returns the detail (i.e. 3rd digit)
|
||||
pub fn detail(&self) -> Detail {
|
||||
self.code.detail
|
||||
}
|
||||
|
||||
/// Tests code equality
|
||||
pub fn has_code(&self, code: u16) -> bool {
|
||||
self.code.to_string() == format!("{}", code)
|
||||
@@ -507,133 +482,6 @@ mod test {
|
||||
).is_positive());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_response_message() {
|
||||
assert_eq!(
|
||||
Response::new(
|
||||
Code {
|
||||
severity: "2".parse::<Severity>().unwrap(),
|
||||
category: "3".parse::<Category>().unwrap(),
|
||||
detail: "1".parse::<Detail>().unwrap(),
|
||||
},
|
||||
vec![
|
||||
"me".to_string(),
|
||||
"8BITMIME".to_string(),
|
||||
"SIZE 42".to_string(),
|
||||
],
|
||||
).message(),
|
||||
vec![
|
||||
"me".to_string(),
|
||||
"8BITMIME".to_string(),
|
||||
"SIZE 42".to_string(),
|
||||
]
|
||||
);
|
||||
let empty_message: Vec<String> = vec![];
|
||||
assert_eq!(
|
||||
Response::new(
|
||||
Code {
|
||||
severity: "2".parse::<Severity>().unwrap(),
|
||||
category: "3".parse::<Category>().unwrap(),
|
||||
detail: "1".parse::<Detail>().unwrap(),
|
||||
},
|
||||
vec![],
|
||||
).message(),
|
||||
empty_message
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_response_severity() {
|
||||
assert_eq!(
|
||||
Response::new(
|
||||
Code {
|
||||
severity: "2".parse::<Severity>().unwrap(),
|
||||
category: "3".parse::<Category>().unwrap(),
|
||||
detail: "1".parse::<Detail>().unwrap(),
|
||||
},
|
||||
vec![
|
||||
"me".to_string(),
|
||||
"8BITMIME".to_string(),
|
||||
"SIZE 42".to_string(),
|
||||
],
|
||||
).severity(),
|
||||
Severity::PositiveCompletion
|
||||
);
|
||||
assert_eq!(
|
||||
Response::new(
|
||||
Code {
|
||||
severity: "5".parse::<Severity>().unwrap(),
|
||||
category: "3".parse::<Category>().unwrap(),
|
||||
detail: "1".parse::<Detail>().unwrap(),
|
||||
},
|
||||
vec![
|
||||
"me".to_string(),
|
||||
"8BITMIME".to_string(),
|
||||
"SIZE 42".to_string(),
|
||||
],
|
||||
).severity(),
|
||||
Severity::PermanentNegativeCompletion
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_response_category() {
|
||||
assert_eq!(
|
||||
Response::new(
|
||||
Code {
|
||||
severity: "2".parse::<Severity>().unwrap(),
|
||||
category: "4".parse::<Category>().unwrap(),
|
||||
detail: "1".parse::<Detail>().unwrap(),
|
||||
},
|
||||
vec![
|
||||
"me".to_string(),
|
||||
"8BITMIME".to_string(),
|
||||
"SIZE 42".to_string(),
|
||||
],
|
||||
).category(),
|
||||
Category::Unspecified4
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_response_detail() {
|
||||
assert_eq!(
|
||||
Response::new(
|
||||
Code {
|
||||
severity: "2".parse::<Severity>().unwrap(),
|
||||
category: "3".parse::<Category>().unwrap(),
|
||||
detail: "1".parse::<Detail>().unwrap(),
|
||||
},
|
||||
vec![
|
||||
"me".to_string(),
|
||||
"8BITMIME".to_string(),
|
||||
"SIZE 42".to_string(),
|
||||
],
|
||||
).detail(),
|
||||
Detail(1)
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_response_code() {
|
||||
assert_eq!(
|
||||
Response::new(
|
||||
Code {
|
||||
severity: "2".parse::<Severity>().unwrap(),
|
||||
category: "4".parse::<Category>().unwrap(),
|
||||
detail: "1".parse::<Detail>().unwrap(),
|
||||
},
|
||||
vec![
|
||||
"me".to_string(),
|
||||
"8BITMIME".to_string(),
|
||||
"SIZE 42".to_string(),
|
||||
],
|
||||
).code()
|
||||
.to_string(),
|
||||
"241"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_response_has_code() {
|
||||
assert!(
|
||||
|
||||
Reference in New Issue
Block a user