public String readLine() throws Exception { if (!isReadLast) { handler.handleRequest(in, out, session); isReadLast = true; } final String result = out.nextLine(); return result; }
if (isSelectedMailboxDeleted(session)) { writeSignoff(output, session); result = false; } else { } catch (DecodingException e) { logger.debug("Unexpected end of line. Cannot handle request: ", e); abandon(output, session); return false; if (doProcessRequest(request, response, session)) { abandon(output, session); return false; logger.debug("Connection was abandoned after request processing failed."); result = false; abandon(output, session);
public Session(Continuation continuation) { out = new ByteBufferOutputStream(continuation); in = new ByteBufferInputStream(); handler = new ImapRequestStreamHandler(decoder, processor, encoder); session = new ImapSessionImpl(); session.setLog(new SilentLog()); }
public ChannelPipeline getPipeline() throws Exception { ChannelPipeline pipeline = pipeline(); pipeline.addLast("groupHandler", groupHandler); pipeline.addLast("timeoutHandler", new TimeoutHandler(timer, TIMEOUT)); pipeline.addLast("connectionLimit", new ConnectionLimitUpstreamHandler(IMAPServer.this.connectionLimit)); pipeline.addLast("connectionPerIpLimit", new ConnectionPerIpLimitUpstreamHandler(IMAPServer.this.connPerIP)); if (isSSLSocket()) { // We need to set clientMode to false. // See https://issues.apache.org/jira/browse/JAMES-1025 SSLEngine engine = getSSLContext().createSSLEngine(); engine.setUseClientMode(false); pipeline.addFirst("sslHandler", new SslHandler(engine)); } pipeline.addLast("connectionCountHandler", countHandler); final ImapRequestStreamHandler handler = new ImapRequestStreamHandler(decoder, processor, encoder); if (isStartTLSSupported()) { pipeline.addLast("coreHandler", new ImapStreamChannelUpstreamHandler(hello, handler, getLogger(), IMAPServer.this.getTimeout(), getSSLContext().createSSLEngine())); } else { pipeline.addLast("coreHandler", new ImapStreamChannelUpstreamHandler(hello, handler, getLogger(), IMAPServer.this.getTimeout())); } return pipeline; }
@Override protected void processStreamIo(final ChannelHandlerContext ctx, final InputStream in, final OutputStream out) { final ImapSessionImpl imapSession = (ImapSessionImpl) getAttachment(ctx).get(IMAP_SESSION); Channel channel = ctx.getChannel(); // Store the stream as attachment OutputStream bufferedOut = new StartTLSOutputStream(out); getAttachment(ctx).put(BUFFERED_OUT, bufferedOut); // handle requests in a loop while (channel.isConnected() && handler.handleRequest(in, bufferedOut, imapSession)); if (imapSession != null) imapSession.logout(); logger.debug("Thread execution complete for session " + channel.getId()); channel.close(); }