diff --git a/src/transport/smtp/response.rs b/src/transport/smtp/response.rs index 403162b..990a22c 100644 --- a/src/transport/smtp/response.rs +++ b/src/transport/smtp/response.rs @@ -132,6 +132,12 @@ impl Code { } } +impl From 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";