void handleCommand() throws IOException { _currentLine = _conn.readLine(); if (_currentLine == null) { quit(); return; } String commandName = new StringTokenizer(_currentLine, " ").nextToken().toUpperCase(); Pop3Command command = _registry.getCommand(commandName); if (command == null) { _conn.println("-ERR Command not recognized"); return; } if (!command.isValidForState(_state)) { _conn.println("-ERR Command not valid for this state"); return; } command.execute(_conn, _state, _currentLine); }
public void run() { try { _conn = new Pop3Connection(this, _socket); _state = new Pop3State(_manager); _quitting = false; sendGreetings(); while (!_quitting) { handleCommand(); } _conn.close(); } catch (SocketTimeoutException ste) { _conn.println("421 Service shutting down and closing transmission channel"); } catch (Exception e) { e.printStackTrace(); } finally { try { _socket.close(); } catch (IOException ioe) { ioe.printStackTrace(); } } }
void sendGreetings() { _conn.println("+OK POP3 GreenMail Server ready"); }