示例#1
0
  @Nonnull
  private static Content processPart(MimePart part, MimePart parent)
      throws MessagingException, IOException {
    if (part == null) {
      return new Content();
    }

    if (part.getFileName() != null) {
      // Assume that a part which has a filename is an attachment.
      return new Content(part);
    }

    if (part.isMimeType("text/*")) {
      return getContent(part);
    } else if (part.isMimeType("multipart/*")) {
      if (part.isMimeType(MimeType.MULTIPART_RELATED)) {
        return getContentWithAttachments(part);
      } else if (part.isMimeType(MimeType.MULTIPART_ALTERNATIVE)) {
        return getContentOfBestPart(part, parent);
      } else {
        return getJoinedContent(part);
      }
    }

    return new Content();
  }
示例#2
0
 private static Content getContentOfBestPart(MimePart part, MimePart parent)
     throws IOException, MessagingException {
   MimeBodyPart best = null;
   MimeMultipart mp = (MimeMultipart) part.getContent();
   for (int i = 0; i < mp.getCount(); i++) {
     // Prefer HTML if the parent is a multipart/related part which may contain
     // inline images, because text/plain cannot embed the images.
     boolean isHtmlPreferred = parent != null && parent.isMimeType(MimeType.MULTIPART_RELATED);
     best = better((MimeBodyPart) mp.getBodyPart(i), best, isHtmlPreferred);
   }
   return processPart(best, part);
 }