Horde_ActiveSync_Imap_Adapter::getAttachment PHP Method

getAttachment() public method

Return the content of a specific MIME part of the specified message.
public getAttachment ( string $mailbox, string $uid, string $part ) : Horde_Mime_Part
$mailbox string The mailbox name.
$uid string The message UID.
$part string The MIME part identifier.
return Horde_Mime_Part The attachment data
    public function getAttachment($mailbox, $uid, $part)
    {
        $imap = $this->_getImapOb();
        $mbox = new Horde_Imap_Client_Mailbox($mailbox);
        $messages = $this->_getMailMessages($mbox, array($uid));
        if (empty($messages[$uid]) || !$messages[$uid]->exists(Horde_Imap_Client::FETCH_STRUCTURE)) {
            throw new Horde_ActiveSync_Exception('Message Gone');
        }
        $msg = new Horde_ActiveSync_Imap_Message($imap, $mbox, $messages[$uid]);
        $part = $msg->getMimePart($part);
        return $part;
    }

Usage Example

Example #1
0
 /**
  * Return the specified attachment.
  *
  * @param string $name  The attachment identifier. For this driver, this
  *                      consists of 'mailbox:uid:mimepart'
  * @param array $options  Any options requested. Currently supported:
  *  - stream: (boolean) Return a stream resource for the mime contents.
  *            DEFAULT: true (Return a stream resource for the 'data' value).
  *
  * @return array  The attachment in the form of an array with the following
  *                structure:
  * array('content-type' => {the content-type of the attachement},
  *       'data'         => {the raw attachment data})
  */
 public function getAttachment($name, array $options = array())
 {
     $options = array_merge(array('stream' => true), $options);
     list($mailbox, $uid, $part) = explode(':', $name);
     $atc = $this->_imap->getAttachment($mailbox, $uid, $part);
     return array('content-type' => $atc->getType(), 'data' => $atc->getContents(array('stream' => $options['stream'])));
 }