Message messages[] = inbox.getMessages();
for (int i = 0; i < messages.length; i++) {
MimeMessageParser p = new MimeMessageParser(new MimeMessage(session, messages[i].getInputStream()));
Enumeration allHeaders = p.getMimeMessage().getAllHeaders();
while (allHeaders.hasMoreElements()) {
Object j = allHeaders.nextElement();
if (j instanceof javax.mail.Header) {
javax.mail.Header msg = (javax.mail.Header) j;
logger.info("XML as message header is " + msg.getValue());
if (msg.getValue().contains(contains)) {
//found it
messages[i].setFlag(Flags.Flag.DELETED, true);
found++;
}
}
}
for (int k = 0; k < p.getAttachmentList().size(); k++) {
InputStream is = p.getAttachmentList().get((k)).getInputStream();
QuotedPrintableCodec qp = new QuotedPrintableCodec();
// If "is" is not already buffered, wrap a BufferedInputStream
// around it.
if (!(is instanceof BufferedInputStream)) {
is = new BufferedInputStream(is);