* 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 {