当前位置: 首页>>代码示例>>PHP>>正文


PHP rcube_mime::parse_headers方法代码示例

本文整理汇总了PHP中rcube_mime::parse_headers方法的典型用法代码示例。如果您正苦于以下问题:PHP rcube_mime::parse_headers方法的具体用法?PHP rcube_mime::parse_headers怎么用?PHP rcube_mime::parse_headers使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在rcube_mime的用法示例。


在下文中一共展示了rcube_mime::parse_headers方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: structure_part


//.........这里部分代码省略.........
            x. location (optional)
        */
     // regular part
     $struct->ctype_primary = strtolower($part[0]);
     $struct->ctype_secondary = strtolower($part[1]);
     $struct->mimetype = $struct->ctype_primary . '/' . $struct->ctype_secondary;
     // read content type parameters
     if (is_array($part[2])) {
         $struct->ctype_parameters = array();
         for ($i = 0; $i < count($part[2]); $i += 2) {
             $struct->ctype_parameters[strtolower($part[2][$i])] = $part[2][$i + 1];
         }
         if (isset($struct->ctype_parameters['charset'])) {
             $struct->charset = $struct->ctype_parameters['charset'];
         }
     }
     // #1487700: workaround for lack of charset in malformed structure
     if (empty($struct->charset) && !empty($mime_headers) && $mime_headers->charset) {
         $struct->charset = $mime_headers->charset;
     }
     // read content encoding
     if (!empty($part[5])) {
         $struct->encoding = strtolower($part[5]);
         $struct->headers['content-transfer-encoding'] = $struct->encoding;
     }
     // get part size
     if (!empty($part[6])) {
         $struct->size = intval($part[6]);
     }
     // read part disposition
     $di = 8;
     if ($struct->ctype_primary == 'text') {
         $di += 1;
     } else {
         if ($struct->mimetype == 'message/rfc822') {
             $di += 3;
         }
     }
     if (is_array($part[$di]) && count($part[$di]) == 2) {
         $struct->disposition = strtolower($part[$di][0]);
         if (is_array($part[$di][1])) {
             for ($n = 0; $n < count($part[$di][1]); $n += 2) {
                 $struct->d_parameters[strtolower($part[$di][1][$n])] = $part[$di][1][$n + 1];
             }
         }
     }
     // get message/rfc822's child-parts
     if (is_array($part[8]) && $di != 8) {
         $struct->parts = array();
         for ($i = 0, $count = 0; $i < count($part[8]); $i++) {
             if (!is_array($part[8][$i])) {
                 break;
             }
             $struct->parts[] = $this->structure_part($part[8][$i], ++$count, $struct->mime_id);
         }
     }
     // get part ID
     if (!empty($part[3])) {
         $struct->content_id = $part[3];
         $struct->headers['content-id'] = $part[3];
         if (empty($struct->disposition)) {
             $struct->disposition = 'inline';
         }
     }
     // fetch message headers if message/rfc822 or named part (could contain Content-Location header)
     if ($struct->ctype_primary == 'message' || $struct->ctype_parameters['name'] && !$struct->content_id) {
         if (empty($mime_headers)) {
             $mime_headers = $this->conn->fetchPartHeader($this->folder, $this->msg_uid, true, $struct->mime_id);
         }
         if (is_string($mime_headers)) {
             $struct->headers = rcube_mime::parse_headers($mime_headers) + $struct->headers;
         } else {
             if (is_object($mime_headers)) {
                 $struct->headers = get_object_vars($mime_headers) + $struct->headers;
             }
         }
         // get real content-type of message/rfc822
         if ($struct->mimetype == 'message/rfc822') {
             // single-part
             if (!is_array($part[8][0])) {
                 $struct->real_mimetype = strtolower($part[8][0] . '/' . $part[8][1]);
             } else {
                 for ($n = 0; $n < count($part[8]); $n++) {
                     if (!is_array($part[8][$n])) {
                         break;
                     }
                 }
                 $struct->real_mimetype = 'multipart/' . strtolower($part[8][$n]);
             }
         }
         if ($struct->ctype_primary == 'message' && empty($struct->parts)) {
             if (is_array($part[8]) && $di != 8) {
                 $struct->parts[] = $this->structure_part($part[8], ++$count, $struct->mime_id);
             }
         }
     }
     // normalize filename property
     $this->set_part_filename($struct, $mime_headers);
     return $struct;
 }
开发者ID:ehabqino,项目名称:roundcubemail,代码行数:101,代码来源:rcube_imap.php

示例2: parse_structure

 /**
  * Read the message structure returend by the IMAP server
  * and build flat lists of content parts and attachments
  *
  * @param rcube_message_part $structure Message structure node
  * @param bool               $recursive True when called recursively
  */
 private function parse_structure($structure, $recursive = false)
 {
     // real content-type of message/rfc822 part
     if ($structure->mimetype == 'message/rfc822' && $structure->real_mimetype) {
         $mimetype = $structure->real_mimetype;
         // parse headers from message/rfc822 part
         if (!isset($structure->headers['subject']) && !isset($structure->headers['from'])) {
             list($headers, ) = explode("\r\n\r\n", $this->get_part_body($structure->mime_id, false, 32768));
             $structure->headers = rcube_mime::parse_headers($headers);
         }
     } else {
         $mimetype = $structure->mimetype;
     }
     // show message headers
     if ($recursive && is_array($structure->headers) && (isset($structure->headers['subject']) || $structure->headers['from'] || $structure->headers['to'])) {
         $c = new stdClass();
         $c->type = 'headers';
         $c->headers = $structure->headers;
         $this->parts[] = $c;
     }
     // Allow plugins to handle message parts
     $plugin = $this->app->plugins->exec_hook('message_part_structure', array('object' => $this, 'structure' => $structure, 'mimetype' => $mimetype, 'recursive' => $recursive));
     if ($plugin['abort']) {
         return;
     }
     $structure = $plugin['structure'];
     list($message_ctype_primary, $message_ctype_secondary) = explode('/', $plugin['mimetype']);
     // print body if message doesn't have multiple parts
     if ($message_ctype_primary == 'text' && !$recursive) {
         // parts with unsupported type add to attachments list
         if (!in_array($message_ctype_secondary, array('plain', 'html', 'enriched'))) {
             $this->attachments[] = $structure;
             return;
         }
         $structure->type = 'content';
         $this->parts[] = $structure;
         // Parse simple (plain text) message body
         if ($message_ctype_secondary == 'plain') {
             foreach ((array) $this->uu_decode($structure) as $uupart) {
                 $this->mime_parts[$uupart->mime_id] = $uupart;
                 $this->attachments[] = $uupart;
             }
         }
     } else {
         if ($mimetype == 'application/pgp' && !$recursive) {
             $structure->type = 'content';
             $this->parts[] = $structure;
         } else {
             if ($mimetype == 'multipart/alternative' && is_array($structure->parts) && count($structure->parts) > 1) {
                 // get html/plaintext parts, other add to attachments list
                 foreach ($structure->parts as $p => $sub_part) {
                     $sub_mimetype = $sub_part->mimetype;
                     $is_multipart = preg_match('/^multipart\\/(related|relative|mixed|alternative)/', $sub_mimetype);
                     // skip empty text parts
                     if (!$sub_part->size && !$is_multipart) {
                         continue;
                     }
                     // We've encountered (malformed) messages with more than
                     // one text/plain or text/html part here. There's no way to choose
                     // which one is better, so we'll display first of them and add
                     // others as attachments (#1489358)
                     // check if sub part is
                     if ($is_multipart) {
                         $related_part = $p;
                     } else {
                         if ($sub_mimetype == 'text/plain' && !$plain_part) {
                             $plain_part = $p;
                         } else {
                             if ($sub_mimetype == 'text/html' && !$html_part) {
                                 $html_part = $p;
                                 $this->got_html_part = true;
                             } else {
                                 if ($sub_mimetype == 'text/enriched' && !$enriched_part) {
                                     $enriched_part = $p;
                                 } else {
                                     // add unsupported/unrecognized parts to attachments list
                                     $this->attachments[] = $sub_part;
                                 }
                             }
                         }
                     }
                 }
                 // parse related part (alternative part could be in here)
                 if ($related_part !== null && !$this->parse_alternative) {
                     $this->parse_alternative = true;
                     $this->parse_structure($structure->parts[$related_part], true);
                     $this->parse_alternative = false;
                     // if plain part was found, we should unset it if html is preferred
                     if ($this->opt['prefer_html'] && count($this->parts)) {
                         $plain_part = null;
                     }
                 }
                 // choose html/plain part to print
//.........这里部分代码省略.........
开发者ID:Bergdahls,项目名称:YetiForceCRM,代码行数:101,代码来源:rcube_message.php


注:本文中的rcube_mime::parse_headers方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。