InputStream is = gm.getResponseBodyAsStream(); MimeMessage mm = new MimeMessage(mJMSession, is); MimeMultipart mmp = (MimeMultipart)mm.getContent(); BodyPart bp = mmp.getBodyPart(1); Part msg = (Part) bp.getContent(); File file = new File(outdir, mOutputPrefix + "-" + n); OutputStream os = new BufferedOutputStream(new FileOutputStream(file)); msg.writeTo(os); os.close(); if (mLog.isInfoEnabled()) mLog.info("Wrote: " + file);
InputStream is = null; MimeMessage mm = null; try { is = gm.getResponseBodyAsStream(); mm = new MimeMessage(mJMSession, is); } finally { is.close(); }  if (!(mm.getContent() instanceof MimeMultipart)) { mLog.warn("Spam/notspam messages must have attachments (skipping " + gm.getPath() + ")"); return; } MimeMultipart mmp = (MimeMultipart)mm.getContent(); int nAttachments  = mmp.getCount(); boolean foundAtleastOneAttachedMessage = false; for (int i = 0; i < nAttachments; i++) { BodyPart bp = mmp.getBodyPart(i); if (!bp.getContentType().equalsIgnoreCase("message/rfc822")) {  continue; } foundAtleastOneAttachedMessage = true; Part msg = (Part) bp.getContent(); File file = new File(outdir, mOutputPrefix + "-" + mExtractIndex++); OutputStream os = null; try { os = new BufferedOutputStream(new FileOutputStream(file)); msg.writeTo(os); } finally { os.close(); } if (mVerbose) mLog.info("Wrote: " + file); }  if (!foundAtleastOneAttachedMessage) { String msgid = mm.getHeader("Message-ID", " "); mLog.warn("message uri=" + gm.getPath() + " message-id=" + msgid + " had no attachments"); }
    private static void extractMessage0(HttpClient hc, GetMethod gm, int n, String path, File outdir) throws HttpException, IOException, MessagingException {        gm.setPath(path);        if (mLog.isDebugEnabled()) mLog.debug("Fetching " + path);        hc.executeMethod(gm);        if (gm.getStatusCode() != HttpStatus.SC_OK) {            mLog.warn("Fetch status: " + gm.getStatusLine());        }        InputStream is = gm.getResponseBodyAsStream();        MimeMessage mm = new MimeMessage(mJMSession, is);        MimeMultipart mmp = (MimeMultipart)mm.getContent(); // multipart/mixed         BodyPart bp = mmp.getBodyPart(1); // message/rfc822 part        Part msg = (Part) bp.getContent(); // the actual message        File file = new File(outdir, mOutputPrefix + "-" + n);        OutputStream os = new BufferedOutputStream(new FileOutputStream(file));         msg.writeTo(os);        os.close();        if (mLog.isInfoEnabled()) mLog.info("Wrote: " + file);    }