diff options
Diffstat (limited to 'src')
| -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"), } } } |
