* 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.getAttachment(POP3Session.UID_LIST, State.Transaction);
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");
for (int i = 0; i < uidList.size(); i++) {
MessageMetaData metadata = uidList.get(i);
if (deletedUidList.contains(metadata.getUid()) == false) {
StringBuilder responseBuffer = new StringBuilder().append(i + 1).append(" ").append(metadata.getUid(identifier));
response.appendLine(responseBuffer.toString());
}
}
response.appendLine(".");
} else {
int num = 0;
try {
num = Integer.parseInt(parameters);
MessageMetaData metadata = MessageMetaDataUtils.getMetaData(session, num);
if (metadata == null) {
StringBuilder responseBuffer = new StringBuilder(64).append("Message (").append(num).append(") does not exist.");
return new POP3Response(POP3Response.ERR_RESPONSE, responseBuffer.toString());
}
if (deletedUidList.contains(metadata.getUid()) == false) {
StringBuilder responseBuffer = new StringBuilder(64).append(num).append(" ").append(metadata.getUid(identifier));
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) {
return POP3Response.ERR;
}