InputStream mailAsStream =
session.getMaildrop().getMailAsStream(messageNumber);
try {
session.getThread().sendResponse(
"+OK " + scanListing.length + " octets");
DotTerminatedOutputStream dotTerminatedOutputStream =
new DotTerminatedOutputStream(session.getThread()
.getOutputStream());
ExtraDotOutputStream dotOutputStream =
new ExtraDotOutputStream(dotTerminatedOutputStream);
byte[] buffer = new byte[4096];
int cRead;
while (-1 != (cRead = mailAsStream.read(buffer))) {
dotOutputStream.write(buffer, 0, cRead);
}
dotOutputStream.flush();
dotTerminatedOutputStream.writeTerminatingSequence();
dotTerminatedOutputStream.flush();
logger.debug("Message sent");
} finally {
mailAsStream.close();
}
}