title: How to get email attachments with Zend Framework 2
body: <p>I have managed to get text/html and text/plain parts of email, but now I need to get using <code>strtok($part-&gt;contentType, ';') == "text/plain"</code> and <code>strtok($part-&gt;contentType, ';') == "text/plain"</code> but now I need to get attachments (name, and to decode them). 
  I have tried to do it via <code>Content-Disposition</code> equal to attachment, but I cant get to <code>Content-Disposition</code> from header array.
  So my question is how to get attachments from email using IMAP and ZF2?
  I saw couple similar questions like this and they are all submitted for previous version, I will need some newer solution.</p>
  
  <p>Using Zend\Mail\Storage\Imap.</p>
  
  <p>This is what I got when using <code>print_r( $part-&gt;getHeaders() );</code> (this is only email part with attachment) :</p>
  
  <pre><code>Zend\Mail\Headers Object
  (
      [pluginClassLoader:protected] =&gt; Zend\Mail\Header\HeaderLoader Object
          (
              [plugins:protected] =&gt; Array
                  (
                      [bcc] =&gt; Zend\Mail\Header\Bcc
                      [cc] =&gt; Zend\Mail\Header\Cc
                      [contenttype] =&gt; Zend\Mail\Header\ContentType
                      [content_type] =&gt; Zend\Mail\Header\ContentType
                      [content-type] =&gt; Zend\Mail\Header\ContentType
                      [date] =&gt; Zend\Mail\Header\Date
                      [from] =&gt; Zend\Mail\Header\From
                      [message-id] =&gt; Zend\Mail\Header\MessageId
                      [mimeversion] =&gt; Zend\Mail\Header\MimeVersion
                      [mime_version] =&gt; Zend\Mail\Header\MimeVersion
                      [mime-version] =&gt; Zend\Mail\Header\MimeVersion
                      [received] =&gt; Zend\Mail\Header\Received
                      [replyto] =&gt; Zend\Mail\Header\ReplyTo
                      [reply_to] =&gt; Zend\Mail\Header\ReplyTo
                      [reply-to] =&gt; Zend\Mail\Header\ReplyTo
                      [sender] =&gt; Zend\Mail\Header\Sender
                      [subject] =&gt; Zend\Mail\Header\Subject
                      [to] =&gt; Zend\Mail\Header\To
                  )
  
          )
  
      [headersKeys:protected] =&gt; Array
          (
              [0] =&gt; contenttype
              [1] =&gt; contentdisposition
              [2] =&gt; contenttransferencoding
              [3] =&gt; xattachmentid
          )
  
      [headers:protected] =&gt; Array
          (
              [0] =&gt; Zend\Mail\Header\ContentType Object
                  (
                      [type:protected] =&gt; application/octet-stream
                      [parameters:protected] =&gt; Array
                          (
                              [name] =&gt; listen.pls
                          )
  
                  )
  
              [1] =&gt; Zend\Mail\Header\GenericHeader Object
                  (
                      [fieldName:protected] =&gt; Content-Disposition
                      [fieldValue:protected] =&gt; attachment; filename="listen.pls"
                      [encoding:protected] =&gt; ASCII
                  )
  
              [2] =&gt; Zend\Mail\Header\GenericHeader Object
                  (
                      [fieldName:protected] =&gt; Content-Transfer-Encoding
                      [fieldValue:protected] =&gt; base64
                      [encoding:protected] =&gt; ASCII
                  )
  
              [3] =&gt; Zend\Mail\Header\GenericHeader Object
                  (
                      [fieldName:protected] =&gt; X-Attachment-Id
                      [fieldValue:protected] =&gt; f_hlmfqj9o2
                      [encoding:protected] =&gt; ASCII
                  )
  
          )
  
      [encoding:protected] =&gt; ASCII
  )
  </code></pre>