日期:2014-05-19 浏览次数:20730 次
public String getMessageText(Message message) throws java.io.IOException,javax.mail.MessagingException { String body = null; Object o = message.getContent(); if (o instanceof MimeMultipart) { MimeMultipart mm = (MimeMultipart)o; mm = (MimeMultipart)o; BodyPart bp = null; for(int j = 0; j < mm.getCount(); j++) { bp = mm.getBodyPart(j); try { o = bp.getContent(); } catch (IOException e) { if (bp.getContentType().equals("text/plain; charset=unicode-1-1-utf-7")) { ByteArrayOutputStream bao = new ByteArrayOutputStream(); bp.writeTo(bao); body = bao.toString(); } break; } if (o instanceof MimeMessage) { body = ((MimeMessage)o).getContent().toString(); break; } else if (o instanceof String) { body = (String)o; break; } } } else { body = message.getContent().toString(); } return body; }