Aleksander Machniak
2012-05-21 9a2de8411ecb66e3df2fae5e65f0251b7c25173f
Merge branch 'courier-fix'

Conflicts:
CHANGELOG
5 files modified
130 ■■■■■ changed files
CHANGELOG 1 ●●●● patch | view | raw | blame | history
config/main.inc.php.dist 4 ●●●● patch | view | raw | blame | history
plugins/subscriptions_option/package.xml 4 ●●●● patch | view | raw | blame | history
plugins/subscriptions_option/subscriptions_option.php 7 ●●●● patch | view | raw | blame | history
program/include/rcube_imap.php 114 ●●●●● patch | view | raw | blame | history
CHANGELOG
@@ -1,6 +1,7 @@
CHANGELOG Roundcube Webmail
===========================
- Fix listing shared folders on Courier IMAP (#1488466)
- Fix issue where draft auto-save wasn't executed after some inactivity time
- Add vCard import from multiple files at once (#1488015)
- Roundcube Framework:
config/main.inc.php.dist
@@ -106,6 +106,10 @@
// Enable this option to force LSUB command usage instead.
$rcmail_config['imap_force_lsub'] = false;
// Some server configurations (e.g. Courier) doesn't list folders in all namespaces
// Enable this option to force listing of folders in all namespaces
$rcmail_config['imap_force_ns'] = false;
// IMAP connection timeout, in seconds. Default: 0 (no limit)
$rcmail_config['imap_timeout'] = 0;
plugins/subscriptions_option/package.xml
@@ -23,9 +23,9 @@
        <email>ziba@umich.edu</email>
        <active>yes</active>
    </developer>
    <date>2012-03-05</date>
    <date>2012-05-21</date>
    <version>
        <release>1.2</release>
        <release>1.3</release>
        <api>1.1</api>
    </version>
    <stability>
plugins/subscriptions_option/subscriptions_option.php
@@ -74,12 +74,9 @@
    function mailboxes_list($args)
    {
        $rcmail  = rcmail::get_instance();
        $rcmail = rcmail::get_instance();
        if (!$rcmail->config->get('use_subscriptions', true)) {
            $storage = $rcmail->get_storage();
            if ($storage->check_connection()) {
                $args['folders'] = $storage->conn->listMailboxes($args['root'], $args['name']);
            }
            $args['folders'] = $rcmail->get_storage()->list_folders_direct();
        }
        return $args;
    }
program/include/rcube_imap.php
@@ -2524,11 +2524,27 @@
        // Server supports LIST-EXTENDED, we can use selection options
        // #1486225: Some dovecot versions returns wrong result using LIST-EXTENDED
        if (!$config->get('imap_force_lsub') && $this->get_capability('LIST-EXTENDED')) {
        $list_extended = !$config->get('imap_force_lsub') && $this->get_capability('LIST-EXTENDED');
        if ($list_extended) {
            // This will also set folder options, LSUB doesn't do that
            $a_folders = $this->conn->listMailboxes($root, $name,
                NULL, array('SUBSCRIBED'));
        }
        else {
            // retrieve list of folders from IMAP server using LSUB
            $a_folders = $this->conn->listSubscribed($root, $name);
        }
        if (!is_array($a_folders)) {
            return array();
        }
        // #1486796: some server configurations doesn't return folders in all namespaces
        if ($root == '' && $name == '*' && $config->get('imap_force_ns')) {
            $this->list_folders_update($a_folders, ($list_extended ? 'ext-' : '') . 'subscribed');
        }
        if ($list_extended) {
            // unsubscribe non-existent folders, remove from the list
            // we can do this only when LIST response is available
            if (is_array($a_folders) && $name == '*' && !empty($this->conn->data['LIST'])) {
@@ -2542,10 +2558,7 @@
                }
            }
        }
        // retrieve list of folders from IMAP server using LSUB
        else {
            $a_folders = $this->conn->listSubscribed($root, $name);
            // unsubscribe non-existent folders, remove them from the list,
            // we can do this only when LIST response is available
            if (is_array($a_folders) && $name == '*' && !empty($this->conn->data['LIST'])) {
@@ -2561,10 +2574,6 @@
                    }
                }
            }
        }
        if (!is_array($a_folders) || !sizeof($a_folders)) {
            $a_folders = array();
        }
        return $a_folders;
@@ -2661,50 +2670,69 @@
            return array();
        }
        // #1486796: some server configurations doesn't
        // return folders in all namespaces, we'll try to detect that situation
        // and ask for these namespaces separately
        if ($root == '' && $name == '*') {
            $delim     = $this->get_hierarchy_delimiter();
            $namespace = $this->get_namespace();
            $search    = array();
        // #1486796: some server configurations doesn't return folders in all namespaces
        if ($root == '' && $name == '*' && $config->get('imap_force_ns')) {
            $this->list_folders_update($result);
        }
            // build list of namespace prefixes
            foreach ((array)$namespace as $ns) {
                if (is_array($ns)) {
                    foreach ($ns as $ns_data) {
                        if (strlen($ns_data[0])) {
                            $search[] = $ns_data[0];
                        }
                    }
                }
            }
        return $result;
    }
            if (!empty($search)) {
                // go through all folders detecting namespace usage
                foreach ($result as $folder) {
                    foreach ($search as $idx => $prefix) {
                        if (strpos($folder, $prefix) === 0) {
                            unset($search[$idx]);
                        }
                    }
                    if (empty($search)) {
                        break;
                    }
                }
                // get folders in hidden namespaces and add to the result
                foreach ($search as $prefix) {
                    $list = $this->conn->listMailboxes($prefix, $name);
    /**
     * Fix folders list by adding folders from other namespaces.
     * Needed on some servers eg. Courier IMAP
     *
     * @param array  $result  Reference to folders list
     * @param string $type    Listing type (ext-subscribed, subscribed or all)
     */
    private function list_folders_update(&$result, $type = null)
    {
        $delim     = $this->get_hierarchy_delimiter();
        $namespace = $this->get_namespace();
        $search    = array();
                    if (!empty($list)) {
                        $result = array_merge($result, $list);
        // build list of namespace prefixes
        foreach ((array)$namespace as $ns) {
            if (is_array($ns)) {
                foreach ($ns as $ns_data) {
                    if (strlen($ns_data[0])) {
                        $search[] = $ns_data[0];
                    }
                }
            }
        }
        return $result;
        if (!empty($search)) {
            // go through all folders detecting namespace usage
            foreach ($result as $folder) {
                foreach ($search as $idx => $prefix) {
                    if (strpos($folder, $prefix) === 0) {
                        unset($search[$idx]);
                    }
                }
                if (empty($search)) {
                    break;
                }
            }
            // get folders in hidden namespaces and add to the result
            foreach ($search as $prefix) {
                if ($type == 'ext-subscribed') {
                    $list = $this->conn->listMailboxes('', $prefix . '*', null, array('SUBSCRIBED'));
                }
                else if ($type == 'subscribed') {
                    $list = $this->conn->listSubscribed('', $prefix . '*');
                }
                else {
                    $list = $this->conn->listMailboxes('', $prefix . '*');
                }
                if (!empty($list)) {
                    $result = array_merge($result, $list);
                }
            }
        }
    }