@Override public Response onConnect(POP3Session session) { StringBuilder responseBuffer = new StringBuilder(); // Generate the timestamp which can be also used with APOP. See RFC1939 APOP responseBuffer.append("<").append(session.getSessionID()).append(".").append(System.currentTimeMillis()).append("@").append(session.getConfiguration().getHelloName()).append("> "); // 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 "); return new POP3Response(POP3Response.OK_RESPONSE, responseBuffer.toString()); }
if (meta == null) { StringBuilder responseBuffer = new StringBuilder(64).append("Message (").append(num).append(") does not exist."); return new POP3Response(POP3Response.ERR_RESPONSE, responseBuffer.toString()); return new POP3Response(POP3Response.ERR_RESPONSE, responseBuffer.toString()); } else { deletedUidList.add(uid); return new POP3Response(POP3Response.ERR_RESPONSE, responseBuffer.toString());
/** * Handler method called upon receipt of a STAT command. Returns the number * of messages in the mailbox and its aggregate size. */ @Override @SuppressWarnings("unchecked") public Response onCommand(POP3Session session, Request request) { 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); long size = 0; int count = 0; if (uidList.isEmpty() == false) { List<MessageMetaData> validResults = new ArrayList<>(); for (MessageMetaData data : uidList) { if (deletedUidList.contains(data.getUid()) == false) { size += data.getSize(); count++; 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; } }
@Override public Response onCommand(POP3Session session, Request request) { POP3Response response = new POP3Response(POP3Response.OK_RESPONSE, "Capability list follows"); for (CapaCapability capabilities : caps) { for (String cap : capabilities.getImplementedCapabilities(session)) { response.appendLine(cap); } } response.appendLine("."); return response; }
String identifier = session.getUserMailbox().getIdentifier(); if (parameters == null) { response = new POP3Response(POP3Response.OK_RESPONSE, "unique-id listing follows"); return new POP3Response(POP3Response.ERR_RESPONSE, responseBuffer.toString()); 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()); 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());
response = new POP3Response(POP3Response.OK_RESPONSE, responseBuffer.toString()); count = 0; for (int i = 0; i < validResults.size(); i++) { if (data == null) { StringBuilder responseBuffer = new StringBuilder(64).append("Message (").append(num).append(") does not exist."); return new POP3Response(POP3Response.ERR_RESPONSE, responseBuffer.toString()); 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()); 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());
response = new POP3Response(POP3Response.ERR_RESPONSE, responseBuffer.toString()); return response; } else { StringBuilder responseBuffer = new StringBuilder(64).append("Message (").append(num).append(") does not exist."); response = new POP3Response(POP3Response.ERR_RESPONSE, responseBuffer.toString()); response = new POP3Response(POP3Response.ERR_RESPONSE, responseBuffer.toString());
if (data == null) { StringBuilder responseBuffer = new StringBuilder(64).append("Message (").append(num).append(") does not exist."); return new POP3Response(POP3Response.ERR_RESPONSE, responseBuffer.toString()); return new POP3Response(POP3Response.ERR_RESPONSE, responseBuffer.toString()); } catch (IndexOutOfBoundsException | NoSuchElementException iob) { StringBuilder exceptionBuffer = new StringBuilder(64).append("Message (").append(num).append(") does not exist."); return new POP3Response(POP3Response.ERR_RESPONSE, exceptionBuffer.toString());
/** * Authenticate a user and return the {@link Response} * * @param session * @param user * @param pass * @return response */ protected final Response doAuth(POP3Session session, String user, String pass) { try { Mailbox mailbox = auth(session, user, pass); if (mailbox != null) { session.setUserMailbox(mailbox); stat(session); session.setHandlerState(POP3Session.TRANSACTION); StringBuilder responseBuffer = new StringBuilder(64).append("Welcome ").append(session.getUser()); return new POP3Response(POP3Response.OK_RESPONSE, responseBuffer.toString()); } else { session.setHandlerState(POP3Session.AUTHENTICATION_READY); return AUTH_FAILED; } } catch (Exception e) { LOGGER.error("Unexpected error accessing mailbox for {}", session.getUser(), e); session.setHandlerState(POP3Session.AUTHENTICATION_READY); return UNEXPECTED_ERROR; } }