IMP_Contents::getMimePart PHP Method

getMimePart() public method

Fetch a part of a MIME message.
public getMimePart ( integer $id, array $options = [] ) : Horde_Mime_Part
$id integer The MIME index of the part requested.
$options array Additional options: - length: (integer) If set, only download this many bytes of the bodypart from the server. DEFAULT: All data is retrieved. - nocontents: (boolean) If true, don't add the contents to the part DEFAULT: Contents are added to the part
return Horde_Mime_Part The raw MIME part asked for. If not found, returns null.
    public function getMimePart($id, $options = array())
    {
        $this->_buildMessage();
        if (!($part = $this->_message[$id])) {
            return null;
        }
        /* Ticket #9201: Treat 'ISO-8859-1' as 'windows-1252'. 1252 has some
         * characters (e.g. euro sign, back quote) not in 8859-1. There
         * shouldn't be any issue doing this since the additional code points
         * in 1252 don't map to anything in 8859-1. */
        if (strcasecmp($part->getCharset(), 'ISO-8859-1') === 0) {
            $part->setCharset('windows-1252');
        }
        /* Don't download contents of entire body if ID == 0 (indicating the
         * body of the main multipart message).  I'm pretty sure we never
         * want to download the body of that part here. */
        if (!empty($id) && empty($options['nocontents']) && $this->_indices && !$part->getContents(array('stream' => true))) {
            $body = $this->getBodyPart($id, array('decode' => true, 'length' => empty($options['length']) ? null : $options['length'], 'stream' => true));
            $part->setContents($body->data, array('encoding' => $body->decode, 'usestream' => true));
        }
        return $part;
    }

Usage Example

Exemplo n.º 1
0
Arquivo: View.php Projeto: horde/horde
 /**
  * Get a MIME Part for use in creating download.
  *
  * @param string $id  MIME ID.
  *
  * @return Horde_Mime_Part  MIME part, or null on error.
  */
 protected function _getRawDownloadPart($id)
 {
     if (!($mime = $this->_contents->getMimePart($id))) {
         return null;
     }
     if ($this->_contents->canDisplay($id, IMP_Contents::RENDER_RAW)) {
         $render = $this->_contents->renderMIMEPart($id, IMP_Contents::RENDER_RAW);
         $part = reset($render);
         $mime->setContents($part['data'], array('encoding' => 'binary', 'usestream' => true));
     }
     return $mime;
 }
All Usage Examples Of IMP_Contents::getMimePart