Skip to content

Commit

Permalink
Merge pull request #310 from gessnerfl/bugfix/199_fix_missing_exit_wh…
Browse files Browse the repository at this point in the history
…en_client_stops_sending_data

#199: fix command loop to terminate when no data is sent by client
  • Loading branch information
gessnerfl authored Oct 16, 2023
2 parents 2749d1f + 69d9b8c commit 76e5d31
Showing 1 changed file with 23 additions and 26 deletions.
49 changes: 23 additions & 26 deletions src/main/java/de/gessnerfl/fakesmtp/smtp/server/Session.java
Original file line number Diff line number Diff line change
Expand Up @@ -212,33 +212,30 @@ private void runCommandLoop() throws IOException {
this.sendResponse("220 " + this.server.getHostName() + " ESMTP " + this.server.getSoftwareName());

while (!this.quitting) {
onCommandLoop();
}
}

private void onCommandLoop() throws IOException {
try {
Optional<String> line = readCommandLine();
if (line.isPresent()) {
LOGGER.debug("Client: {}", line);
this.server.getCommandHandler().handleCommand(this, line.get());
} else {
LOGGER.debug("no more lines from client");
try {
Optional<String> line = readCommandLine();
if (line.isPresent()) {
LOGGER.debug("Client: {}", line);
this.server.getCommandHandler().handleCommand(this, line.get());
} else {
LOGGER.debug("no more lines from client");
return;
}
} catch (final SocketTimeoutException ex) {
this.sendResponse("421 Timeout waiting for data from client.");
} catch (final CRLFTerminatedReader.TerminationException te) {
final String msg = "501 Syntax error at character position "
+ te.position()
+ ". CR and LF must be CRLF paired. See RFC 2821 #2.7.1.";

LOGGER.debug(msg);
this.sendResponse(msg);
} catch (final CRLFTerminatedReader.MaxLineLengthException mlle) {
final String msg = "501 " + mlle.getMessage();

LOGGER.debug(msg);
this.sendResponse(msg);
}
} catch (final SocketTimeoutException ex) {
this.sendResponse("421 Timeout waiting for data from client.");
} catch (final CRLFTerminatedReader.TerminationException te) {
final String msg = "501 Syntax error at character position "
+ te.position()
+ ". CR and LF must be CRLF paired. See RFC 2821 #2.7.1.";

LOGGER.debug(msg);
this.sendResponse(msg);
} catch (final CRLFTerminatedReader.MaxLineLengthException mlle) {
final String msg = "501 " + mlle.getMessage();

LOGGER.debug(msg);
this.sendResponse(msg);
}
}

Expand Down

0 comments on commit 76e5d31

Please sign in to comment.