From 8fcc3e1ad67496496c788023daeb01631a39d915 Mon Sep 17 00:00:00 2001
From: alecpl <alec@alec.pl>
Date: Thu, 14 Oct 2010 06:22:25 -0400
Subject: [PATCH] - Improved IMAP errors handling

---
 program/include/rcube_imap.php |   32 ++++++++++++++++++++++++++------
 1 files changed, 26 insertions(+), 6 deletions(-)

diff --git a/program/include/rcube_imap.php b/program/include/rcube_imap.php
index 0a27989..9d027c8 100644
--- a/program/include/rcube_imap.php
+++ b/program/include/rcube_imap.php
@@ -32,7 +32,6 @@
 class rcube_imap
 {
     public $debug_level = 1;
-    public $error_code = 0;
     public $skip_deleted = false;
     public $root_dir = '';
     public $page_size = 10;
@@ -173,7 +172,6 @@
         }
         // write error log
         else if ($this->conn->error) {
-            $this->error_code = $this->conn->errornum;
             if ($pass && $user)
                 raise_error(array('code' => 403, 'type' => 'imap',
                     'file' => __FILE__, 'line' => __LINE__,
@@ -213,7 +211,29 @@
             $this->conn->select($this->mailbox);
     }
 
+
+    /**
+     * Returns code of last error
+     *
+     * @return int Error code
+     */
+    function get_error_code()
+    {
+        return ($this->conn) ? $this->conn->errornum : 0;
+    }
+
+
+    /**
+     * Returns message of last error
+     *
+     * @return string Error message
+     */
+    function get_error_str()
+    {
+        return ($this->conn) ? $this->conn->error : '';
+    }
     
+
     /**
      * Set options to be used in rcube_imap_generic::connect()
      *
@@ -568,11 +588,11 @@
         if (!empty($this->icache['threads']))
             return count($this->icache['threads']['tree']);
 
-        list ($thread_tree, $msg_depth, $has_children) = $this->_fetch_threads($mailbox);
+        if (is_array($result = $this->_fetch_threads($mailbox)))
+            $thread_tree = array_shift($result);
 
-        $msg_count = count($msg_depth);
-
-//    $this->update_thread_cache($mailbox, $thread_tree, $msg_depth, $has_children);
+//        list ($thread_tree, $msg_depth, $has_children) = $result;
+//        $this->update_thread_cache($mailbox, $thread_tree, $msg_depth, $has_children);
         return count($thread_tree);
     }
 

--
Gitblit v1.9.1