Add conversion from SMTP code to integer (#941)
This commit is contained in:
@@ -132,6 +132,12 @@ impl Code {
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Code> for u16 {
|
||||
fn from(code: Code) -> Self {
|
||||
code.detail as u16 + 10 * code.category as u16 + 100 * code.severity as u16
|
||||
}
|
||||
}
|
||||
|
||||
/// Contains an SMTP reply, with separated code and message
|
||||
///
|
||||
/// The text message is optional, only the code is mandatory
|
||||
@@ -317,6 +323,17 @@ mod test {
|
||||
assert_eq!(code.to_string(), "421");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_code_to_u16() {
|
||||
let code = Code {
|
||||
severity: Severity::TransientNegativeCompletion,
|
||||
category: Category::Connections,
|
||||
detail: Detail::One,
|
||||
};
|
||||
let c: u16 = code.into();
|
||||
assert_eq!(c, 421);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_response_from_str() {
|
||||
let raw_response = "250-me\r\n250-8BITMIME\r\n250-SIZE 42\r\n250 AUTH PLAIN CRAM-MD5\r\n";
|
||||
|
||||
Reference in New Issue
Block a user