alecpl
2010-10-25 fc7a41f75e7a3c8b0b3b8ada633172daa6a67931
- Small improvements in NAMESPACE handling


1 files modified
78 ■■■■■ changed files
program/include/rcube_imap_generic.php 78 ●●●●● patch | view | raw | blame | history
program/include/rcube_imap_generic.php
@@ -534,24 +534,24 @@
        return $code;
    }
    function getNamespace()
    function getRootDir()
    {
        if (isset($this->prefs['rootdir']) && is_string($this->prefs['rootdir'])) {
            $this->rootdir = $this->prefs['rootdir'];
            return true;
        }
        if (!is_array($data = $this->_namespace())) {
        if (!is_array($data = $this->getNamespace())) {
            return false;
        }
        $user_space_data = $data[0];
        $user_space_data = $data['personal'];
        if (!is_array($user_space_data)) {
            return false;
        }
        $first_userspace = $user_space_data[0];
        if (count($first_userspace)!=2) {
        if (count($first_userspace) !=2 ) {
            return false;
        }
@@ -562,7 +562,6 @@
        return true;
    }
    /**
     * Gets the delimiter, for example:
@@ -598,12 +597,12 @@
        // if that fails, try namespace extension
        // try to fetch namespace data
        if (!is_array($data = $this->_namespace())) {
        if (!is_array($data = $this->getNamespace())) {
            return false;
        }
        // extract user space data (opposed to global/shared space)
        $user_space_data = $data[0];
        $user_space_data = $data['personal'];
        if (!is_array($user_space_data)) {
            return false;
        }
@@ -618,23 +617,38 @@
        return $this->delimiter = $first_userspace[1];
    }
    function _namespace()
    /**
     * NAMESPACE handler (RFC 2342)
     *
     * @return array Namespace data hash (personal, other, shared)
     */
    function getNamespace()
    {
        if (array_key_exists('namespace', $this->prefs)) {
            return $this->prefs['namespace'];
        }
        if (!$this->getCapability('NAMESPACE')) {
            return false;
            return self::ERROR_BAD;
        }
        list($code, $response) = $this->execute('NAMESPACE');
        if ($code == self::ERROR_OK && preg_match('/^\* NAMESPACE /', $response)) {
            $data = $this->parseNamespace(substr($response, 11), $i, 0, 0);
            $data = $this->tokenizeResponse(substr($response, 11));
        }
        if (!is_array($data)) {
            return false;
            return $code;
        }
        return $data;
        $this->prefs['namespace'] = array(
            'personal' => $data[0],
            'other'    => $data[1],
            'shared'   => $data[2],
        );
        return $this->prefs['namespace'];
    }
    function connect($host, $user, $password, $options=null)
@@ -789,7 +803,7 @@
            if ($this->prefs['force_caps']) {
                $this->clearCapability();
            }
            $this->getNamespace();
            $this->getRootDir();
            $this->logged = true;
            return true;
@@ -2951,44 +2965,6 @@
            return $res;
        }
        return $string;
    }
    private function parseNamespace($str, &$i, $len=0, $l)
    {
        if (!$l) {
            $str = str_replace('NIL', '()', $str);
        }
        if (!$len) {
            $len = strlen($str);
        }
        $data      = array();
        $in_quotes = false;
        $elem      = 0;
        for ($i; $i<$len; $i++) {
            $c = (string)$str[$i];
            if ($c == '(' && !$in_quotes) {
                $i++;
                $data[$elem] = $this->parseNamespace($str, $i, $len, $l++);
                $elem++;
            } else if ($c == ')' && !$in_quotes) {
                return $data;
            } else if ($c == '\\') {
                $i++;
                if ($in_quotes) {
                    $data[$elem] .= $str[$i];
                }
            } else if ($c == '"') {
                $in_quotes = !$in_quotes;
                if (!$in_quotes) {
                    $elem++;
                }
            } else if ($in_quotes) {
                $data[$elem].=$c;
            }
        }
        return $data;
    }
    private function parseCapability($str)