Package org.apache.james.protocols.pop3

Examples of org.apache.james.protocols.pop3.POP3Response


  {
    Logger logger = new POP3ProtocolLogger();

    POP3ProtocolHandlerChain chain = new POP3ProtocolHandlerChain(new AuthHandler(backend));

    server = new NettyServer(new POP3Protocol(chain, new POP3ServerConfig(), logger));
    server.setListenAddresses(new InetSocketAddress(Configurator.getPop3Port()));
    server.setMaxConcurrentConnections(Configurator.getPop3MaxConnections());
    server.setTimeout(POP3ServerConfig.CONNECTION_TIMEOUT);
    server.setUseExecutionHandler(true, 16);
    server.bind();
View Full Code Here


  public void start() throws Exception
  {
    Logger logger = new POP3ProtocolLogger();

    POP3ProtocolHandlerChain chain = new POP3ProtocolHandlerChain(new AuthHandler(backend));

    server = new NettyServer(new POP3Protocol(chain, new POP3ServerConfig(), logger));
    server.setListenAddresses(new InetSocketAddress(Configurator.getPop3Port()));
    server.setMaxConcurrentConnections(Configurator.getPop3MaxConnections());
    server.setTimeout(POP3ServerConfig.CONNECTION_TIMEOUT);
View Full Code Here

            try {
               
                MessageMetaData data = MessageMetaDataUtils.getMetaData(session, num);
                if (data == null) {
                    StringBuilder responseBuffer = new StringBuilder(64).append("Message (").append(num).append(") does not exist.");
                    return  new POP3Response(POP3Response.ERR_RESPONSE, responseBuffer.toString());
                }
               
                List<String> deletedUidList = (List<String>) session.getAttachment(POP3Session.DELETED_UID_LIST, State.Transaction);

                String uid = data.getUid();
                if (deletedUidList.contains(uid) == false) {

                    InputStream message = new CountingBodyInputStream(new ExtraDotInputStream(new CRLFTerminatedInputStream(session.getUserMailbox().getMessage(uid))), lines);
                    if (message != null) {
                        return new POP3StreamResponse(POP3Response.OK_RESPONSE, "Message follows", message);
                    } else {
                        StringBuilder exceptionBuffer = new StringBuilder(64).append("Message (").append(num).append(") does not exist.");
                        return new POP3Response(POP3Response.ERR_RESPONSE, exceptionBuffer.toString());
                    }

                } else {
                    StringBuilder responseBuffer = new StringBuilder(64).append("Message (").append(num).append(") already deleted.");
                    return new POP3Response(POP3Response.ERR_RESPONSE, responseBuffer.toString());
                }
            } catch (IOException ioe) {
                return ERROR_MESSAGE_RETR;
            } catch (IndexOutOfBoundsException iob) {
                StringBuilder exceptionBuffer = new StringBuilder(64).append("Message (").append(num).append(") does not exist.");
                return new POP3Response(POP3Response.ERR_RESPONSE, exceptionBuffer.toString());
            } catch (NoSuchElementException iob) {
                StringBuilder exceptionBuffer = new StringBuilder(64).append("Message (").append(num).append(") does not exist.");
                return new POP3Response(POP3Response.ERR_RESPONSE, exceptionBuffer.toString());
            }
        } else {
            return POP3Response.ERR;
        }
View Full Code Here

     * Handler method called upon receipt of a RETR command. This command
     * retrieves a particular mail message from the mailbox.
     */
    @SuppressWarnings("unchecked")
    public Response onCommand(POP3Session session, Request request) {
        POP3Response response = null;
        String parameters = request.getArgument();
        if (session.getHandlerState() == POP3Session.TRANSACTION) {
            int num = 0;
            try {
                num = Integer.parseInt(parameters.trim());
            } catch (Exception e) {
                return SYNTAX_ERROR;
            }
            try {
                MessageMetaData data = MessageMetaDataUtils.getMetaData(session, num);

                if (data == null) {
                    StringBuilder responseBuffer = new StringBuilder(64).append("Message (").append(num).append(") does not exist.");
                    response = new POP3Response(POP3Response.ERR_RESPONSE, responseBuffer.toString());
                    return response;
                }
                List<String> deletedUidList = (List<String>) session.getAttachment(POP3Session.DELETED_UID_LIST, State.Transaction);

                String uid = data.getUid();
                if (deletedUidList.contains(uid) == false) {
                    InputStream content = session.getUserMailbox().getMessage(uid);

                    if (content != null) {
                        InputStream in = new CRLFTerminatedInputStream(new ExtraDotInputStream(content));
                        response = new POP3StreamResponse(POP3Response.OK_RESPONSE, "Message follows", in);
                        return response;
                    } else {
                        StringBuilder responseBuffer = new StringBuilder(64).append("Message (").append(num).append(") does not exist.");
                        response = new POP3Response(POP3Response.ERR_RESPONSE, responseBuffer.toString());
                    }
                } else {
                    StringBuilder responseBuffer = new StringBuilder(64).append("Message (").append(num).append(") already deleted.");
                    response = new POP3Response(POP3Response.ERR_RESPONSE, responseBuffer.toString());
                }
            } catch (IOException ioe) {
                return ERROR_MESSAGE_RETRIEVE;
            }
        } else {
View Full Code Here

            }
            try {
                MessageMetaData meta = MessageMetaDataUtils.getMetaData(session, num);
                if (meta == null) {
                    StringBuilder responseBuffer = new StringBuilder(64).append("Message (").append(num).append(") does not exist.");
                    return  new POP3Response(POP3Response.ERR_RESPONSE, responseBuffer.toString());
                }
                List<String> deletedUidList = (List<String>) session.getAttachment(POP3Session.DELETED_UID_LIST, State.Transaction);

                String uid = meta.getUid();

                if (deletedUidList.contains(uid)) {
                    StringBuilder responseBuffer = new StringBuilder(64).append("Message (").append(num).append(") already deleted.");
                    return new POP3Response(POP3Response.ERR_RESPONSE, responseBuffer.toString());
                } else {
                    deletedUidList.add(uid);
                    // we are replacing our reference with "DELETED", so we have
                    // to dispose the no-more-referenced mail object.
                    return DELETED;
                }
            } catch (IndexOutOfBoundsException iob) {
                StringBuilder responseBuffer = new StringBuilder(64).append("Message (").append(num).append(") does not exist.");
                return  new POP3Response(POP3Response.ERR_RESPONSE, responseBuffer.toString());
            }
        } else {
            return POP3Response.ERR;
        }
    }
View Full Code Here

     * Handler method called upon receipt of a UIDL command. Returns a listing
     * of message ids to the client.
     */
    @SuppressWarnings("unchecked")
    public Response onCommand(POP3Session session, Request request) {
        POP3Response response = null;
        String parameters = request.getArgument();
        if (session.getHandlerState() == POP3Session.TRANSACTION) {
            List<MessageMetaData> uidList = (List<MessageMetaData>) session.getAttachment(POP3Session.UID_LIST, State.Transaction);
            List<String> deletedUidList = (List<String>) session.getAttachment(POP3Session.DELETED_UID_LIST, State.Transaction);
            try {
                String identifier = session.getUserMailbox().getIdentifier();
                if (parameters == null) {
                    response = new POP3Response(POP3Response.OK_RESPONSE, "unique-id listing follows");

                    for (int i = 0; i < uidList.size(); i++) {
                        MessageMetaData metadata = uidList.get(i);
                        if (deletedUidList.contains(metadata.getUid()) == false) {
                            StringBuilder responseBuffer = new StringBuilder().append(i + 1).append(" ").append(metadata.getUid(identifier));
                            response.appendLine(responseBuffer.toString());
                        }
                    }

                    response.appendLine(".");
                } else {
                    int num = 0;
                    try {
                        num = Integer.parseInt(parameters);
                       
                        MessageMetaData metadata = MessageMetaDataUtils.getMetaData(session, num);

                        if (metadata == null) {
                            StringBuilder responseBuffer = new StringBuilder(64).append("Message (").append(num).append(") does not exist.");
                            return  new POP3Response(POP3Response.ERR_RESPONSE, responseBuffer.toString());
                        }

                        if (deletedUidList.contains(metadata.getUid()) == false) {
                            StringBuilder responseBuffer = new StringBuilder(64).append(num).append(" ").append(metadata.getUid(identifier));
                            response = new POP3Response(POP3Response.OK_RESPONSE, responseBuffer.toString());
                        } else {
                            StringBuilder responseBuffer = new StringBuilder(64).append("Message (").append(num).append(") already deleted.");
                            response = new POP3Response(POP3Response.ERR_RESPONSE, responseBuffer.toString());
                        }
                    } catch (IndexOutOfBoundsException npe) {
                        StringBuilder responseBuffer = new StringBuilder(64).append("Message (").append(num).append(") does not exist.");
                        response = new POP3Response(POP3Response.ERR_RESPONSE, responseBuffer.toString());
                    } catch (NumberFormatException nfe) {
                        StringBuilder responseBuffer = new StringBuilder(64).append(parameters).append(" is not a valid number");
                        response = new POP3Response(POP3Response.ERR_RESPONSE, responseBuffer.toString());
                    }
                }
            } catch (IOException e) {
                return POP3Response.ERR;
            }
View Full Code Here

        String parameters = request.getArgument();
        List<MessageMetaData> uidList = (List<MessageMetaData>) session.getAttachment(POP3Session.UID_LIST, State.Transaction);
        List<String> deletedUidList = (List<String>) session.getAttachment(POP3Session.DELETED_UID_LIST, State.Transaction);

        if (session.getHandlerState() == POP3Session.TRANSACTION) {
            POP3Response response = null;

            if (parameters == null) {

                long size = 0;
                int count = 0;
                List<MessageMetaData> validResults = new ArrayList<MessageMetaData>();
                if (uidList.isEmpty() == false) {

                    for (int i = 0; i < uidList.size(); i++) {
                        MessageMetaData data = uidList.get(i);
                        if (deletedUidList.contains(data.getUid()) == false) {
                            size += data.getSize();
                            count++;
                            validResults.add(data);
                        }
                    }
                }
                StringBuilder responseBuffer = new StringBuilder(32).append(count).append(" ").append(size);
                response = new POP3Response(POP3Response.OK_RESPONSE, responseBuffer.toString());
                count = 0;
                for (int i = 0; i < validResults.size(); i++) {
                    responseBuffer = new StringBuilder(16).append(i + 1).append(" ").append(validResults.get(i).getSize());
                    response.appendLine(responseBuffer.toString());
                }
                response.appendLine(".");
            } else {
                int num = 0;
                try {
                    num = Integer.parseInt(parameters);
                   
                    MessageMetaData data = MessageMetaDataUtils.getMetaData(session, num);
                    if (data == null) {
                        StringBuilder responseBuffer = new StringBuilder(64).append("Message (").append(num).append(") does not exist.");
                        return  new POP3Response(POP3Response.ERR_RESPONSE, responseBuffer.toString());
                    }
                   
                    if (deletedUidList.contains(data.getUid()) == false) {
                        StringBuilder responseBuffer = new StringBuilder(64).append(num).append(" ").append(data.getSize());
                        response = new POP3Response(POP3Response.OK_RESPONSE, responseBuffer.toString());
                    } else {
                        StringBuilder responseBuffer = new StringBuilder(64).append("Message (").append(num).append(") already deleted.");
                        response = new POP3Response(POP3Response.ERR_RESPONSE, responseBuffer.toString());
                    }
                } catch (IndexOutOfBoundsException npe) {
                    StringBuilder responseBuffer = new StringBuilder(64).append("Message (").append(num).append(") does not exist.");
                    response = new POP3Response(POP3Response.ERR_RESPONSE, responseBuffer.toString());
                } catch (NumberFormatException nfe) {
                    StringBuilder responseBuffer = new StringBuilder(64).append(parameters).append(" is not a valid number");
                    response = new POP3Response(POP3Response.ERR_RESPONSE, responseBuffer.toString());
                }
            }
            return response;
        } else {
            return POP3Response.ERR;
View Full Code Here

        // store the timestamp for later usage
        session.setAttachment(POP3Session.APOP_TIMESTAMP, responseBuffer.toString(), State.Connection);
       
        // complete the response banner and send it back to the client
        responseBuffer.append("POP3 server (").append(session.getConfiguration().getSoftwareName()).append(") ready ");
        POP3Response response = new POP3Response(POP3Response.OK_RESPONSE, responseBuffer.toString());
        return response;
    }
View Full Code Here

                        validResults.add(data);
                    }
                }
            }
            StringBuilder responseBuffer = new StringBuilder(32).append(count).append(" ").append(size);
            return new POP3Response(POP3Response.OK_RESPONSE, responseBuffer.toString());

        } else {
            return POP3Response.ERR;
        }
    }
View Full Code Here

     *
     * @param argument the first argument parsed by the parseCommand method
     */

    public Response onCommand(POP3Session session, Request request) {
        POP3Response response = null;
        String parameters = request.getArgument();
       
        if (session.getHandlerState() == POP3Session.TRANSACTION) {
            Mail dm = (Mail) session.getState().get(POP3Session.DELETED);

            if (parameters == null) {

                long size = 0;
                int count = 0;

                try {

                    for (Mail mc:session.getUserMailbox()) {
                        if (mc != dm) {
                            size += mc.getMessageSize();
                            count++;
                        }
                    }
                    StringBuilder responseBuffer =
                        new StringBuilder(32)
                                .append(count)
                                .append(" ")
                                .append(size);
                    response = new POP3Response(POP3Response.OK_RESPONSE, responseBuffer.toString());
                    count = 0;
                    for (Mail mc:session.getUserMailbox()) {
                        if (mc != dm) {
                            responseBuffer =
                                new StringBuilder(16)
                                        .append(count)
                                        .append(" ")
                                        .append(mc.getMessageSize());
                            response.appendLine(responseBuffer.toString());
                        }
                        count++;
                    }
                    response.appendLine(".");
                } catch (MessagingException me) {
                    response = new POP3Response(POP3Response.ERR_RESPONSE);
                }
            } else {
                int num = 0;
                try {
                    num = Integer.parseInt(parameters);
                    int size =getMessageSize(session, num);
                    if (mc != dm) {
                        StringBuilder responseBuffer =
                            new StringBuilder(64)
                                    .append(num)
                                    .append(" ")
                                    .append(mc.getMessageSize());
                        response = new POP3Response(POP3Response.OK_RESPONSE, responseBuffer.toString());
                    } else {
                        StringBuilder responseBuffer =
                            new StringBuilder(64)
                                    .append("Message (")
                                    .append(num)
                                    .append(") already deleted.");
                        response = new POP3Response(POP3Response.ERR_RESPONSE, responseBuffer.toString());
                    }
                } catch (IndexOutOfBoundsException npe) {
                    StringBuilder responseBuffer =
                        new StringBuilder(64)
                                .append("Message (")
                                .append(num)
                                .append(") does not exist.");
                    response = new POP3Response(POP3Response.ERR_RESPONSE, responseBuffer.toString());
                } catch (NumberFormatException nfe) {
                    StringBuilder responseBuffer =
                        new StringBuilder(64)
                                .append(parameters)
                                .append(" is not a valid number");
                    response = new POP3Response(POP3Response.ERR_RESPONSE, responseBuffer.toString());
                } catch (MessagingException me) {
                    response = new POP3Response(POP3Response.ERR_RESPONSE);
                }
            }
        } else {
            response = new POP3Response(POP3Response.ERR_RESPONSE);
        }
        return response;
    }
View Full Code Here

TOP

Related Classes of org.apache.james.protocols.pop3.POP3Response

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.