diff options
| author | Mroik <mroik@delayed.space> | 2026-04-07 16:20:58 +0200 |
|---|---|---|
| committer | Mroik <mroik@delayed.space> | 2026-04-13 06:56:10 +0200 |
| commit | 1600c4d157e64d7022f9401a53649c30d193cd45 (patch) | |
| tree | 8d82771e73b30651e4ef6f693c02c003181f172d | |
| parent | 24cee3a3bc44a758d5fdfdf5d32df82a97afdd97 (diff) | |
Add SMTP reply for unrecognized commands
Signed-off-by: Mroik <mroik@delayed.space>
| -rw-r--r-- | src/smtp.rs | 10 |
1 files changed, 9 insertions, 1 deletions
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"), } } } |
