alecpl
2010-06-04 f22b5439f2e783f47f61042bebb6cc53672568fd
program/include/rcube_imap.php
@@ -472,7 +472,6 @@
            // get message count and store in cache
            if ($mode == 'UNSEEN')
                $search_str .= " UNSEEN";
            // get message count using SEARCH
            // not very performant but more precise (using UNDELETED)
            // disable THREADS for this request
@@ -823,8 +822,11 @@
            return $this->_list_thread_header_set($mailbox, $page, $sort_field, $sort_order, $slice);
        // search set is threaded, we need a new one
        if ($this->search_threads)
        if ($this->search_threads) {
            if (empty($this->search_set['tree']))
                return array();
            $this->search('', $this->search_string, $this->search_charset, $sort_field);
        }
        $msgs = $this->search_set;
        $a_msg_headers = array();
@@ -946,8 +948,15 @@
    private function _list_thread_header_set($mailbox, $page=NULL, $sort_field=NULL, $sort_order=NULL, $slice=0)
    {
        // update search_set if previous data was fetched with disabled threading
        if (!$this->search_threads)
        if (!$this->search_threads) {
            if (empty($this->search_set))
                return array();
            $this->search('', $this->search_string, $this->search_charset, $sort_field);
        }
        // empty result
        if (empty($this->search_set['tree']))
            return array();
        $thread_tree = $this->search_set['tree'];
        $msg_depth = $this->search_set['depth'];
@@ -2034,7 +2043,7 @@
            return true;
        // convert charset (if text or message part)
        if ($o_part->ctype_primary=='text' || $o_part->ctype_primary=='message') {
        if ($o_part->ctype_primary == 'text' || $o_part->ctype_primary == 'message') {
            // assume default if no charset specified
            if (empty($o_part->charset) || strtolower($o_part->charset) == 'us-ascii')
                $o_part->charset = $this->default_charset;
@@ -2512,7 +2521,7 @@
     * --------------------------------*/
    /**
     * Public method for mailbox listing.
     * Public method for listing subscribed folders
     *
     * Converts mailbox name with root dir first
     *
@@ -2552,16 +2561,16 @@
     */
    private function _list_mailboxes($root='', $filter='*')
    {
        $a_defaults = $a_out = array();
        // get cached folder list
        $a_mboxes = $this->get_cache('mailboxes');
        if (is_array($a_mboxes))
            return $a_mboxes;
        $a_defaults = $a_out = array();
        // Give plugins a chance to provide a list of mailboxes
        $data = rcmail::get_instance()->plugins->exec_hook('list_mailboxes',
            array('root'=>$root,'filter'=>$filter));
            array('root' => $root, 'filter' => $filter, 'mode' => 'LSUB'));
        if (isset($data['folders'])) {
            $a_folders = $data['folders'];
@@ -2585,17 +2594,26 @@
     * Get a list of all folders available on the IMAP server
     *
     * @param string IMAP root dir
     * @param string Optional filter for mailbox listing
     * @return array Indexed array with folder names
     */
    function list_unsubscribed($root='')
    function list_unsubscribed($root='', $filter='*')
    {
        static $a_folders;
        // Give plugins a chance to provide a list of mailboxes
        $data = rcmail::get_instance()->plugins->exec_hook('list_mailboxes',
            array('root' => $root, 'filter' => $filter, 'mode' => 'LIST'));
        if (is_array($a_folders))
            return $a_folders;
        // retrieve list of folders from IMAP server
        $a_mboxes = $this->conn->listMailboxes($this->mod_mailbox($root), '*');
        if (isset($data['folders'])) {
            $a_mboxes = $data['folders'];
        }
        else {
            // retrieve list of folders from IMAP server
            $a_mboxes = $this->conn->listMailboxes($this->mod_mailbox($root), $filter);
        }
        $a_folders = array();
        if (!is_array($a_mboxes))
            $a_mboxes = array();
        // modify names with root dir
        foreach ($a_mboxes as $idx => $mbox_name) {
@@ -3370,43 +3388,6 @@
        }
        return $out;
    }
    /**
     * Decode a Microsoft Outlook TNEF part (winmail.dat)
     *
     * @param object rcube_message_part Message part to decode
     * @param string UID of the message
     * @return array List of rcube_message_parts extracted from windmail.dat
     */
    function tnef_decode(&$part, $uid)
    {
        if (!isset($part->body))
            $part->body = $this->get_message_part($uid, $part->mime_id, $part);
        require_once('lib/tnef_decoder.inc');
        $pid = 0;
        $tnef_parts = array();
        $tnef_arr = tnef_decode($part->body);
        foreach ($tnef_arr as $winatt) {
            $tpart = new rcube_message_part;
            $tpart->filename = trim($winatt['name']);
            $tpart->encoding = 'stream';
            $tpart->ctype_primary = trim(strtolower($winatt['type0']));
            $tpart->ctype_secondary = trim(strtolower($winatt['type1']));
            $tpart->mimetype = $tpart->ctype_primary . '/' . $tpart->ctype_secondary;
            $tpart->mime_id = "winmail." . $part->mime_id . ".$pid";
            $tpart->size = $winatt['size'];
            $tpart->body = $winatt['stream'];
            $tnef_parts[] = $tpart;
            $pid++;
        }
        return $tnef_parts;
    }