Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/EmbeddedMail/EmbeddedSmtpServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,12 @@ public void OnClientConnect(ISocket clientSocket)
{
OnMessage = (msg) => _messages.Add(msg)
};
session.Start();

try {
session.Start();
} catch (Exception) {
session.WriteResponse("421 localhost error occured");
}

_sessions.Add(session);
}
Expand Down
9 changes: 5 additions & 4 deletions src/EmbeddedMail/ISmtpSession.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@ Encoding GetDefaultStreamWriterEncoding() {
* ReadLine returns `null` if the end of the input stream is reached
* https://docs.microsoft.com/en-us/dotnet/api/system.io.streamreader.readline
*/
break;
WriteResponse("421 localhost reached end of input stream while attempting to receive the next line from the client");
return;
}
var token = SmtpToken.FromLine(line, isMessageBody);

Expand All @@ -81,17 +82,17 @@ Encoding GetDefaultStreamWriterEncoding() {
var handler = ProtocolHandlers.HandlerFor(token);
if(handler.Handle(token, this) == ContinueProcessing.Stop)
{
break;
return;
}

isMessageBody = token.IsData && token.IsMessageBody;
}

SmtpLog.Warn("The socket closed unexpectedly");
}

public void Dispose()
{
WriteResponse("421 localhost Closing transmission channel");

_writer.Close();
_reader.Close();
}
Expand Down