Thomas Bruederli
2012-10-27 ddafe4e4109a8d6d412c3c138412ee2ca3d58dbf
program/include/rcube_message.php
@@ -17,9 +17,6 @@
 +-----------------------------------------------------------------------+
 | Author: Thomas Bruederli <roundcube@gmail.com>                        |
 +-----------------------------------------------------------------------+
 $Id$
*/
@@ -53,13 +50,14 @@
     */
    private $mime;
    private $opt = array();
    private $inline_parts = array();
    private $parse_alternative = false;
    public $uid = null;
    public $uid;
    public $folder;
    public $headers;
    public $parts = array();
    public $mime_parts = array();
    public $inline_parts = array();
    public $attachments = array();
    public $subject = '';
    public $sender = null;
@@ -71,16 +69,21 @@
     *
     * Provide a uid, and parse message structure.
     *
     * @param string $uid The message UID.
     * @param string $uid    The message UID.
     * @param string $folder Folder name
     *
     * @see self::$app, self::$storage, self::$opt, self::$parts
     */
    function __construct($uid)
    function __construct($uid, $folder = null)
    {
        $this->uid  = $uid;
        $this->app  = rcube::get_instance();
        $this->storage = $this->app->get_storage();
        $this->folder  = strlen($folder) ? $folder : $this->storage->get_folder();
        $this->storage->set_options(array('all_headers' => true));
        // Set current folder
        $this->storage->set_folder($this->folder);
        $this->headers = $this->storage->get_message($uid);
@@ -182,10 +185,12 @@
                }
                return $fp ? true : $part->body;
            }
            // 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);
        } else
            return null;
        }
    }
@@ -205,15 +210,16 @@
                if (!$recursive) {
                    $level = explode('.', $part->mime_id);
                    // Level too high
                    if (count($level) > 2) {
                    // Skip if level too deep or part has a file name
                    if (count($level) > 2 || $part->filename) {
                        continue;
                    }
                    // HTML part can be on the lower level, if not...
                    if (count($level) > 1) {
                        // It can be an alternative or related message part
                        $parent = $this->mime_parts[0];
                        array_pop($level);
                        $parent = $this->mime_parts[join('.', $level)];
                        // ... parent isn't multipart/alternative or related
                        if ($parent->mimetype != 'multipart/alternative' && $parent->mimetype != 'multipart/related') {
                            continue;
                        }
@@ -280,6 +286,32 @@
    /**
     * Checks if part of the message is an attachment (or part of it)
     *
     * @param rcube_message_part $part Message part
     *
     * @return bool True if the part is an attachment part
     */
    public function is_attachment($part)
    {
        foreach ($this->attachments as $att_part) {
            if ($att_part->mime_id == $part->mime_id) {
                return true;
            }
            // check if the part is a subpart of another attachment part (message/rfc822)
            if ($att_part->mimetype == 'message/rfc822') {
                if (in_array($part, (array)$att_part->parts)) {
                    return true;
                }
            }
        }
        return false;
    }
    /**
     * Read the message structure returend by the IMAP server
     * and build flat lists of content parts and attachments
     *
@@ -339,6 +371,11 @@
            foreach ($structure->parts as $p => $sub_part) {
                $sub_mimetype = $sub_part->mimetype;
                // skip empty text parts
                if (!$sub_part->size && preg_match('#^text/(plain|html|enriched)$#', $sub_mimetype)) {
                    continue;
                }
                // check if sub part is
                if ($sub_mimetype == 'text/plain')
@@ -463,8 +500,13 @@
                    }
                    // list as attachment as well
                    if (!empty($mail_part->filename))
                    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') {
@@ -614,8 +656,10 @@
    function tnef_decode(&$part)
    {
        // @TODO: attachment may be huge, hadle it via file
        if (!isset($part->body))
        if (!isset($part->body)) {
            $this->storage->set_folder($this->folder);
            $part->body = $this->storage->get_message_part($this->uid, $part->mime_id, $part);
        }
        $parts = array();
        $tnef = new tnef_decoder;
@@ -650,8 +694,10 @@
    function uu_decode(&$part)
    {
        // @TODO: messages may be huge, hadle body via file
        if (!isset($part->body))
        if (!isset($part->body)) {
            $this->storage->set_folder($this->folder);
            $part->body = $this->storage->get_message_part($this->uid, $part->mime_id, $part);
        }
        $parts = array();
        // FIXME: line length is max.65?