| | |
| | | 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); |
| | |
| | | $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); |
| | | } |
| | | } |
| | |
| | | |
| | | // 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') |
| | | if ($message_ctype_secondary == 'plain') { |
| | | foreach ((array)$this->uu_decode($structure) as $uupart) { |
| | | $this->mime_parts[$uupart->mime_id] = $uupart; |
| | | $this->attachments[] = $uupart; |
| | | } |
| | | } |
| | | } |
| | | // the same for pgp signed messages |
| | | else if ($mimetype == 'application/pgp' && !$recursive) { |
| | |
| | | // 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) { |
| | |
| | | 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; |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |