@Override public void run() { // Closed automatically when socket is closed via #close() try (InputStream ins = new BufferedInputStream(socket.getInputStream(), 512); OutputStream outs = new BufferedOutputStream(socket.getOutputStream(), 1024) ) { response = new ImapResponse(outs); // Write welcome message String responseBuffer = VERSION + " Server GreenMail v" + BuildInfo.INSTANCE.getProjectVersion() + " ready"; response.okResponse(null, responseBuffer); session = new ImapSessionImpl(imapHost, userManager, this, socket.getInetAddress().getHostAddress()); while (requestHandler.handleRequest(ins, outs, session)) { // Loop ... } } catch (Exception e) { log.error("Can not handle IMAP connection", e); throw new IllegalStateException("Can not handle IMAP connection", e); } finally { close(); } }
/** * This method parses POP3 commands read off the wire in handleConnection. * Actual processing of the command (possibly including additional back and * forth communication with the client) is delegated to one of a number of * command specific handler methods. The primary purpose of this method is * to parse the raw command string to determine exactly which handler should * be called. It returns true if expecting additional commands, false otherwise. * * @return whether additional commands are expected. */ public boolean handleRequest(InputStream input, OutputStream output, ImapSession session) throws ProtocolException { ImapRequestLineReader request = new ImapRequestLineReader(input, output); try { request.nextChar(); } catch (ProtocolException e) { return false; } ImapResponse response = new ImapResponse(output); doProcessRequest(request, response, session); // Consume the rest of the line, throwing away any extras. This allows us // to clean up after a protocol error. request.consumeLine(); return true; }