* Handler method called upon receipt of a UIDL command. Returns a listing
* of message ids to the client.
*/
@SuppressWarnings("unchecked")
public Response onCommand(POP3Session session, Request request) {
POP3Response response = null;
String parameters = request.getArgument();
if (session.getHandlerState() == POP3Session.TRANSACTION) {
List<MessageMetaData> uidList = (List<MessageMetaData>) session.getState().get(POP3Session.UID_LIST);
List<Long> deletedUidList = (List<Long>) session.getState().get(POP3Session.DELETED_UID_LIST);
try {
String identifier = session.getUserMailbox().getIdentifier();
if (parameters == null) {
response = new POP3Response(POP3Response.OK_RESPONSE, "unique-id listing follows");
for (int i = 0; i < uidList.size(); i++) {
Long uid = uidList.get(i).getUid();
if (deletedUidList.contains(uid) == false) {
// construct unique UIDL. See JAMES-1264
StringBuilder responseBuffer = new StringBuilder(64).append(i + 1).append(" ").append(identifier).append("-").append(uid);
response.appendLine(responseBuffer.toString());
}
}
response.appendLine(".");
} else {
int num = 0;
try {
num = Integer.parseInt(parameters);
Long uid = uidList.get(num - 1).getUid();
if (deletedUidList.contains(uid) == false) {
// construct unique UIDL. See JAMES-1264
StringBuilder responseBuffer = new StringBuilder(64).append(num).append(" ").append(identifier).append("-").append(uid);
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());
}
} catch (IndexOutOfBoundsException npe) {
StringBuilder responseBuffer = new StringBuilder(64).append("Message (").append(num).append(") does not exist.");
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());
}
}
} catch (IOException e) {
response = new POP3Response(POP3Response.ERR_RESPONSE);
return response;
}
} else {
response = new POP3Response(POP3Response.ERR_RESPONSE);
}
return response;
}