From 1600c4d157e64d7022f9401a53649c30d193cd45 Mon Sep 17 00:00:00 2001 From: Mroik Date: Tue, 7 Apr 2026 16:20:58 +0200 Subject: Add SMTP reply for unrecognized commands Signed-off-by: Mroik --- src/smtp.rs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'src/smtp.rs') diff --git a/src/smtp.rs b/src/smtp.rs index b77a0b6..6614897 100644 --- a/src/smtp.rs +++ b/src/smtp.rs @@ -61,7 +61,13 @@ impl SessionHandler { } log::debug!("Received '{}' from '{}'", buffer.trim(), self.addr); - let command = Command::try_from(buffer.as_str())?; + let command = match Command::try_from(buffer.as_str()) { + Err(_) => { + writer.write_all(Reply::InvalidCommand.to_string().as_bytes())?; + continue; + } + Ok(v) => v, + }; let res = self.apply(command).await?; writer.write_all(res.to_string().as_bytes())?; @@ -101,6 +107,7 @@ impl Default for SessionState { enum Reply { Ready(String), Completed(String), + InvalidCommand, } impl ToString for Reply { @@ -108,6 +115,7 @@ impl ToString for Reply { match self { Reply::Ready(hostname) => format!("220 {}", hostname), Reply::Completed(hostname) => format!("250 {}", hostname), + Reply::InvalidCommand => format!("500 Command not recognized"), } } } -- cgit v1.3