Horde_Mime_Part::addMimeHeaders PHP Method

addMimeHeaders() public method

Returns a Horde_Mime_Header object containing all MIME headers needed for the part.
public addMimeHeaders ( array $options = [] ) : Horde_Mime_Headers
$options array Additional options: - encode: (integer) A mask of allowable encodings. DEFAULT: Auto-determined - headers: (Horde_Mime_Headers) The object to add the MIME headers to. DEFAULT: Add headers to a new object
return Horde_Mime_Headers A Horde_Mime_Headers object.
    public function addMimeHeaders($options = array())
    {
        if (empty($options['headers'])) {
            $headers = new Horde_Mime_Headers();
        } else {
            $headers = $options['headers'];
            $headers->removeHeader('Content-Disposition');
            $headers->removeHeader('Content-Transfer-Encoding');
        }
        /* Add the mandatory Content-Type header. */
        $ct = $this->_headers['content-type'];
        $headers->addHeaderOb($ct);
        /* Add the language(s), if set. (RFC 3282 [2]) */
        if ($hdr = $this->_headers['content-language']) {
            $headers->addHeaderOb($hdr);
        }
        /* Get the description, if any. */
        if ($hdr = $this->_headers['content-description']) {
            $headers->addHeaderOb($hdr);
        }
        /* Set the duration, if it exists. (RFC 3803) */
        if ($hdr = $this->_headers['content-duration']) {
            $headers->addHeaderOb($hdr);
        }
        /* Per RFC 2046[4], this MUST appear in the base message headers. */
        if ($this->_status & self::STATUS_BASEPART) {
            $headers->addHeaderOb(Horde_Mime_Headers_MimeVersion::create());
        }
        /* message/* parts require no additional header information. */
        if ($ct->ptype === 'message') {
            return $headers;
        }
        /* RFC 2183 [2] indicates that default is no requested disposition -
         * the receiving MUA is responsible for display choice. */
        $cd = $this->_headers['content-disposition'];
        if (!$cd->isDefault()) {
            $headers->addHeaderOb($cd);
        }
        /* Add transfer encoding information. RFC 2045 [6.1] indicates that
         * default is 7bit. No need to send the header in this case. */
        $cte = new Horde_Mime_Headers_ContentTransferEncoding(null, $this->_getTransferEncoding(empty($options['encode']) ? null : $options['encode']));
        if (!$cte->isDefault()) {
            $headers->addHeaderOb($cte);
        }
        /* Add content ID information. */
        if ($hdr = $this->_headers['content-id']) {
            $headers->addHeaderOb($hdr);
        }
        return $headers;
    }

Usage Example

Example #1
0
 /**
  * Returns base header information.
  *
  * @param integer $type  See getHeader().
  * @param boolean $seen  Mark message as seen?
  *
  * @return mixed  See getHeader().
  */
 protected function _getHeader($type, $seen)
 {
     if (!isset($this->_header)) {
         if (!$this->_indices) {
             $this->_header = $this->_message->addMimeHeaders();
         } else {
             $query = new Horde_Imap_Client_Fetch_Query();
             $query->headerText(array('peek' => !$seen));
             $this->_header = ($res = $this->_fetchData($query)) ? $res : new Horde_Imap_Client_Data_Fetch();
         }
     }
     switch ($type) {
         case self::HEADER_OB:
             return $this->_indices ? $this->_header->getHeaderText(0, Horde_Imap_Client_Data_Fetch::HEADER_PARSE) : $this->_header;
         case self::HEADER_TEXT:
             return $this->_indices ? $this->_header->getHeaderText() : $this->_header->toString();
         case self::HEADER_STREAM:
             if ($this->_indices) {
                 return $this->_header->getHeaderText(0, Horde_Imap_Client_Data_Fetch::HEADER_STREAM);
             }
             $stream = new Horde_Support_StringStream($this->_header->toString());
             $stream->fopen();
             return $stream;
     }
 }
All Usage Examples Of Horde_Mime_Part::addMimeHeaders