Esempio n. 1
0
 /**
  * Fetch body structure from the IMAP server and build
  * an object structure similar to the one generated by PEAR::Mail_mimeDecode
  *
  * @param int    $uid           Message UID to fetch
  * @param string $structure_str Message BODYSTRUCTURE string (optional)
  * @return object rcube_message_part Message part tree or False on failure
  */
 function &get_structure($uid, $structure_str = '')
 {
     $cache_key = $this->mailbox . '.msg';
     $headers =& $this->get_cached_message($cache_key, $uid);
     // return cached message structure
     if (is_object($headers) && is_object($headers->structure)) {
         return $headers->structure;
     }
     if (!$structure_str) {
         $structure_str = $this->conn->fetchStructureString($this->mailbox, $uid, true);
     }
     $structure = rcube_mime_struct::parseStructure($structure_str);
     $struct = false;
     // parse structure and add headers
     if (!empty($structure)) {
         $headers = $this->get_headers($uid);
         $this->_msg_id = $headers->id;
         // set message charset from message headers
         if ($headers->charset) {
             $this->struct_charset = $headers->charset;
         } else {
             $this->struct_charset = $this->_structure_charset($structure);
         }
         $headers->ctype = strtolower($headers->ctype);
         // Here we can recognize malformed BODYSTRUCTURE and
         // 1. [@TODO] parse the message in other way to create our own message structure
         // 2. or just show the raw message body.
         // Example of structure for malformed MIME message:
         // ("text" "plain" NIL NIL NIL "7bit" 2154 70 NIL NIL NIL)
         if ($headers->ctype && !is_array($structure[0]) && $headers->ctype != 'text/plain' && strtolower($structure[0] . '/' . $structure[1]) == 'text/plain') {
             // we can handle single-part messages, by simple fix in structure (#1486898)
             if (preg_match('/^(text|application)\\/(.*)/', $headers->ctype, $m)) {
                 $structure[0] = $m[1];
                 $structure[1] = $m[2];
             } else {
                 return false;
             }
         }
         $struct =& $this->_structure_part($structure, 0, '', $headers);
         $struct->headers = get_object_vars($headers);
         // don't trust given content-type
         if (empty($struct->parts) && !empty($struct->headers['ctype'])) {
             $struct->mime_id = '1';
             $struct->mimetype = strtolower($struct->headers['ctype']);
             list($struct->ctype_primary, $struct->ctype_secondary) = explode('/', $struct->mimetype);
         }
         // write structure to cache
         if ($this->caching_enabled) {
             $this->add_message_cache($cache_key, $this->_msg_id, $headers, $struct, $this->icache['message.id'][$uid], true);
         }
     }
     return $struct;
 }
Esempio n. 2
0
 /**
  * Fetch body structure from the IMAP server and build
  * an object structure similar to the one generated by PEAR::Mail_mimeDecode
  *
  * @param int Message UID to fetch
  * @param string Message BODYSTRUCTURE string (optional)
  * @return object rcube_message_part Message part tree or False on failure
  */
 function &get_structure($uid, $structure_str = '')
 {
     $cache_key = $this->mailbox . '.msg';
     $headers =& $this->get_cached_message($cache_key, $uid);
     // return cached message structure
     if (is_object($headers) && is_object($headers->structure)) {
         return $headers->structure;
     }
     if (!$structure_str) {
         $structure_str = $this->conn->fetchStructureString($this->mailbox, $uid, true);
     }
     $structure = rcube_mime_struct::parseStructure($structure_str);
     $struct = false;
     // parse structure and add headers
     if (!empty($structure)) {
         $headers = $this->get_headers($uid);
         $this->_msg_id = $headers->id;
         // set message charset from message headers
         if ($headers->charset) {
             $this->struct_charset = $headers->charset;
         } else {
             $this->struct_charset = $this->_structure_charset($structure);
         }
         // Here we can recognize malformed BODYSTRUCTURE and
         // 1. [@TODO] parse the message in other way to create our own message structure
         // 2. or just show the raw message body.
         // Example of structure for malformed MIME message:
         // ("text" "plain" ("charset" "us-ascii") NIL NIL "7bit" 2154 70 NIL NIL NIL)
         if ($headers->ctype && $headers->ctype != 'text/plain' && $structure[0] == 'text' && $structure[1] == 'plain') {
             return false;
         }
         $struct =& $this->_structure_part($structure);
         $struct->headers = get_object_vars($headers);
         // don't trust given content-type
         if (empty($struct->parts) && !empty($struct->headers['ctype'])) {
             $struct->mime_id = '1';
             $struct->mimetype = strtolower($struct->headers['ctype']);
             list($struct->ctype_primary, $struct->ctype_secondary) = explode('/', $struct->mimetype);
         }
         // write structure to cache
         if ($this->caching_enabled) {
             $this->add_message_cache($cache_key, $this->_msg_id, $headers, $struct);
         }
     }
     return $struct;
 }