Exemplo n.º 1
0
 /**
  * Convert the output from mimeDecode::decode() into a structure that
  * matches imap_fetchstructure() output.
  *
  * @access private
  *
  * @param stdClass &$ob The output from mimeDecode::decode().
  */
 protected static function _convertMimeDecodeData(&$ob)
 {
     /* Primary content-type. */
     if (!isset($ob->ctype_primary)) {
         $ob->ctype_primary = 'application';
         $ob->ctype_secondary = 'octet-stream';
     }
     $ob->type = intval(Horde_MIME::type($ob->ctype_primary));
     /* Secondary content-type. */
     if (isset($ob->ctype_secondary)) {
         $ob->subtype = Horde_String::upper($ob->ctype_secondary);
         $ob->ifsubtype = 1;
     } else {
         $ob->ifsubtype = 0;
     }
     /* Content transfer encoding. */
     if (isset($ob->headers['content-transfer-encoding'])) {
         $ob->encoding = Horde_MIME::encoding($ob->headers['content-transfer-encoding']);
     }
     /* Content-type and Disposition parameters. */
     $param_types = array('ctype_parameters' => 'parameters', 'd_parameters' => 'dparameters');
     foreach ($param_types as $param_key => $param_value) {
         $if_var = 'if' . $param_value;
         if (isset($ob->{$param_key})) {
             $ob->{$if_var} = 1;
             $ob->{$param_value} = array();
             foreach ($ob->{$param_key} as $key => $val) {
                 $newOb =& new stdClass();
                 $newOb->attribute = $key;
                 $newOb->value = $val;
                 array_push($ob->{$param_value}, $newOb);
             }
         } else {
             $ob->{$if_var} = 0;
         }
     }
     /* Content-Disposition. */
     if (isset($ob->headers['content-disposition'])) {
         $ob->ifdisposition = 1;
         $hdr = $ob->headers['content-disposition'];
         $pos = strpos($hdr, ';');
         if ($pos !== false) {
             $hdr = substr($hdr, 0, $pos);
         }
         $ob->disposition = $hdr;
     } else {
         $ob->ifdisposition = 0;
     }
     /* Content-ID. */
     if (isset($ob->headers['content-id'])) {
         $ob->ifid = 1;
         $ob->id = $ob->headers['content-id'];
     } else {
         $ob->ifid = 0;
     }
     /* Get file size (if 'body' text is set). */
     if (isset($ob->body)) {
         $ob->bytes = strlen($ob->body);
     }
     /* Process parts also. */
     if (isset($ob->parts)) {
         reset($ob->parts);
         while (list($key, ) = each($ob->parts)) {
             Horde_MIME_Structure::_convertMimeDecodeData($ob->parts[$key]);
         }
     }
 }
Exemplo n.º 2
0
 /**
  * Set the mimetype of this part.
  *
  * @param string $mimetype The mimetype to set (ex.: text/plain).
  */
 public function setType($mimetype)
 {
     /* 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. */
     if ($this->_transferEncoding == 'x-unknown') {
         return;
     }
     /* Set the 'setType' flag. */
     $this->_flags['setType'] = true;
     list($this->_type, $this->_subtype) = explode('/', Horde_String::lower($mimetype));
     if ($type = Horde_MIME::type($this->_type, MIME_STRING)) {
         $this->_type = $type;
         /* Set the boundary string for 'multipart/*' parts. */
         if ($type == 'multipart') {
             if (!$this->getContentTypeParameter('boundary')) {
                 $this->setContentTypeParameter('boundary', $this->_generateBoundary());
             }
         } else {
             $this->clearContentTypeParameter('boundary');
         }
     } else {
         $this->_type = 'x-unknown';
         $this->clearContentTypeParameter('boundary');
     }
 }