Changeset fc7a41f in github


Ignore:
Timestamp:
Oct 25, 2010 4:32:53 AM (3 years ago)
Author:
alecpl <alec@…>
Branches:
master, HEAD, courier-fix, dev-browser-capabilities, pdo, release-0.6, release-0.7, release-0.8
Children:
2b42838
Parents:
781f0ca5
Message:
  • Small improvements in NAMESPACE handling
File:
1 edited

Legend:

Unmodified
Added
Removed
  • program/include/rcube_imap_generic.php

    r781f0ca5 rfc7a41f  
    535535    } 
    536536 
    537     function getNamespace() 
     537    function getRootDir() 
    538538    { 
    539539            if (isset($this->prefs['rootdir']) && is_string($this->prefs['rootdir'])) { 
     
    542542            } 
    543543 
    544             if (!is_array($data = $this->_namespace())) { 
     544            if (!is_array($data = $this->getNamespace())) { 
    545545                return false; 
    546546            } 
    547547 
    548             $user_space_data = $data[0]; 
     548            $user_space_data = $data['personal']; 
    549549            if (!is_array($user_space_data)) { 
    550550                return false; 
     
    552552 
    553553            $first_userspace = $user_space_data[0]; 
    554             if (count($first_userspace)!=2) { 
     554            if (count($first_userspace) !=2 ) { 
    555555                return false; 
    556556            } 
     
    563563            return true; 
    564564    } 
    565  
    566565 
    567566    /** 
     
    599598            // if that fails, try namespace extension 
    600599            // try to fetch namespace data 
    601             if (!is_array($data = $this->_namespace())) { 
     600            if (!is_array($data = $this->getNamespace())) { 
    602601            return false; 
    603602        } 
    604603 
    605604            // extract user space data (opposed to global/shared space) 
    606             $user_space_data = $data[0]; 
     605            $user_space_data = $data['personal']; 
    607606            if (!is_array($user_space_data)) { 
    608607                return false; 
     
    619618    } 
    620619 
    621     function _namespace() 
    622     { 
     620    /** 
     621     * NAMESPACE handler (RFC 2342) 
     622     * 
     623     * @return array Namespace data hash (personal, other, shared) 
     624     */ 
     625    function getNamespace() 
     626    { 
     627        if (array_key_exists('namespace', $this->prefs)) { 
     628            return $this->prefs['namespace']; 
     629        } 
     630     
    623631        if (!$this->getCapability('NAMESPACE')) { 
    624                 return false; 
     632                return self::ERROR_BAD; 
    625633            } 
    626634 
     
    628636 
    629637                if ($code == self::ERROR_OK && preg_match('/^\* NAMESPACE /', $response)) { 
    630                 $data = $this->parseNamespace(substr($response, 11), $i, 0, 0); 
     638                $data = $this->tokenizeResponse(substr($response, 11)); 
    631639                } 
    632640 
    633641            if (!is_array($data)) { 
    634                 return false; 
    635             } 
    636  
    637         return $data; 
     642                return $code; 
     643            } 
     644 
     645        $this->prefs['namespace'] = array( 
     646            'personal' => $data[0], 
     647            'other'    => $data[1], 
     648            'shared'   => $data[2], 
     649        ); 
     650 
     651        return $this->prefs['namespace']; 
    638652    } 
    639653 
     
    790804                            $this->clearCapability(); 
    791805            } 
    792                     $this->getNamespace(); 
     806                    $this->getRootDir(); 
    793807            $this->logged = true; 
    794808 
     
    29542968    } 
    29552969 
    2956     private function parseNamespace($str, &$i, $len=0, $l) 
    2957     { 
    2958             if (!$l) { 
    2959                 $str = str_replace('NIL', '()', $str); 
    2960             } 
    2961             if (!$len) { 
    2962                 $len = strlen($str); 
    2963             } 
    2964             $data      = array(); 
    2965             $in_quotes = false; 
    2966             $elem      = 0; 
    2967  
    2968         for ($i; $i<$len; $i++) { 
    2969                     $c = (string)$str[$i]; 
    2970                     if ($c == '(' && !$in_quotes) { 
    2971                             $i++; 
    2972                             $data[$elem] = $this->parseNamespace($str, $i, $len, $l++); 
    2973                             $elem++; 
    2974                     } else if ($c == ')' && !$in_quotes) { 
    2975                             return $data; 
    2976                 } else if ($c == '\\') { 
    2977                             $i++; 
    2978                             if ($in_quotes) { 
    2979                                     $data[$elem] .= $str[$i]; 
    2980                         } 
    2981                     } else if ($c == '"') { 
    2982                             $in_quotes = !$in_quotes; 
    2983                             if (!$in_quotes) { 
    2984                                     $elem++; 
    2985                         } 
    2986                     } else if ($in_quotes) { 
    2987                             $data[$elem].=$c; 
    2988                     } 
    2989             } 
    2990  
    2991         return $data; 
    2992     } 
    2993  
    29942970    private function parseCapability($str) 
    29952971    { 
Note: See TracChangeset for help on using the changeset viewer.