[Svn] r4129 - trunk/roundcubemail/program/include

trac at roundcube.net trac at roundcube.net
Mon Oct 25 10:32:53 CEST 2010


Author: alec
Date: 2010-10-25 03:32:53 -0500 (Mon, 25 Oct 2010)
New Revision: 4129

Modified:
   trunk/roundcubemail/program/include/rcube_imap_generic.php
Log:
- Small improvements in NAMESPACE handling


Modified: trunk/roundcubemail/program/include/rcube_imap_generic.php
===================================================================
--- trunk/roundcubemail/program/include/rcube_imap_generic.php	2010-10-25 07:45:35 UTC (rev 4128)
+++ trunk/roundcubemail/program/include/rcube_imap_generic.php	2010-10-25 08:32:53 UTC (rev 4129)
@@ -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;
 	    }
 
@@ -563,7 +563,6 @@
 	    return true;
     }
 
-
     /**
      * Gets the delimiter, for example:
      * INBOX.foo -> .
@@ -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;
@@ -2953,44 +2967,6 @@
     	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)
     {
         $str = preg_replace('/^\* CAPABILITY /i', '', $str);

_______________________________________________
http://lists.roundcube.net/mailman/listinfo/svn



More information about the Svn mailing list