| | |
| | | if (!empty($this->headers->structure)) { |
| | | $this->get_mime_numbers($this->headers->structure); |
| | | $this->parse_structure($this->headers->structure); |
| | | $this->parse_attachments(); |
| | | } |
| | | else { |
| | | $this->body = $this->storage->get_body($uid); |
| | |
| | | if (!$recursive) { |
| | | $level = explode('.', $part->mime_id); |
| | | |
| | | // Skip if level too deep or part has a file name |
| | | if (count($level) > 2 || $part->filename) { |
| | | // Skip if part is an attachment |
| | | if ($this->is_attachment($part)) { |
| | | continue; |
| | | } |
| | | |
| | | // HTML part can be on the lower level, if not... |
| | | if (count($level) > 1) { |
| | | array_pop($level); |
| | | // Check if the part belongs to higher-level's alternative/related |
| | | while (array_pop($level) !== null) { |
| | | if (!count($level)) { |
| | | return true; |
| | | } |
| | | |
| | | $parent = $this->mime_parts[join('.', $level)]; |
| | | // ... parent isn't multipart/alternative or related |
| | | if ($parent->mimetype != 'multipart/alternative' && $parent->mimetype != 'multipart/related') { |
| | | continue; |
| | | continue 2; |
| | | } |
| | | } |
| | | } |
| | |
| | | $out = $this->get_part_content($mime_id); |
| | | |
| | | // create instance of html2text class |
| | | $txt = new html2text($out); |
| | | $txt = new rcube_html2text($out); |
| | | return $txt->get_text(); |
| | | } |
| | | } |
| | |
| | | |
| | | // parse headers from message/rfc822 part |
| | | if (!isset($structure->headers['subject'])) { |
| | | list($headers, $dump) = explode("\r\n\r\n", $this->get_part_content($structure->mime_id, null, true, 4096)); |
| | | list($headers, $dump) = explode("\r\n\r\n", $this->get_part_content($structure->mime_id, null, true, 8192)); |
| | | $structure->headers = rcube_mime::parse_headers($headers); |
| | | } |
| | | } |
| | |
| | | // get html/plaintext parts, other add to attachments list |
| | | foreach ($structure->parts as $p => $sub_part) { |
| | | $sub_mimetype = $sub_part->mimetype; |
| | | $is_multipart = in_array($sub_mimetype, array('multipart/related', 'multipart/mixed', 'multipart/alternative')); |
| | | $is_multipart = preg_match('/^multipart\/(related|relative|mixed|alternative)/', $sub_mimetype); |
| | | |
| | | // skip empty text parts |
| | | if (!$sub_part->size && !$is_multipart) { |
| | |
| | | $p->ctype_secondary = 'plain'; |
| | | $p->mimetype = 'text/plain'; |
| | | $p->realtype = 'multipart/encrypted'; |
| | | |
| | | $this->parts[] = $p; |
| | | } |
| | | // this is an S/MIME ecrypted message -> create a plaintext body with the according message |
| | | else if ($mimetype == 'application/pkcs7-mime') { |
| | | $p = new stdClass; |
| | | $p->type = 'content'; |
| | | $p->ctype_primary = 'text'; |
| | | $p->ctype_secondary = 'plain'; |
| | | $p->mimetype = 'text/plain'; |
| | | $p->realtype = 'application/pkcs7-mime'; |
| | | |
| | | $this->parts[] = $p; |
| | | } |
| | |
| | | continue; |
| | | |
| | | // part belongs to a related message and is linked |
| | | if ($mimetype == 'multipart/related' |
| | | if (preg_match('/^multipart\/(related|relative)/', $mimetype) |
| | | && ($mail_part->headers['content-id'] || $mail_part->headers['content-location'])) { |
| | | if ($mail_part->headers['content-id']) |
| | | $mail_part->content_id = preg_replace(array('/^</', '/>$/'), '', $mail_part->headers['content-id']); |
| | |
| | | } |
| | | |
| | | // if this was a related part try to resolve references |
| | | if ($mimetype == 'multipart/related' && sizeof($this->inline_parts)) { |
| | | if (preg_match('/^multipart\/(related|relative)/', $mimetype) && sizeof($this->inline_parts)) { |
| | | $a_replaces = array(); |
| | | $img_regexp = '/^image\/(gif|jpe?g|png|tiff|bmp|svg)/'; |
| | | |
| | |
| | | // message is a single part non-text (without filename) |
| | | else if (preg_match('/application\//i', $mimetype)) { |
| | | $this->attachments[] = $structure; |
| | | } |
| | | } |
| | | |
| | | |
| | | /** |
| | | * Parse attachment parts |
| | | */ |
| | | private function parse_attachments() |
| | | { |
| | | // Attachment must have a name |
| | | foreach ($this->attachments as $attachment) { |
| | | if (!$attachment->filename) { |
| | | $ext = rcube_mime::get_mime_extensions($attachment->mimetype); |
| | | $ext = array_shift($ext); |
| | | |
| | | $attachment->filename = 'Part_' . $attachment->mime_id; |
| | | if ($ext) { |
| | | $attachment->filename .= '.' . $ext; |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |