From 2b42838427c887c8704afd033e5f17172216f82f Mon Sep 17 00:00:00 2001
From: alecpl <alec@alec.pl>
Date: Mon, 25 Oct 2010 05:11:49 -0400
Subject: [PATCH] - Simplify some code, add some comments

---
 program/include/rcube_imap.php         |    5 +-
 program/include/rcube_imap_generic.php |   58 ++++++++++++++++++----------
 2 files changed, 40 insertions(+), 23 deletions(-)

diff --git a/program/include/rcube_imap.php b/program/include/rcube_imap.php
index 4bf7cac..7fbff37 100644
--- a/program/include/rcube_imap.php
+++ b/program/include/rcube_imap.php
@@ -163,8 +163,9 @@
             }
 
             // get server properties
-            if (!empty($this->conn->rootdir))
-                $this->set_rootdir($this->conn->rootdir);
+            $rootdir = $this->conn->getRootDir();
+            if (!empty($rootdir))
+                $this->set_rootdir($rootdir);
             if (empty($this->delimiter))
 	            $this->get_hierarchy_delimiter();
 
diff --git a/program/include/rcube_imap_generic.php b/program/include/rcube_imap_generic.php
index 29f23f6..9009d12 100644
--- a/program/include/rcube_imap_generic.php
+++ b/program/include/rcube_imap_generic.php
@@ -86,8 +86,6 @@
     public $error;
     public $errornum;
 	public $message;
-	public $rootdir;
-	public $delimiter;
     public $data = array();
     public $flags = array(
         'SEEN'     => '\\Seen',
@@ -128,6 +126,14 @@
     {
     }
 
+    /**
+     * Send simple (one line) command to the connection stream
+     *
+     * @param string $string Command string
+     * @param bool   $endln  True if CRLF need to be added at the end of command
+     *
+     * @param int Number of bytes sent, False on error
+     */
     function putLine($string, $endln=true)
     {
         if (!$this->fp)
@@ -147,7 +153,15 @@
         return $res;
     }
 
-    // $this->putLine replacement with Command Continuation Requests (RFC3501 7.5) support
+    /**
+     * Send command to the connection stream with Command Continuation
+     * Requests (RFC3501 7.5) and LITERAL+ (RFC2088) support
+     *
+     * @param string $string Command string
+     * @param bool   $endln  True if CRLF need to be added at the end of command
+     *
+     * @param int Number of bytes sent, False on error
+     */
     function putLineC($string, $endln=true)
     {
         if (!$this->fp)
@@ -534,11 +548,15 @@
         return $code;
     }
 
+    /**
+     * Gets the root directory and delimiter (of personal namespace)
+     *
+     * @return mixed A root directory name, or false.
+     */
     function getRootDir()
     {
 	    if (isset($this->prefs['rootdir']) && is_string($this->prefs['rootdir'])) {
-    		$this->rootdir = $this->prefs['rootdir'];
-		    return true;
+    		return $this->prefs['rootdir'];
 	    }
 
 	    if (!is_array($data = $this->getNamespace())) {
@@ -551,16 +569,15 @@
 	    }
 
 	    $first_userspace = $user_space_data[0];
-	    if (count($first_userspace) !=2 ) {
+	    if (count($first_userspace) !=2) {
 	        return false;
 	    }
 
-	    $this->rootdir            = $first_userspace[0];
-	    $this->delimiter          = $first_userspace[1];
-	    $this->prefs['rootdir']   = substr($this->rootdir, 0, -1);
-	    $this->prefs['delimiter'] = $this->delimiter;
+        $rootdir                  = $first_userspace[0];
+	    $this->prefs['delimiter'] = $first_userspace[1];
+	    $this->prefs['rootdir']   = $rootdir ? substr($rootdir, 0, -1) : '';
 
-	    return true;
+	    return $this->prefs['rootdir'];
     }
 
     /**
@@ -574,11 +591,11 @@
      */
     function getHierarchyDelimiter()
     {
-	    if ($this->delimiter) {
-    		return $this->delimiter;
+	    if ($this->prefs['delimiter']) {
+    		return $this->prefs['delimiter'];
 	    }
 	    if (!empty($this->prefs['delimiter'])) {
-    	    return ($this->delimiter = $this->prefs['delimiter']);
+    	    return $this->prefs['delimiter'];
 	    }
 
 	    // try (LIST "" ""), should return delimiter (RFC2060 Sec 6.3.8)
@@ -590,8 +607,7 @@
             $delimiter = $args[3];
 
 	        if (strlen($delimiter) > 0) {
-	            $this->delimiter = $delimiter;
-	            return $delimiter;
+	            return ($this->prefs['delimiter'] = $delimiter);
 	        }
         }
 
@@ -614,7 +630,7 @@
 	    }
 
 	    // extract delimiter
-	    return $this->delimiter = $first_userspace[1];
+	    return $this->prefs['delimiter'] = $first_userspace[1];
     }
 
     /**
@@ -1845,11 +1861,11 @@
 		if (empty($mailbox)) {
 	        $mailbox = '*';
 	    }
-
-	    if (empty($ref) && $this->rootdir) {
-	        $ref = $this->rootdir;
+/*
+	    if (empty($ref) && $this->prefs['rootdir']) {
+	        $ref = $this->prefs['rootdir'];
 	    }
-
+*/
         $args = array($this->escape($ref), $this->escape($mailbox));
 
         if (!empty($status_opts) && $this->getCapability('LIST-STATUS')) {

--
Gitblit v1.9.1