code: private List<SmtpMessage> handleTransaction(PrintWriter out, BufferedReader input) throws IOException {
  		// Initialize the state machine
  		SmtpState smtpState = SmtpState.CONNECT;
  		SmtpRequest smtpRequest = new SmtpRequest(SmtpActionType.CONNECT, "", smtpState);
  
  		// Execute the connection request
  		SmtpResponse smtpResponse = smtpRequest.execute();
  
  		// Send initial response
  		sendResponse(out, smtpResponse);
  		smtpState = smtpResponse.getNextState();
  
  		List<SmtpMessage> msgList = new ArrayList<>();
  		SmtpMessage msg = new SmtpMessage();
  
  		while (smtpState != SmtpState.CONNECT) {
  			String line = input.readLine();
  
  			if (line == null) {
  				break;
  			}
  
  			// Create request from client input and current state
  			SmtpRequest request = SmtpRequest.createRequest(line, smtpState);
  			// Execute request and create response object
  			SmtpResponse response = request.execute();
  			// Move to next internal state
  			smtpState = response.getNextState();
  			// Send response to client
  			sendResponse(out, response);
  
  			// Store input in message
  			String params = request.getParams();
  			msg.store(response, params);
  
  			// If message reception is complete save it
  			if (smtpState == SmtpState.QUIT) {
  				msgList.add(msg);
  				msg = new SmtpMessage();
  			}
  		}
  
  		return msgList;
  	}
docs: Handle an SMTP transaction, i.e. all activity between initial connect and QUIT command.
  
  @param out output stream
  @param input input stream
  @return List of SmtpMessage