@Test void onCommandShouldNotThrowOnMessageDecNumberOverflow() { POP3Session session = mock(POP3Session.class); when(session.getHandlerState()).thenReturn(POP3Session.TRANSACTION); Request request = mock(Request.class); String overflowedNumber = Long.toString(Long.MAX_VALUE); when(request.getArgument()).thenReturn(overflowedNumber); assertThat(new RetrCmdHandler().onCommand(session, request)) .isEqualTo(RetrCmdHandler.SYNTAX_ERROR); }
@Override @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 = session.getAttachment(POP3Session.DELETED_UID_LIST, State.Transaction).orElse(ImmutableList.of()); String uid = data.getUid(); if (!deletedUidList.contains(uid)) { 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 { return POP3Response.ERR; } return response; }
RetrCmdHandler implements CommandHandler<POP3Session> { @Override @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 = session.getAttachment(POP3Session.DELETED_UID_LIST, State.Transaction).orElse(ImmutableList.of()); String uid = data.getUid(); if (!deletedUidList.contains(uid)) { 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 { return POP3Response.ERR; } return response; } }
RetrCmdHandler implements CommandHandler<POP3Session> { @Override @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 = session.getAttachment(POP3Session.DELETED_UID_LIST, State.Transaction).orElse(ImmutableList.of()); String uid = data.getUid(); if (!deletedUidList.contains(uid)) { 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 { return POP3Response.ERR; } return response; }  }
RetrCmdHandler implements CommandHandler<POP3Session> { @Override @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 = session.getAttachment(POP3Session.DELETED_UID_LIST, State.Transaction).orElse(ImmutableList.of()); String uid = data.getUid(); if (!deletedUidList.contains(uid)) { 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 { return POP3Response.ERR; } return response; }  @Override @SuppressWarnings("unchecked") Response onCommand(POP3Session session, Request request); @Override Collection<String> getImplCommands(); }
RetrCmdHandler implements CommandHandler<POP3Session> { @Override @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 = session.getAttachment(POP3Session.DELETED_UID_LIST, State.Transaction).orElse(ImmutableList.of()); String uid = data.getUid(); if (!deletedUidList.contains(uid)) { 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 { return POP3Response.ERR; } return response; }  @Override @SuppressWarnings("unchecked") Response onCommand(POP3Session session, Request request); @Override Collection<String> getImplCommands();  }