title: How to get HTML text / plain text from java.mail
body: <p>When I'm reading email body from java.mail in <em>contentText</em> I get first plain text and after this HTML text. I.e. if send message is </p>
  
  <blockquote>
    <p>&lt;div&gt;&lt;b&gt;Mock&lt;/b&gt;&lt;br /&gt;Mock 2&lt;/div&gt;</p>
  </blockquote>
  
  <p>contentText will contains:</p>
  
  <blockquote>
    <p>Mock Mock
    &lt;div&gt;&lt;b&gt;Mock&lt;/b&gt;&lt;br /&gt;Mock 2&lt;/div&gt;</p>
  </blockquote>
  
  <p>Below is my code to load contentText:</p>
  
  <pre><code>public void setContentText(Multipart multipart) throws MessagingException, IOException {
      contentText ="";
  
      for (int i = 0; i &lt; multipart.getCount(); i++) {
          BodyPart bodyPart = multipart.getBodyPart(i);
          getBodyToStringPart(bodyPart);
      }
  }
  
  protected void getBodyToStringPart(BodyPart bodyPart) throws MessagingException, IOException {
      String disposition = bodyPart.getDisposition();
  
      if (!StringUtils.equalsIgnoreCase(disposition, "ATTACHMENT")) {
          if (bodyPart.getContent() instanceof BASE64DecoderStream
                  &amp;&amp; bodyPart.getHeader("Content-ID") != null) {
              BASE64DecoderStream base64DecoderStream = (BASE64DecoderStream) bodyPart
                      .getContent();
              byte[] byteArray = IOUtils.toByteArray(base64DecoderStream);
              byte[] encodeBase64 = Base64.encodeBase64(byteArray);
  
              this.contentText = this.contentText.replaceAll(
                      "cid:"
                              + bodyPart.getHeader("Content-ID")[0].replaceAll("&gt;", "")
                                      .replaceAll("&lt;", ""), "data:" + bodyPart.getContentType()
                              + ";base64," + new String(encodeBase64, "UTF-8"));
  
          } else if (bodyPart.getContent() instanceof MimeMultipart) {
              MimeMultipart mimeMultipart = (MimeMultipart) bodyPart.getContent();
              for (int j = 0; j &lt; mimeMultipart.getCount(); j++) {
                  getBodyToStringPart(mimeMultipart.getBodyPart(j));
              }
          } else {
              this.contentText += bodyPart.getContent() + "";
          }
      } else {
          // TODO: Do we need attachments ?
      }
  
  }
  </code></pre>