diff --git a/src/main/java/de/gessnerfl/fakesmtp/smtp/server/Session.java b/src/main/java/de/gessnerfl/fakesmtp/smtp/server/Session.java index 2f1733b7..4906b3ed 100644 --- a/src/main/java/de/gessnerfl/fakesmtp/smtp/server/Session.java +++ b/src/main/java/de/gessnerfl/fakesmtp/smtp/server/Session.java @@ -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 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 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); } }