/** * Implements a "stat". If the handler is currently in a transaction state, * this amounts to a rollback of the mailbox contents to the beginning of * the transaction. This method is also called when first entering the * transaction state to initialize the handler copies of the user inbox. */ protected void stat(POP3Session session) { try { List<MessageMetaData> messages = session.getUserMailbox().getMessages(); session.setAttachment(POP3Session.UID_LIST, messages, State.Transaction); session.setAttachment(POP3Session.DELETED_UID_LIST, new ArrayList<String>(), State.Transaction); } catch (IOException e) { // In the event of an exception being thrown there may or may not be // anything in userMailbox LOGGER.error("Unable to STAT mail box ", e); } }
/** * Handler method called upon receipt of a QUIT command. This method handles * cleanup of the POP3Handler state. */ @Override @SuppressWarnings("unchecked") public Response onCommand(POP3Session session, Request request) { Response response = null; if (session.getHandlerState() == POP3Session.AUTHENTICATION_READY || session.getHandlerState() == POP3Session.AUTHENTICATION_USERSET) { return SIGN_OFF; } List<String> toBeRemoved = (List<String>) session.getAttachment(POP3Session.DELETED_UID_LIST, State.Transaction); Mailbox mailbox = session.getUserMailbox(); try { String[] uids = toBeRemoved.toArray(new String[toBeRemoved.size()]); mailbox.remove(uids); response = SIGN_OFF; } catch (Exception ex) { response = SIGN_OFF_NOT_CLEAN; LOGGER.error("Some deleted messages were not removed", ex); } try { mailbox.close(); } catch (IOException e) { // ignore on close } return response; }
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");
InputStream content = session.getUserMailbox().getMessage(uid);
if (deletedUidList.contains(uid) == false) { InputStream message = new CountingBodyInputStream(new ExtraDotInputStream(new CRLFTerminatedInputStream(session.getUserMailbox().getMessage(uid))), lines); return new POP3StreamResponse(POP3Response.OK_RESPONSE, "Message follows", message);