Object content = mp.getContent(); if (content instanceof InputStream) try { content = new MimeMultipart(new InputStreamDataSource((InputStream) content, cts)); } catch (Exception e) { mLog.info("Mime.accept(): Unable to parse multipart InputStream", e); }
Object content = getMultipartContent(mp, cts);
    public static void accept(MimeVisitor visitor, MimePart mp)    throws IOException, MessagingException {        if (mp instanceof MimeMessage) {            visitor.visitMessage((MimeMessage) mp, MimeVisitor.VISIT_BEGIN);        }        String cts = mp.getContentType();        if (cts == null)            cts = CT_DEFAULT;        else {            // only use "type/subtype"            // This is a workaround for messages sent by some broken mailers            // that generate an invalid content type string which causes            // JavaMail ParseException.  The broken mailer that necessitated            // this hack is "X-Mailer: Balsa 2.0.17", which generated            // Content-Type of "Content-Type:   text/plain; charset=US-ASCII;\r\n"            // "\tFormat=Flowed   DelSp=Yes\r\n".  Notice it is missing ';' after            // "Flowed".            int semicolon = cts.indexOf(';');            if (semicolon != -1)                cts = cts.substring(0, semicolon);            // Some mailers don't specify subtype at all, e.g. "Content-Type: text"            // Special case "text" to "text/plain".            if (cts.equals("text"))                cts = CT_TEXT_PLAIN;        }        ContentType ct = null;        try {            ct = new ContentType(cts.toLowerCase());            cts = ct.getPrimaryType() + "/" + ct.getSubType();        } catch (ParseException e) {            if (mLog.isInfoEnabled())                mLog.info("Unrecognized Content-Type " + cts + "; assuming " + CT_DEFAULT);            ct = new ContentType(CT_DEFAULT);        }                boolean isMultipart = ct.match(CT_MULTIPART_WILD);        boolean isMessage = !isMultipart && ct.match(CT_MESSAGE_RFC822);                if (isMultipart) {            // handle unparsed content due to miscapitalization of content-type value            Object content = mp.getContent();            if (content instanceof InputStream)                try {                    content = new MimeMultipart(new InputStreamDataSource((InputStream) content, cts));                } catch (Exception e) {                    mLog.info("Mime.accept(): Unable to parse multipart InputStream", e);                }            if (content instanceof MimeMultipart) {                MimeMultipart multi = (MimeMultipart) content;                visitor.visitMultipart(multi, MimeVisitor.VISIT_BEGIN);                                // Make a copy of the parts array and iterate the copy,                // in case the visitor is adding or removing parts.                List parts = new ArrayList();                for (int i = 0; i < multi.getCount(); i++) {                    parts.add(multi.getBodyPart(i));                }                Iterator i = parts.iterator();                while (i.hasNext()) {                    BodyPart bodyPart = (BodyPart) i.next();                    if (bodyPart instanceof MimeBodyPart) {                        accept(visitor, (MimeBodyPart) bodyPart);                    } else {                        mLog.info("Mime.accept(): Unexpected BodyPart subclass: " + bodyPart.getClass().getName());                    }                }                visitor.visitMultipart(multi, MimeVisitor.VISIT_END);            }        } else if (isMessage) {            Object content = mp.getContent();            // handle unparsed content due to miscapitalization of content-type value            if (content instanceof InputStream)                try {                    content = new MimeMessage(null, (InputStream) content);                } catch (Exception e) {                    mLog.info("Mime.accept(): Unable to parse message InputStream", e);                }            if (content instanceof MimeMessage) {                accept(visitor, (MimeMessage) content);            }        } else if (mp instanceof MimeBodyPart) {            visitor.visitBodyPart((MimeBodyPart) mp);        } else if (!(mp instanceof MimeMessage)) {            mLog.info("Mime.accept(): Unexpected type: " + mp.getClass().getName() +                ".  Content-Type='" + cts + "'");        }        if (mp instanceof MimeMessage) {            visitor.visitMessage((MimeMessage) mp, MimeVisitor.VISIT_END);        }    }