/** Creates a new instance of RenderablePlainText */
 public RenderablePlainText(Message message) throws MessagingException, IOException {
   subject = message.getSubject();
   bodytext = (String) message.getContent();
   receivedOn = message.getReceivedDate();
   if (!StringUtils.isNull(bodytext)) {
     if (bodytext.indexOf("Original Message") > -1) {
       subBody = bodytext.substring(0, bodytext.indexOf("Original Message"));
     }
     if (!StringUtils.isNull(bodytext)
         && bodytext.indexOf(", \"[email protected]\" <*****@*****.**> wrote:") > -1) {
       String tempstr =
           bodytext.substring(
               0, bodytext.indexOf(", \"[email protected]\" <*****@*****.**> wrote:"));
       subBody = tempstr.substring(0, tempstr.lastIndexOf("On"));
     }
   }
 }
 public String getReferenceId() {
   String eventRefStartPoint = null;
   if (!StringUtils.isNull(bodytext) && bodytext.lastIndexOf("Event Reference:: [") > -1) {
     eventRefStartPoint = bodytext.substring(bodytext.lastIndexOf("Event Reference:: ["));
     eventRefStartPoint =
         eventRefStartPoint != null && eventRefStartPoint.length() > 19
             ? eventRefStartPoint.substring(19, eventRefStartPoint.indexOf("]"))
             : null;
   }
   return eventRefStartPoint;
 }
  private void extractPart(final Part part) throws MessagingException, IOException {
    if (part.getContent() instanceof Multipart) {
      Multipart mp = (Multipart) part.getContent();
      for (int i = 0; i < mp.getCount(); i++) {
        extractPart(mp.getBodyPart(i));
      }
      return;
    }

    if (part.getContentType().startsWith("text/html")) {
      if (bodytext == null) {
        bodytext = (String) part.getContent();
      } else {
        bodytext = bodytext + "<HR/>" + (String) part.getContent();
      }
    } else if (!part.getContentType().startsWith("text/plain")) {
      Attachment attachment = new Attachment();
      attachment.setContenttype(part.getContentType());
      attachment.setFilename(part.getFileName());

      InputStream in = part.getInputStream();
      ByteArrayOutputStream bos = new ByteArrayOutputStream();

      byte[] buffer = new byte[8192];
      int count = 0;
      while ((count = in.read(buffer)) >= 0) bos.write(buffer, 0, count);
      in.close();
      attachment.setContent(bos.toByteArray());
      attachments.add(attachment);
    }

    if (!StringUtils.isNull(bodytext) && bodytext.indexOf("Original Message") > -1) {
      subBody = bodytext.substring(0, bodytext.indexOf("Original Message"));
    } else if (!StringUtils.isNull(bodytext)
        && bodytext.indexOf(", \"[email protected]\" <*****@*****.**> wrote:") > -1) {
      String tempstr =
          bodytext.substring(
              0, bodytext.indexOf(", \"[email protected]\" <*****@*****.**> wrote:"));
      subBody = tempstr.substring(0, tempstr.lastIndexOf("On"));
    }
  }