title: Get Only the Attachments from an E-mail
body: <p>I have a code which checks attachments of e-mail:</p>
  
  <pre><code>final Multipart mp = (Multipart) msg.getContent();
  final int numAttachments = mp.getCount();
  ...
  final Part part = mp.getBodyPart(attachmentNumber);
  </code></pre>
  
  <p>However, <code>numAttachments</code> return number of attachments + 1. When I iterate over <code>mp.getBodyPart(index)</code> I see that I iterate over attachments and e-mail. I just want to get attachments, not e-mails.</p>
  
  <p>I know <a href="http://www.oracle.com/technetwork/java/faq-135477.html#attachments" rel="nofollow noreferrer">that</a>:</p>
  
  <blockquote>
    <p>Attachments will usually, but not always, have a Content-Disposition of attachment. Attachments will usually, but not always, have a file name.</p>
  </blockquote>
  
  <p>When I test it, I see that e-mail is always at 0-th index and attachments comes after that. So, skipping the 0-th index may be a solution but I don't know is this valid for all e-mail servers.</p>
  
  <p>How can I get only the attachments from an e-mail? </p>