Horde_Mime_Part::setTransferEncoding PHP Method

setTransferEncoding() public method

Only needed in the following circumstances: 1.) Indicate what the transfer encoding is if the data has not yet been set in the object (can only be set if there presently are not any contents). 2.) Force the encoding to a certain type on a toString() call (if 'send' is true).
public setTransferEncoding ( string $encoding, array $options = [] )
$encoding string The transfer encoding to use.
$options array Additional options: - send: (boolean) If true, use $encoding as the sending encoding. DEFAULT: $encoding is used to change the base encoding.
    public function setTransferEncoding($encoding, $options = array())
    {
        if (empty($encoding) || empty($options['send']) && !empty($this->_contents)) {
            return;
        }
        switch ($encoding = Horde_String::lower($encoding)) {
            case '7bit':
            case '8bit':
            case 'base64':
            case 'binary':
            case 'quoted-printable':
                // Non-RFC types, but old mailers may still use
            // Non-RFC types, but old mailers may still use
            case 'uuencode':
            case 'x-uuencode':
            case 'x-uue':
                if (empty($options['send'])) {
                    $this->_transferEncoding = $encoding;
                } else {
                    $this->_temp['sendEncoding'] = $encoding;
                }
                break;
            default:
                if (empty($options['send'])) {
                    /* RFC 2045: Any entity with unrecognized encoding must be
                     * treated as if it has a Content-Type of
                     * "application/octet-stream" regardless of what the
                     * Content-Type field actually says. */
                    $this->setType('application/octet-stream');
                    $this->_transferEncoding = null;
                }
                break;
        }
    }

Usage Example

Example #1
0
 private function load()
 {
     $headers = [];
     $fetch_query = new \Horde_Imap_Client_Fetch_Query();
     $fetch_query->bodyPart($this->attachmentId);
     $fetch_query->mimeHeader($this->attachmentId);
     $headers = array_merge($headers, ['importance', 'list-post', 'x-priority']);
     $headers[] = 'content-type';
     $fetch_query->headers('imp', $headers, ['cache' => true]);
     // $list is an array of Horde_Imap_Client_Data_Fetch objects.
     $ids = new \Horde_Imap_Client_Ids($this->messageId);
     $headers = $this->conn->fetch($this->mailBox, $fetch_query, ['ids' => $ids]);
     /** @var $fetch Horde_Imap_Client_Data_Fetch */
     if (!isset($headers[$this->messageId])) {
         throw new DoesNotExistException('Unable to load the attachment.');
     }
     $fetch = $headers[$this->messageId];
     $mimeHeaders = $fetch->getMimeHeader($this->attachmentId, Horde_Imap_Client_Data_Fetch::HEADER_PARSE);
     $this->mimePart = new \Horde_Mime_Part();
     // To prevent potential problems with the SOP we serve all files with the
     // MIME type "application/octet-stream"
     $this->mimePart->setType('application/octet-stream');
     // Serve all files with a content-disposition of "attachment" to prevent Cross-Site Scripting
     $this->mimePart->setDisposition('attachment');
     // Extract headers from part
     $contentDisposition = $mimeHeaders->getValue('content-disposition', \Horde_Mime_Headers::VALUE_PARAMS);
     if (!is_null($contentDisposition)) {
         $vars = ['filename'];
         foreach ($contentDisposition as $key => $val) {
             if (in_array($key, $vars)) {
                 $this->mimePart->setDispositionParameter($key, $val);
             }
         }
     } else {
         $contentDisposition = $mimeHeaders->getValue('content-type', \Horde_Mime_Headers::VALUE_PARAMS);
         $vars = ['name'];
         foreach ($contentDisposition as $key => $val) {
             if (in_array($key, $vars)) {
                 $this->mimePart->setContentTypeParameter($key, $val);
             }
         }
     }
     /* Content transfer encoding. */
     if ($tmp = $mimeHeaders->getValue('content-transfer-encoding')) {
         $this->mimePart->setTransferEncoding($tmp);
     }
     $body = $fetch->getBodyPart($this->attachmentId);
     $this->mimePart->setContents($body);
 }
All Usage Examples Of Horde_Mime_Part::setTransferEncoding