MimeMultipart mp = (MimeMultipart) attachment.getContent(); for (int i = 0; i < mp.getCount(); i++) { Part bp = mp.getBodyPart(i); if (bp.isMimeType("text/*")) { String text = (String)bp.getContent(); //process text } else if (bp.isMimeType("image/*")) { InputStream is = bp.getInputStream(); //process image } }
private String getText(Part p) throws MessagingException, IOException { System.out.println("getText contentType "+p.getContentType()); if (p.isMimeType("text/plain")) { String s = (String) p.getContent(); System.out.println(s); return s; } else if (p.isMimeType("text/html")) { // the last two parameters of this may need to be modified String s = Jsoup.parse(p.getInputStream(), null, null).text(); System.out.println(s); return s; } else if (p.isMimeType("multipart/alternative")) { Multipart mp = (Multipart) p.getContent(); String text = ""; for (int i = 0; i < mp.getCount(); i++) { Part bp = mp.getBodyPart(i); if (bp.isMimeType("text/*")) { String s = getText(bp); if (s != null) { text += s; } } } return text; } return null; }
if(p.isMimeType("image/*")){ if (p.isMimeType("text/*")) { String s = ""; Object objContent = p.getContent(); if(objContent instanceof String){ if(p.isMimeType("text/html")){ s = (String) objContent; if (p.isMimeType("multipart/alternative")) { for (int i = 0; i < mp.getCount(); i++) { Part bp = mp.getBodyPart(i); if (bp.isMimeType("text/plain")) { String s = getText(bp,embededImgMap); if (s != null){ return s; } else if (bp.isMimeType("text/html")) { String s = getText(bp,embededImgMap); if (s != null){ } else if (p.isMimeType("multipart/*")) { Multipart mp = (Multipart) p.getContent(); for (int i = 0; i < mp.getCount(); i++) { }else if (p.isMimeType("multipart/related")) { Multipart mp = (Multipart) p.getContent(); for (int i = 0; i < mp.getCount(); i++) {