title: Convert formatted email (HTML) to plain Text?
body: <p>I have this code that implements <code>ParserCallback</code> and converts <code>HTML</code> emails to <code>Plain</code> text. This code works fine when I parse email body like this =</p>
  
  <pre><code>  "DO NOT REPLY TO THIS EMAIL MESSAGE.   &lt;br&gt;---------------------------------------&lt;br&gt;\n" +
                  "nix&lt;br&gt;---------------------------------------&lt;br&gt; Esfghjdfkj\n" +
                  "&lt;/blockquote&gt;&lt;/div&gt;&lt;br&gt;&lt;br clear=\"all\"&gt;&lt;div&gt;&lt;br&gt;&lt;/div&gt;-- &lt;br&gt;&lt;div dir=\"ltr\"&gt;&lt;b&gt;Regards &lt;br&gt;Nisj&lt;br&gt;Software Engineer&lt;br&gt;&lt;/b&gt;&lt;div&gt;&lt;b&gt;Bingo&lt;/b&gt;&lt;/div&gt;&lt;/div&gt;\n" +
                  "&lt;/div&gt;"
  </code></pre>
  
  <p>but when I parse this kinda email body, it returns null, </p>
  
  <pre><code> email = "&lt;html&gt;&lt;head&gt;&lt;meta http-equiv=\"Content-Type\" content=\"text/html charset=us-ascii\"&gt;&lt;/head&gt;&lt;body style=\"word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;\"&gt;Got it...so pls send to customer now.&lt;div&gt;&lt;br&gt;&lt;div style=\"\"&gt;&lt;div&gt;On Nov 8, 2013, at 12:31 PM, &lt;a href=\"mailto:xxxxxxx.com\"&gt;xxxxxxx.com&lt;/a&gt; wrote:&lt;/div&gt;&lt;br class=\"Apple-interchange-newline\"&gt;&lt;blockquote type=\"cite\"&gt;Forwarding test.&lt;br&gt;---------------------------------------&lt;br&gt; ABCD.&lt;/blockquote&gt;&lt;/div&gt;&lt;br&gt;&lt;/div&gt;&lt;/body&gt;&lt;/html&gt;";
  </code></pre>
  
  <p>Code :</p>
  
  <pre><code>import java.io.IOException;
  import java.io.StringReader;
  
  import javax.swing.text.MutableAttributeSet;
  import javax.swing.text.html.HTML.Attribute;
  import javax.swing.text.html.HTML.Tag;
  import javax.swing.text.html.HTMLEditorKit.Parser;
  import javax.swing.text.html.HTMLEditorKit.ParserCallback;
  import javax.swing.text.html.parser.ParserDelegator;
  
  public class EmailBody {
      public static void main(String[] args) throws IOException
      {
          String email = "";
  
          class EmailCallback extends ParserCallback
          {
              private String body_;
              private boolean divStarted_;
  
              public String getBody()
              {
                  return body_;
              }
  
              @Override
              public void handleStartTag(Tag t, MutableAttributeSet a, int pos)
              {
                  if (t.equals(Tag.DIV) &amp;&amp; "ltr".equals(a.getAttribute(Attribute.DIR)))
                  {
                      divStarted_ = true;
                  }
              }
  
              @Override
              public void handleEndTag(Tag t, int pos)
              {
                  if (t.equals(Tag.DIV))
                  {
                      divStarted_ = false;
                  }
              }
  
              @Override
              public void handleText(char[] data, int pos)
              {
                  if (divStarted_)
                  {
                      body_ = new String(data);
                  }
              }
          }
          EmailCallback callback = new EmailCallback();
          Parser parser = new ParserDelegator();
          StringReader reader = new StringReader(email);
          parser.parse(reader, callback, true);
          reader.close();
          System.out.println(callback.getBody());
      }
  }
  </code></pre>
  
  <p><strong>Can you tell the reason, why this is happening ?</strong></p>