From f91f8533678c388b879d9e999a6bcc9e22ad7e19 Mon Sep 17 00:00:00 2001 From: Hugues Hiegel Date: Tue, 5 Aug 2014 16:44:07 +0200 Subject: lot of stuff --- program/lib/Roundcube/rcube_message.php | 128 ++++++++++++-------------------- 1 file changed, 48 insertions(+), 80 deletions(-) (limited to 'program/lib/Roundcube/rcube_message.php') diff --git a/program/lib/Roundcube/rcube_message.php b/program/lib/Roundcube/rcube_message.php index 9b662a286..a8bcf6afc 100644 --- a/program/lib/Roundcube/rcube_message.php +++ b/program/lib/Roundcube/rcube_message.php @@ -168,11 +168,10 @@ class rcube_message * @param resource $fp File pointer to save the message part * @param boolean $skip_charset_conv Disables charset conversion * @param int $max_bytes Only read this number of bytes - * @param boolean $formatted Enables formatting of text/* parts bodies * * @return string Part content */ - public function get_part_content($mime_id, $fp = null, $skip_charset_conv = false, $max_bytes = 0, $formatted = true) + public function get_part_content($mime_id, $fp = null, $skip_charset_conv = false, $max_bytes = 0) { if ($part = $this->mime_parts[$mime_id]) { // stored in message structure (winmail/inline-uuencode) @@ -186,88 +185,47 @@ class rcube_message // get from IMAP $this->storage->set_folder($this->folder); - return $this->storage->get_message_part($this->uid, $mime_id, $part, - NULL, $fp, $skip_charset_conv, $max_bytes, $formatted); + return $this->storage->get_message_part($this->uid, $mime_id, $part, NULL, $fp, $skip_charset_conv, $max_bytes); } } /** - * Determine if the message contains a HTML part. This must to be - * a real part not an attachment (or its part) + * Determine if the message contains a HTML part * - * @param bool $enriched Enables checking for text/enriched parts too + * @param bool $recursive Enables checking in all levels of the structure + * @param bool $enriched Enables checking for text/enriched parts too * * @return bool True if a HTML is available, False if not */ - function has_html_part($enriched = false) + function has_html_part($recursive = true, $enriched = false) { // check all message parts - foreach ($this->mime_parts as $part) { + foreach ($this->parts as $part) { if ($part->mimetype == 'text/html' || ($enriched && $part->mimetype == 'text/enriched')) { - // Skip if part is an attachment, don't use is_attachment() here - if ($part->filename) { - continue; - } - - $level = explode('.', $part->mime_id); + // Level check, we'll skip e.g. HTML attachments + if (!$recursive) { + $level = explode('.', $part->mime_id); - // Check if the part belongs to higher-level's multipart part - // this can be alternative/related/signed/encrypted, but not mixed - while (array_pop($level) !== null) { - if (!count($level)) { - return true; - } - - $parent = $this->mime_parts[join('.', $level)]; - if (!preg_match('/^multipart\/(alternative|related|signed|encrypted)$/', $parent->mimetype)) { - continue 2; + // Skip if part is an attachment + if ($this->is_attachment($part)) { + continue; } - } - - if ($part->size) { - return true; - } - } - } - - return false; - } - - - /** - * Determine if the message contains a text/plain part. This must to be - * a real part not an attachment (or its part) - * - * @return bool True if a plain text part is available, False if not - */ - function has_text_part() - { - // check all message parts - foreach ($this->mime_parts as $part) { - if ($part->mimetype == 'text/plain') { - // Skip if part is an attachment, don't use is_attachment() here - if ($part->filename) { - continue; - } - - $level = explode('.', $part->mime_id); - // Check if the part belongs to higher-level's alternative/related - while (array_pop($level) !== null) { - if (!count($level)) { - return true; - } + // 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)]; - if ($parent->mimetype != 'multipart/alternative' && $parent->mimetype != 'multipart/related') { - continue 2; + $parent = $this->mime_parts[join('.', $level)]; + if ($parent->mimetype != 'multipart/alternative' && $parent->mimetype != 'multipart/related') { + continue 2; + } } } - if ($part->size) { - return true; - } + return true; } } @@ -362,8 +320,8 @@ class rcube_message $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_content($structure->mime_id, null, true, 32768)); + if (!isset($structure->headers['subject'])) { + list($headers, $dump) = explode("\r\n\r\n", $this->get_part_content($structure->mime_id, null, true, 32768)); $structure->headers = rcube_mime::parse_headers($headers); } } @@ -372,7 +330,7 @@ class rcube_message // show message headers if ($recursive && is_array($structure->headers) && - (isset($structure->headers['subject']) || $structure->headers['from'] || $structure->headers['to'])) { + ($structure->headers['subject'] || $structure->headers['from'] || $structure->headers['to'])) { $c = new stdClass; $c->type = 'headers'; $c->headers = $structure->headers; @@ -434,24 +392,17 @@ class rcube_message 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) + else if ($sub_mimetype == 'text/plain') $plain_part = $p; - else if ($sub_mimetype == 'text/html' && !$html_part) + else if ($sub_mimetype == 'text/html') $html_part = $p; - else if ($sub_mimetype == 'text/enriched' && !$enriched_part) + else if ($sub_mimetype == 'text/enriched') $enriched_part = $p; - else { - // add unsupported/unrecognized parts to attachments list - $this->attachments[] = $sub_part; - } + else + $attach_part = $p; } // parse related part (alternative part could be in here) @@ -492,6 +443,19 @@ class rcube_message $this->parts[] = $c; } + + // add html part as attachment + if ($html_part !== null && $structure->parts[$html_part] !== $print_part) { + $html_part = $structure->parts[$html_part]; + $html_part->mimetype = 'text/html'; + + $this->attachments[] = $html_part; + } + + // add unsupported/unrecognized parts to attachments list + if ($attach_part) { + $this->attachments[] = $structure->parts[$attach_part]; + } } // this is an ecrypted message -> create a plaintext body with the according message else if ($mimetype == 'multipart/encrypted') { @@ -572,6 +536,10 @@ class rcube_message if (!empty($mail_part->filename)) { $this->attachments[] = $mail_part; } + // list html part as attachment (here the part is most likely inside a multipart/related part) + else if ($this->parse_alternative && ($secondary_type == 'html' && !$this->opt['prefer_html'])) { + $this->attachments[] = $mail_part; + } } // part message/* else if ($primary_type == 'message') { -- cgit v1.2.3