alecpl
2011-06-27 68070e448c6c8cd09faa75fd70ff11bfea764cc1
program/include/rcube_imap.php
@@ -121,6 +121,13 @@
    function __construct()
    {
        $this->conn = new rcube_imap_generic();
        // Set namespace and delimiter from session,
        // so some methods would work before connection
        if (isset($_SESSION['imap_namespace']))
            $this->namespace = $_SESSION['imap_namespace'];
        if (isset($_SESSION['imap_delimiter']))
            $this->delimiter = $_SESSION['imap_delimiter'];
    }
@@ -549,12 +556,6 @@
    private function set_env()
    {
        if ($this->delimiter !== null && $this->namespace !== null) {
            return;
        }
        if (isset($_SESSION['imap_namespace']) && isset($_SESSION['imap_delimiter'])) {
            $this->namespace = $_SESSION['imap_namespace'];
            $this->delimiter = $_SESSION['imap_delimiter'];
            return;
        }
@@ -3232,7 +3233,7 @@
        // try to subscribe it
        if ($result) {
            // clear cache
            $this->clear_cache('/^mailboxes.*/', true);
            $this->clear_cache('mailboxes', true);
            if ($subscribe)
                $this->subscribe($mailbox);
@@ -3288,7 +3289,7 @@
            // clear cache
            $this->clear_message_cache($mailbox.'.msg');
            $this->clear_cache('/^mailboxes.*/', true);
            $this->clear_cache('mailboxes', true);
        }
        return $result;
@@ -3330,7 +3331,7 @@
            // clear mailbox-related cache
            $this->clear_message_cache($mailbox.'.msg');
            $this->clear_cache('/^mailboxes.*/', true);
            $this->clear_cache('mailboxes', true);
        }
        return $result;
@@ -3485,6 +3486,64 @@
        $opts = $this->conn->data['LIST'][$mailbox];
        return is_array($opts) ? $opts : array();
    }
    /**
     * Returns extended information about the folder
     *
     * @param string $mailbox Folder name
     *
     * @return array Data
     */
    function mailbox_info($mailbox)
    {
        $acl       = $this->get_capability('ACL');
        $namespace = $this->get_namespace();
        $options   = array();
        // check if the folder is a namespace prefix
        if (!empty($namespace)) {
            $mbox = $mailbox . $this->delimiter;
            foreach ($namespace as $ns) {
                if (!empty($ns)) {
                    foreach ($ns as $item) {
                        if ($item[0] === $mbox) {
                            $options['is_root'] = true;
                            break;
                        }
                    }
                }
            }
        }
        $options['name']      = $mailbox;
        $options['options']   = $this->mailbox_options($mailbox, true);
        $options['namespace'] = $this->mailbox_namespace($mailbox);
        $options['rights']    = $acl && !$options['is_root'] ? (array)$this->my_rights($mailbox) : array();
        $options['special']   = in_array($mailbox, $this->default_folders);
        if (is_array($options['options'])) {
            foreach ($options['options'] as $opt) {
                $opt = strtolower($opt);
                if ($opt == '\noselect' || $opt == '\nonexistent') {
                    $options['noselect'] = true;
                }
            }
        }
        else {
            $options['noselect'] = true;
        }
        if (!empty($options['rights'])) {
            $options['norename'] = !in_array('x', $options['rights']) &&
                (!in_array('c', $options['rights']) || !in_array('d', $options['rights']));
            if (!$options['noselect']) {
                $options['noselect'] = !in_array('r', $options['rights']);
            }
        }
        return $options;
    }
@@ -3738,7 +3797,7 @@
    /**
     * Enable or disable indexes caching
     *
     * @param boolean $type Cache type (memcache' or 'db')
     * @param boolean $type Cache type (@see rcmail::get_cache)
     * @access public
     */
    function set_caching($type)
@@ -3786,15 +3845,15 @@
    /**
     * Clears the cache.
     *
     * @param string  $key          Cache key name or pattern
     * @param boolean $pattern_mode Enable it to clear all keys with name
     *                              matching PREG pattern in $key
     * @param string  $key         Cache key name or pattern
     * @param boolean $prefix_mode Enable it to clear all keys starting
     *                             with prefix specified in $key
     * @access public
     */
    function clear_cache($key=null, $pattern_mode=false)
    function clear_cache($key=null, $prefix_mode=false)
    {
        if ($this->cache) {
            $this->cache->remove($key, $pattern_mode);
            $this->cache->remove($key, $prefix_mode);
        }
    }
@@ -4583,20 +4642,9 @@
                    $updated = $this->conn->unsubscribe($mailbox);
            }
        // get cached mailbox list
        // clear cached mailbox list(s)
        if ($updated) {
            $a_mailbox_cache = $this->get_cache('mailboxes');
            if (!is_array($a_mailbox_cache))
                return $updated;
            // modify cached list
            if ($mode == 'subscribe')
                $a_mailbox_cache = array_merge($a_mailbox_cache, $a_mboxes);
            else if ($mode == 'unsubscribe')
                $a_mailbox_cache = array_diff($a_mailbox_cache, $a_mboxes);
            // write mailboxlist to cache
            $this->update_cache('mailboxes', $this->_sort_mailbox_list($a_mailbox_cache));
            $this->clear_cache('mailboxes', true);
        }
        return $updated;