title: Java Mail: Only one part of the message is retrieved / Parsing error / Badly formatted mail
body: <p>Hello all :) I'm having troubles parsing mails from a pop3 server. In the end I want to get the attachements. The mails are multiparts, but so far I only managed to get a small part of the mail. </p>
  
  <p>Here is the original email, as read by outlook (+one file attached):</p>
  
  <pre><code>ID-G1619161
  
  P.S. : This is an automated email.
   Write back to blah@blah.com
  
  Post-scriptum :
  
  This message is confidential. [...]
  </code></pre>
  
  <p>Here is some code:</p>
  
  <pre><code>inbox.open(Folder.READ_ONLY);
  Message[] messages = inbox.getMessages();
  
  for (int i = 0; i &lt; messages.length; i++) {
  
      Message message = messages[i];
      System.out.println("message : " + message);
      System.out.println("***");
      IOUtils.copy(message.getInputStream(),System.out);
      System.out.println("***");              
      System.out.println("message.getContentType : " + message.getContentType());
      Multipart multiPart = (Multipart) message.getContent();
      System.out.println("multiPart : " + multiPart);
      int numberOfParts = multiPart.getCount();  // line A
  }
  </code></pre>
  
  <p>This prints:</p>
  
  <pre><code>message : org.apache.geronimo.javamail.store.pop3.message.POP3Message@79f6f296
  ***
  
  P.S. : This is an automated email.***
  message.getContentType : multipart/mixed; boundary="qMm9M+Fa2AknHoGS"
  multiPart : javax.mail.internet.MimeMultipart@bc92535
  </code></pre>
  
  <p>And throws on line A (<code>multiPart.getCount</code>!):</p>
  
  <pre><code>javax.mail.MessagingException: Unexpected response:  Write back to blah@blah.com
  </code></pre>
  
  <p>My take on this is the message is formatted in a weird way that is not recognised by <code>javax.mail</code>, because <code>getCount</code> is trying to read the rest of the mail.</p>
  
  <p>I can even get the whole message! (Trying to do this at: <code>IOUtils.copy(message.getInputStream(),System.out);</code>)</p>
  
  <p>How would you debug this? Also, if you know a way to get the whole mail as a string (attachements included), I'd be very glad you share it. I'm prepared to parse this by hand.</p>
  
  <p>Best regards</p>