title: Message Content to String Exception
body: <p>I'mworking on an E- Mail Client for my Android Phone using the JavaMail API. If I try to get the Content of an E- Mail, I get the following text in the logCat:</p>
  
  <blockquote>
    <p>FROM: XXXXXXXXXXXXXXXXXXXXXXXXXX</p>
    
    <p>TO: AG Blasorchester </p>
    
    <p>SUBJECT: BITTE DENKT AN DIE SCHWARZE MAPPE / RINGORDNER</p>
    
    <p>SendDate: Wed Feb 27 21:30:49 MEZ 2013</p>
    
    <p>CONTENT-TYPE: TEXT/PLAIN; charset=iso-8859-1</p>
    
    <p>Message Content:</p>
    
    <p>Fehler: java.lang.ClassCastException:
    com.sun.mail.util.QPDecoderStream cannot be cast to java.lang.String</p>
  </blockquote>
  
  <p>This is the thrown exception: java.lang.ClassCastException: com.sun.mail.util.QPDecoderStream cannot be cast to java.lang.String</p>
  
  <p>I use the following code to get the Content:</p>
  
  <pre><code>public static void dumpPart(Part p) throws Exception {
      Log.i("Gestartet", "dumpPart Gestartet");
      if (p instanceof Message)
          dumpEnvelope((Message)p);
  
      /** Dump input stream .. 
  
      InputStream is = p.getInputStream();
      // If "is" is not already buffered, wrap a BufferedInputStream
      // around it.
      if (!(is instanceof BufferedInputStream))
          is = new BufferedInputStream(is);
      int c;
      while ((c = is.read()) != -1)
          System.out.write(c);
  
      **/
  
      String ct = p.getContentType();
      try {
          pr("CONTENT-TYPE: " + (new ContentType(ct)).toString());
      } catch (ParseException pex) {
          pr("BAD CONTENT-TYPE: " + ct);
      }
      String filename = p.getFileName();
      if (filename != null)
          pr("FILENAME: " + filename);
  
      /*
       * Using isMimeType to determine the content type avoids
       * fetching the actual content data until we need it.
       */
      try{
      if (p.isMimeType("text/plain")) {
          pr("This is plain text");
          pr("---------------------------");
          if (!showStructure &amp;&amp; !saveAttachments)
          System.out.println((String)p.getContent());
      } else if (p.isMimeType("multipart/*")) {
          pr("This is a Multipart");
          pr("---------------------------");
          Multipart mp = (Multipart)p.getContent();
          level++;
          int count = mp.getCount();
          for (int i = 0; i &lt; count; i++)
          dumpPart(mp.getBodyPart(i));
          level--;
      } else if (p.isMimeType("message/rfc822")) {
          pr("This is a Nested Message");
          pr("---------------------------");
          level++;
          dumpPart((Part)p.getContent());
          level--;
      } else {
          if (!showStructure &amp;&amp; !saveAttachments) {
          /*
           * If we actually want to see the data, and it's not a
           * MIME type we know, fetch it and check its Java type.
           */
          Object o = p.getContent();
          if (o instanceof String) {
              pr("This is a string");
              pr("---------------------------");
              System.out.println((String)o);
          } else if (o instanceof InputStream) {
              pr("This is just an input stream");
              pr("---------------------------");
              InputStream is = (InputStream)o;
              int c;
              while ((c = is.read()) != -1)
              System.out.write(c);
          } else {
              pr("This is an unknown type");
              pr("---------------------------");
              pr(o.toString());
          }
          } else {
          // just a separator
          pr("---------------------------");
          }
  
          }
      }catch(Exception e){
          Log.i("Fehler", "Fehler: " + e);
      }
  }
  </code></pre>
  
  <p>Can I get the Message Content as a String without an exception?</p>