title: Zend_Mail_Part: Get number of attachments
body: <p>How can i find out that how many attachments a message has?</p>
  
  <p>Is this method reliable?</p>
  
  <pre><code>$attachments = 0;
  $msg = $mail-&gt;getMessage($msgno);
  if($msg-&gt;isMultipart()){
      $parts = $msg-&gt;countParts();
      for($i=1; $i&lt;=$parts; $i++){
          $part = $msg-&gt;getPart($i);
          try {
              if(strpos($part-&gt;contentType,'text/html')===false &amp;&amp; strpos($part-&gt;contentType,'text/plain')===false)
                  $attachments++;
          } catch (Zend_Mail_Exception $e) {}
      }
  }
  </code></pre>
  
  <p>or this?</p>
  
  <pre><code>$matches = array();
  $pattern = '`Content-Disposition: (?!inline)(.*)[\s]*filename=`';
  $attachments = (string) preg_match_all($pattern, $storage-&gt;getRawContent($msgno), $matches);
  </code></pre>