* Handler method called upon receipt of a RETR command. This command
* retrieves a particular mail message from the mailbox.
*
*/
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) {
response = new POP3Response(POP3Response.ERR_RESPONSE,
"Usage: RETR [mail number]");
return response;
}
try {
InputStream msgIn = getMessageInputstream(session, num);
response = new POP3Response(POP3Response.OK_RESPONSE,
"Message follows");
try {
// write the full mail to the client
writeMessageContentTo(msgIn, response, -1);
} finally {
response.appendLine(".");
}
return response;
} catch (IOException ioe) {
response = new POP3Response(POP3Response.ERR_RESPONSE,
"Error while retrieving message.");
} catch (POP3Exception me) {
response = new POP3Response(POP3Response.ERR_RESPONSE,
"Error while retrieving message.");
} catch (IndexOutOfBoundsException iob) {
StringBuilder responseBuffer = new StringBuilder(64).append(
"Message (").append(num).append(") does not exist.");
response = new POP3Response(POP3Response.ERR_RESPONSE,
responseBuffer.toString());
}
} else {
response = new POP3Response(POP3Response.ERR_RESPONSE);
}
return response;
}