Long uid = uidList.get(num - 1);
if (deletedUidList.contains(uid) == false) {
FetchGroupImpl fetchGroup = new FetchGroupImpl(FetchGroup.BODY_CONTENT);
fetchGroup.or(FetchGroup.HEADERS);
Iterator<MessageResult> results = session.getUserMailbox().getMessages(MessageRange.one(uid), fetchGroup, mailboxSession);
MessageStream stream = new MessageStream();
OutputStream out = stream.getOutputStream();
OutputStream extraDotOut = new ExtraDotOutputStream(out);
out.write((POP3Response.OK_RESPONSE + " Message follows\r\n").getBytes());
out.flush();
// response = new POP3Response(POP3Response.OK_RESPONSE,
// "Message follows");
try {
MessageResult result = results.next();
WritableByteChannel outChannel = Channels.newChannel(extraDotOut);
// write headers
Iterator<Header> headers = result.headers();
while (headers.hasNext()) {
headers.next().writeTo(outChannel);
// we need to write out the CRLF after each header
extraDotOut.write("\r\n".getBytes());
}
// headers and body are seperated by a CRLF
extraDotOut.write("\r\n".getBytes());
// write body
result.getBody().writeTo(Channels.newChannel(new CountingBodyOutputStream(extraDotOut, lines)));
} finally {
extraDotOut.flush();
// write a single dot to mark message as complete
out.write((".\r\n").getBytes());
out.flush();
extraDotOut.close();
out.close();
}
session.writeStream(stream.getInputStream());
return null;
} else {
StringBuilder responseBuffer = new StringBuilder(64).append("Message (").append(num).append(") already deleted.");