[Svn] r5759 - in branches/devel-framework/roundcubemail: . program/include program/localization/en_US program/steps/mail program/steps/settings

trac at roundcube.net trac at roundcube.net
Thu Jan 12 14:57:08 CET 2012


Author: alec
Date: 2012-01-12 07:57:08 -0600 (Thu, 12 Jan 2012)
New Revision: 5759

Modified:
   branches/devel-framework/roundcubemail/index.php
   branches/devel-framework/roundcubemail/program/include/main.inc
   branches/devel-framework/roundcubemail/program/include/rcmail.php
   branches/devel-framework/roundcubemail/program/include/rcube_imap.php
   branches/devel-framework/roundcubemail/program/include/rcube_imap_cache.php
   branches/devel-framework/roundcubemail/program/include/rcube_storage.php
   branches/devel-framework/roundcubemail/program/localization/en_US/messages.inc
   branches/devel-framework/roundcubemail/program/steps/mail/func.inc
   branches/devel-framework/roundcubemail/program/steps/settings/edit_folder.inc
   branches/devel-framework/roundcubemail/program/steps/settings/folders.inc
   branches/devel-framework/roundcubemail/program/steps/settings/func.inc
   branches/devel-framework/roundcubemail/program/steps/settings/save_folder.inc
Log:
- Added storage (IMAP) auto-connection feature = improved performance with caching enabled
- Fixed imap configuration handling, broken in last commit
- Some CS fixes


Modified: branches/devel-framework/roundcubemail/index.php
===================================================================
--- branches/devel-framework/roundcubemail/index.php	2012-01-12 10:51:05 UTC (rev 5758)
+++ branches/devel-framework/roundcubemail/index.php	2012-01-12 13:57:08 UTC (rev 5759)
@@ -130,7 +130,7 @@
   else {
     $error_code = is_object($RCMAIL->storage) ? $RCMAIL->storage->get_error_code() : 1;
 
-    $OUTPUT->show_message($error_code < -1 ? 'imaperror' : (!$auth['valid'] ? 'invalidrequest' : 'loginfailed'), 'warning');
+    $OUTPUT->show_message($error_code < -1 ? 'storageerror' : (!$auth['valid'] ? 'invalidrequest' : 'loginfailed'), 'warning');
     $RCMAIL->plugins->exec_hook('login_failed', array(
       'code' => $error_code, 'host' => $auth['host'], 'user' => $auth['user']));
     $RCMAIL->kill_session();

Modified: branches/devel-framework/roundcubemail/program/include/main.inc
===================================================================
--- branches/devel-framework/roundcubemail/program/include/main.inc	2012-01-12 10:51:05 UTC (rev 5758)
+++ branches/devel-framework/roundcubemail/program/include/main.inc	2012-01-12 13:57:08 UTC (rev 5759)
@@ -1594,7 +1594,10 @@
     $err_code = $RCMAIL->storage->get_error_code();
     $res_code = $RCMAIL->storage->get_response_code();
 
-    if ($res_code == rcube_storage::NOPERM) {
+    if ($err_code < 0) {
+        $RCMAIL->output->show_message('storageerror', 'error');
+    }
+    else if ($res_code == rcube_storage::NOPERM) {
         $RCMAIL->output->show_message('errornoperm', 'error');
     }
     else if ($res_code == rcube_storage::READONLY) {

Modified: branches/devel-framework/roundcubemail/program/include/rcmail.php
===================================================================
--- branches/devel-framework/roundcubemail/program/include/rcmail.php	2012-01-12 10:51:05 UTC (rev 5758)
+++ branches/devel-framework/roundcubemail/program/include/rcmail.php	2012-01-12 13:57:08 UTC (rev 5759)
@@ -604,7 +604,7 @@
     }
 
     $driver = $this->config->get('storage_driver', 'imap');
-    $driver_class = "rcube_$driver";
+    $driver_class = "rcube_{$driver}";
 
     if (!class_exists($driver_class)) {
       raise_error(array(
@@ -618,7 +618,7 @@
     $this->storage = new $driver_class;
 
     // enable caching of mail data
-    $storage_cache  = $this->config->get("$driver_cache");
+    $storage_cache  = $this->config->get("{$driver}_cache");
     $messages_cache = $this->config->get('messages_cache');
     // for backward compatybility
     if ($storage_cache === null && $messages_cache === null && $this->config->get('enable_caching')) {
@@ -640,17 +640,25 @@
 
     // set class options
     $options = array(
-      'auth_type'   => $this->config->get("$driver_auth_type", 'check'),
-      'auth_cid'    => $this->config->get("$driver_auth_cid"),
-      'auth_pw'     => $this->config->get("$driver_auth_pw"),
-      'debug'       => (bool) $this->config->get("$driver_debug", 0),
-      'force_caps'  => (bool) $this->config->get("$driver_force_caps"),
-      'timeout'     => (int) $this->config->get("$driver_timeout", 0),
+      'auth_type'   => $this->config->get("{$driver}_auth_type", 'check'),
+      'auth_cid'    => $this->config->get("{$driver}_auth_cid"),
+      'auth_pw'     => $this->config->get("{$driver}_auth_pw"),
+      'debug'       => (bool) $this->config->get("{$driver}_debug"),
+      'force_caps'  => (bool) $this->config->get("{$driver}_force_caps"),
+      'timeout'     => (int) $this->config->get("{$driver}_timeout"),
       'skip_deleted' => (bool) $this->config->get('skip_deleted'),
     );
 
-    $hook = $this->plugins->exec_hook("$driver_init", $options);
+    if (!empty($_SESSION['storage_host'])) {
+      $options['host']     = $_SESSION['storage_host'];
+      $options['user']     = $_SESSION['username'];
+      $options['port']     = $_SESSION['storage_port'];
+      $options['ssl']      = $_SESSION['storage_ssl'];
+      $options['password'] = $this->decrypt($_SESSION['password']);
+    }
 
+    $hook = $this->plugins->exec_hook("{$driver}_init", $options);
+
     $this->storage->set_options($options);
     $this->set_storage_prop();
   }
@@ -674,7 +682,7 @@
 
       if (!$storage->connect($host, $user, $pass, $port, $ssl)) {
         if ($this->output)
-          $this->output->show_message($storage->get_error_code() == -1 ? 'imaperror' : 'sessionerror', 'error');
+          $this->output->show_message($storage->get_error_code() == -1 ? 'storageerror' : 'sessionerror', 'error');
       }
       else {
         $this->set_storage_prop();

Modified: branches/devel-framework/roundcubemail/program/include/rcube_imap.php
===================================================================
--- branches/devel-framework/roundcubemail/program/include/rcube_imap.php	2012-01-12 10:51:05 UTC (rev 5758)
+++ branches/devel-framework/roundcubemail/program/include/rcube_imap.php	2012-01-12 13:57:08 UTC (rev 5759)
@@ -75,7 +75,6 @@
     protected $search_threads = false;
     protected $search_sorted = false;
     protected $options = array('auth_method' => 'check');
-    protected $host, $user, $pass, $port, $ssl;
     protected $caching = false;
     protected $messages_caching = false;
     protected $threading = false;
@@ -123,7 +122,7 @@
         $this->options['port'] = $port;
 
         if ($this->options['debug']) {
-            $this->conn->setDebug(true, array($this, 'debug_handler'));
+            $this->set_debug(true);
 
             $this->options['ident'] = array(
                 'name' => 'Roundcube Webmail',
@@ -146,12 +145,17 @@
             $this->conn->connect($data['host'], $data['user'], $pass, $data);
         } while(!$this->conn->connected() && $data['retry']);
 
-        $this->host = $data['host'];
-        $this->user = $data['user'];
-        $this->pass = $pass;
-        $this->port = $port;
-        $this->ssl  = $use_ssl;
+        $config = array(
+            'host'     => $data['host'],
+            'user'     => $data['user'],
+            'password' => $pass,
+            'port'     => $port,
+            'ssl'      => $use_ssl,
+        );
 
+        $this->options      = array_merge($this->options, $config);
+        $this->connect_done = true;
+
         if ($this->conn->connected()) {
             // get namespace and delimiter
             $this->set_env();
@@ -180,19 +184,40 @@
     public function close()
     {
         $this->conn->closeConnection();
-        if ($this->mcache)
+        if ($this->mcache) {
             $this->mcache->close();
+        }
     }
 
 
     /**
+     * Check connection state, connect if not connected.
+     */
+    public function check_connection()
+    {
+        // Establish connection if it wasn't done yet
+        if (!$this->connect_done && !empty($this->options['user'])) {
+            return $this->connect(
+                $this->options['host'],
+                $this->options['user'],
+                $this->options['password'],
+                $this->options['port'],
+                $this->options['ssl']
+            );
+        }
+
+        return $this->is_connected();
+    }
+
+
+    /**
      * Checks IMAP connection.
      *
      * @return boolean  TRUE on success, FALSE on failure
      */
     public function is_connected()
     {
-        return $this->conn && $this->conn->connected();
+        return $this->conn->connected();
     }
 
 
@@ -331,6 +356,11 @@
      */
     public function get_capability($cap)
     {
+        if (!$this->check_connection()) {
+            return false;
+        }
+
+        // @TODO: cache capabilities or store in session (?)
         return $this->conn->getCapability(strtoupper($cap));
     }
 
@@ -347,6 +377,12 @@
     {
         $flag = strtoupper($flag);
         $imap_flag = $this->conn->flags[$flag];
+
+        if ($this->folder !== null) {
+            $this->check_connection();
+        }
+        // @TODO: cache permanent flags (?)
+
         return (in_array_nocase($imap_flag, $this->conn->data['PERMANENTFLAGS']));
     }
 
@@ -398,8 +434,9 @@
         $imap_shared    = $config->get('imap_ns_shared');
         $imap_delimiter = $config->get('imap_delimiter');
 
-        if (!$this->conn->connected())
+        if (!$this->check_connection()) {
             return;
+        }
 
         $ns = $this->conn->getNamespace();
 
@@ -527,6 +564,10 @@
                 $this->set_folder_stats($folder, 'maxuid', $msg_count ? $this->id2uid($msg_count, $folder) : 0);
             }
         }
+        // Need connection here
+        else if (!$this->check_connection()) {
+            return 0;
+        }
         // RECENT count is fetched a bit different
         else if ($mode == 'RECENT') {
             $count = $this->conn->countRecent($folder);
@@ -630,11 +671,11 @@
 
         // use saved message set
         if ($this->search_string && $folder == $this->folder) {
-            return $this->list_header_set($folder, $page, $slice);
+            return $this->list_search_messages($folder, $page, $slice);
         }
 
         if ($this->threading) {
-            return $this->list_thread_headers($folder, $page, $slice);
+            return $this->list_thread_messages($folder, $page, $slice);
         }
 
         // get UIDs of all messages in the folder, sorted
@@ -668,9 +709,9 @@
      * @param   int      $slice      Number of slice items to extract from result array
      *
      * @return  array    Indexed array with message header objects
-     * @see     rcube_imap::list_headers
+     * @see     rcube_imap::list_messages
      */
-    protected function list_thread_headers($folder, $page, $slice=0)
+    protected function list_thread_messages($folder, $page, $slice=0)
     {
         // get all threads (not sorted)
         if ($mcache = $this->get_mcache_engine())
@@ -697,6 +738,10 @@
         }
 
         if (empty($this->icache['threads'])) {
+            if (!$this->check_connection()) {
+                return new rcube_result_thread();
+            }
+
             // get all threads
             $result = $this->conn->thread($folder, $this->threading,
                 $this->options['skip_deleted'] ? 'UNDELETED' : '', true);
@@ -788,7 +833,7 @@
      *
      * @return  array    Indexed array with message header objects
      */
-    protected function list_header_set($folder, $page, $slice=0)
+    protected function list_search_messages($folder, $page, $slice=0)
     {
         if (!strlen($folder) || empty($this->search_set) || $this->search_set->isEmpty()) {
             return array();
@@ -796,7 +841,7 @@
 
         // use saved messages from searching
         if ($this->threading) {
-            return $this->list_thread_header_set($folder, $page, $slice);
+            return $this->list_search_thread_messages($folder, $page, $slice);
         }
 
         // search set is threaded, we need a new one
@@ -826,8 +871,9 @@
                 $index = clone $this->search_set;
 
                 // return empty array if no messages found
-                if ($index->isEmpty())
+                if ($index->isEmpty()) {
                     return array();
+                }
             }
         }
 
@@ -839,8 +885,9 @@
             // get messages uids for one page
             $index->slice($from, $to-$from);
 
-            if ($slice)
+            if ($slice) {
                 $index->slice(-$slice, $slice);
+            }
 
             // fetch headers
             $a_index       = $index->get();
@@ -859,8 +906,9 @@
             // get messages uids for one page...
             $index->slice($start_msg, min($cnt-$from, $this->page_size));
 
-            if ($slice)
+            if ($slice) {
                 $index->slice(-$slice, $slice);
+            }
 
             // ...and fetch headers
             $a_index       = $index->get();
@@ -874,9 +922,14 @@
             $a_msg_headers = $this->fetch_headers($folder, $a_index, false);
 
             // return empty array if no messages found
-            if (!is_array($a_msg_headers) || empty($a_msg_headers))
+            if (!is_array($a_msg_headers) || empty($a_msg_headers)) {
                 return array();
+            }
 
+            if (!$this->check_connection()) {
+                return array();
+            }
+
             // if not already sorted
             $a_msg_headers = $this->conn->sortHeaders(
                 $a_msg_headers, $this->sort_field, $this->sort_order);
@@ -901,9 +954,9 @@
      * @param   int      $slice      Number of slice items to extract from result array
      *
      * @return  array    Indexed array with message header objects
-     * @see rcube_imap::list_header_set()
+     * @see rcube_imap::list_search_messages()
      */
-    protected function list_thread_header_set($folder, $page, $slice=0)
+    protected function list_search_thread_messages($folder, $page, $slice=0)
     {
         // update search_set if previous data was fetched with disabled threading
         if (!$this->search_threads) {
@@ -934,6 +987,9 @@
         if (!$force && ($mcache = $this->get_mcache_engine())) {
             $headers = $mcache->get_messages($folder, $msgs);
         }
+        else if (!$this->check_connection()) {
+            return array();
+        }
         else {
             // fetch reqested headers from server
             $headers = $this->conn->fetchHeaders(
@@ -1041,8 +1097,9 @@
      */
     public function index($folder = '', $sort_field = NULL, $sort_order = NULL)
     {
-        if ($this->threading)
+        if ($this->threading) {
             return $this->thread_index($folder, $sort_field, $sort_order);
+        }
 
         $this->set_sort_order($sort_field, $sort_order);
 
@@ -1063,6 +1120,9 @@
                 }
                 $index = $this->search_set;
             }
+            else if (!$this->check_connection()) {
+                return new rcube_result_index();
+            }
             else {
                 $index = $this->conn->index($folder, $this->search_set->get(),
                     $this->sort_field, $this->options['skip_deleted'], true, true);
@@ -1112,11 +1172,17 @@
             ) {
                 $index = $this->icache['undeleted_idx'];
             }
+            else if (!$this->check_connection()) {
+                return new rcube_result_index();
+            }
             else {
                 $index = $this->conn->search($folder,
                     'ALL' .($this->options['skip_deleted'] ? ' UNDELETED' : ''), true);
             }
         }
+        else if (!$this->check_connection()) {
+            return new rcube_result_index();
+        }
         // fetch complete message index
         else {
             if ($this->get_capability('SORT')) {
@@ -1244,6 +1310,10 @@
             $mailbox = $this->mailbox;
         }
 
+        if (!$this->check_connection()) {
+            return new rcube_result_index();
+        }
+
         $index = $this->conn->search($mailbox, $str, true);
 
         return $index;
@@ -1265,8 +1335,18 @@
     {
         $orig_criteria = $criteria;
 
-        if ($this->options['skip_deleted'] && !preg_match('/UNDELETED/', $criteria))
+        if (!$this->check_connection()) {
+            if ($this->threading) {
+                return new rcube_result_thread();
+            }
+            else {
+                return new rcube_result_index();
+            }
+        }
+
+        if ($this->options['skip_deleted'] && !preg_match('/UNDELETED/', $criteria)) {
             $criteria = 'UNDELETED '.$criteria;
+        }
 
         if ($this->threading) {
             $threads = $this->conn->thread($folder, $this->threading, $criteria, true, $charset);
@@ -1377,6 +1457,9 @@
         if (!$force && $uid && ($mcache = $this->get_mcache_engine())) {
             $headers = $mcache->get_message($folder, $uid);
         }
+        else if (!$this->check_connection()) {
+            $headers = false;
+        }
         else {
             $headers = $this->conn->fetchHeader(
                 $folder, $uid, true, true, $this->get_fetch_headers());
@@ -1415,19 +1498,25 @@
             return null;
 
         // structure might be cached
-        if (!empty($headers->structure))
+        if (!empty($headers->structure)) {
             return $headers;
+        }
 
         $this->msg_uid = $uid;
 
+        if (!$this->check_connection()) {
+            return $headers;
+        }
+
         if (empty($headers->bodystructure)) {
             $headers->bodystructure = $this->conn->getStructure($folder, $uid, true);
         }
 
         $structure = $headers->bodystructure;
 
-        if (empty($structure))
+        if (empty($structure)) {
             return $headers;
+        }
 
         // set message charset from message headers
         if ($headers->charset)
@@ -1822,6 +1911,10 @@
      */
     public function get_message_part($uid, $part=1, $o_part=NULL, $print=NULL, $fp=NULL, $skip_charset_conv=false)
     {
+        if (!$this->check_connection()) {
+            return null;
+        }
+
         // get part data if not provided
         if (!is_object($o_part)) {
             $structure = $this->conn->getStructure($this->folder, $uid, true);
@@ -1876,6 +1969,10 @@
      */
     public function get_raw_body($uid, $fp=null)
     {
+        if (!$this->check_connection()) {
+            return null;
+        }
+
         return $this->conn->handlePartBody($this->folder, $uid,
             true, null, null, false, $fp);
     }
@@ -1890,17 +1987,23 @@
      */
     public function get_raw_headers($uid)
     {
+        if (!$this->check_connection()) {
+            return null;
+        }
+
         return $this->conn->fetchPartHeader($this->folder, $uid, true);
     }
 
 
     /**
      * Sends the whole message source to stdout
-     *
-     * @param int $uid Message UID
      */
     public function print_raw_body($uid)
     {
+        if (!$this->check_connection()) {
+            return;
+        }
+
         $this->conn->handlePartBody($this->folder, $uid, true, NULL, NULL, true);
     }
 
@@ -1921,6 +2024,10 @@
             $folder = $this->folder;
         }
 
+        if (!$this->check_connection()) {
+            return false;
+        }
+
         $flag = strtoupper($flag);
         list($uids, $all_mode) = $this->parse_uids($uids);
 
@@ -2008,9 +2115,14 @@
         list($uids, $all_mode) = $this->parse_uids($uids);
 
         // exit if no message uids are specified
-        if (empty($uids))
+        if (empty($uids)) {
             return false;
+        }
 
+        if (!$this->check_connection()) {
+            return false;
+        }
+
         // make sure folder exists
         if ($to_mbox != 'INBOX' && !$this->folder_exists($to_mbox)) {
             if (in_array($to_mbox, $this->default_folders)) {
@@ -2091,6 +2203,10 @@
             return false;
         }
 
+        if (!$this->check_connection()) {
+            return false;
+        }
+
         // make sure folder exists
         if ($to_mbox != 'INBOX' && !$this->folder_exists($to_mbox)) {
             if (in_array($to_mbox, $this->default_folders)) {
@@ -2131,9 +2247,14 @@
         list($uids, $all_mode) = $this->parse_uids($uids);
 
         // exit if no message uids are specified
-        if (empty($uids))
+        if (empty($uids)) {
             return false;
+        }
 
+        if (!$this->check_connection()) {
+            return false;
+        }
+
         $deleted = $this->conn->flag($folder, $uids, 'DELETED');
 
         if ($deleted) {
@@ -2183,6 +2304,10 @@
             $folder = $this->folder;
         }
 
+        if (!$this->check_connection()) {
+            return false;
+        }
+
         // force folder selection and check if folder is writeable
         // to prevent a situation when CLOSE is executed on closed
         // or EXPUNGE on read-only folder
@@ -2190,6 +2315,7 @@
         if (!$result) {
             return false;
         }
+
         if (!$this->conn->data['READ-WRITE']) {
             $this->conn->setError(rcube_imap_generic::ERROR_READONLY, "Folder is read-only");
             return false;
@@ -2290,7 +2416,7 @@
         if (isset($data['folders'])) {
             $a_folders = $data['folders'];
         }
-        else if (!$this->conn->connected()) {
+        else if (!$this->check_connection()) {
            return null;
         }
         else {
@@ -2391,7 +2517,7 @@
         }
 
         // cache folder attributes
-        if ($root == '' && $name == '*' && empty($filter)) {
+        if ($root == '' && $name == '*' && empty($filter) && !empty($this->conn->data)) {
             $this->update_cache('mailboxes.attributes', $this->conn->data['LIST']);
         }
 
@@ -2423,6 +2549,10 @@
      */
     protected function _list_folders($root='', $name='*')
     {
+        if (!$this->check_connection()) {
+            return null;
+        }
+
         $result = $this->conn->listMailboxes($root, $name);
 
         if (!is_array($result)) {
@@ -2517,6 +2647,10 @@
      */
     public function folder_size($folder)
     {
+        if (!$this->check_connection()) {
+            return 0;
+        }
+
         // @TODO: could we try to use QUOTA here?
         $result = $this->conn->fetchHeaderIndex($folder, '1:*', 'SIZE', false);
 
@@ -2565,6 +2699,10 @@
      */
     public function create_folder($folder, $subscribe=false)
     {
+        if (!$this->check_connection()) {
+            return false;
+        }
+
         $result = $this->conn->createFolder($folder);
 
         // try to subscribe it
@@ -2594,6 +2732,10 @@
             return false;
         }
 
+        if (!$this->check_connection()) {
+            return false;
+        }
+
         $delm = $this->get_hierarchy_delimiter();
 
         // get list of subscribed folders
@@ -2647,6 +2789,10 @@
     {
         $delm = $this->get_hierarchy_delimiter();
 
+        if (!$this->check_connection()) {
+            return false;
+        }
+
         // get list of folders
         if ((strpos($folder, '%') === false) && (strpos($folder, '*') === false))
             $sub_mboxes = $this->list_unsubscribed('', $folder . $delm . '*');
@@ -2712,6 +2858,10 @@
         if (is_array($this->icache[$key]) && in_array($folder, $this->icache[$key]))
             return true;
 
+        if (!$this->check_connection()) {
+            return false;
+        }
+
         if ($subscription) {
             $a_folders = $this->conn->listSubscribed('', $folder);
         }
@@ -2819,6 +2969,10 @@
         }
 
         if (!is_array($opts)) {
+            if (!$this->check_connection()) {
+                return array();
+            }
+
             $this->conn->listMailboxes('', $folder);
             $opts = $this->conn->data['LIST'][$folder];
         }
@@ -2841,6 +2995,9 @@
             $folder = $this->folder !== null ? $this->folder : 'INBOX';
 
         if ($this->conn->selected != $folder) {
+            if (!$this->check_connection()) {
+                return array();
+            }
             if ($this->conn->select($folder))
                 $this->folder = $folder;
             else
@@ -2993,10 +3150,15 @@
      */
     public function set_acl($folder, $user, $acl)
     {
-        if ($this->get_capability('ACL'))
-            return $this->conn->setACL($folder, $user, $acl);
+        if (!$this->get_capability('ACL')) {
+            return false;
+        }
 
-        return false;
+        if (!$this->check_connection()) {
+            return false;
+        }
+
+        return $this->conn->setACL($folder, $user, $acl);
     }
 
 
@@ -3013,10 +3175,15 @@
      */
     public function delete_acl($folder, $user)
     {
-        if ($this->get_capability('ACL'))
-            return $this->conn->deleteACL($folder, $user);
+        if (!$this->get_capability('ACL')) {
+            return false;
+        }
 
-        return false;
+        if (!$this->check_connection()) {
+            return false;
+        }
+
+        return $this->conn->deleteACL($folder, $user);
     }
 
 
@@ -3030,10 +3197,15 @@
      */
     public function get_acl($folder)
     {
-        if ($this->get_capability('ACL'))
-            return $this->conn->getACL($folder);
+        if (!$this->get_capability('ACL')) {
+            return null;
+        }
 
-        return NULL;
+        if (!$this->check_connection()) {
+            return null;
+        }
+
+        return $this->conn->getACL($folder);
     }
 
 
@@ -3049,10 +3221,15 @@
      */
     public function list_rights($folder, $user)
     {
-        if ($this->get_capability('ACL'))
-            return $this->conn->listRights($folder, $user);
+        if (!$this->get_capability('ACL')) {
+            return null;
+        }
 
-        return NULL;
+        if (!$this->check_connection()) {
+            return null;
+        }
+
+        return $this->conn->listRights($folder, $user);
     }
 
 
@@ -3067,10 +3244,15 @@
      */
     public function my_rights($folder)
     {
-        if ($this->get_capability('ACL'))
-            return $this->conn->myRights($folder);
+        if (!$this->get_capability('ACL')) {
+            return null;
+        }
 
-        return NULL;
+        if (!$this->check_connection()) {
+            return null;
+        }
+
+        return $this->conn->myRights($folder);
     }
 
 
@@ -3085,6 +3267,10 @@
      */
     public function set_metadata($folder, $entries)
     {
+        if (!$this->check_connection()) {
+            return false;
+        }
+
         if ($this->get_capability('METADATA') ||
             (!strlen($folder) && $this->get_capability('METADATA-SERVER'))
         ) {
@@ -3113,6 +3299,10 @@
      */
     public function delete_metadata($folder, $entries)
     {
+        if (!$this->check_connection()) {
+            return false;
+        }
+
         if ($this->get_capability('METADATA') || 
             (!strlen($folder) && $this->get_capability('METADATA-SERVER'))
         ) {
@@ -3142,7 +3332,11 @@
      */
     public function get_metadata($folder, $entries, $options=array())
     {
-        if ($this->get_capability('METADATA') || 
+        if (!$this->check_connection()) {
+            return null;
+        }
+
+        if ($this->get_capability('METADATA') ||
             (!strlen($folder) && $this->get_capability('METADATA-SERVER'))
         ) {
             return $this->conn->getMetadata($folder, $entries, $options);
@@ -3165,7 +3359,7 @@
             return $res;
         }
 
-        return NULL;
+        return null;
     }
 
 
@@ -3187,7 +3381,7 @@
         }
 
         // @TODO: log error
-        return NULL;
+        return null;
     }
 
 
@@ -3418,6 +3612,10 @@
             return $uid;
         }
 
+        if (!$this->check_connection()) {
+            return null;
+        }
+
         $uid = $this->conn->ID2UID($folder, $id);
 
         $this->uid_id_map[$folder][$uid] = $id;
@@ -3434,6 +3632,10 @@
         $updated = false;
 
         if (!empty($folders)) {
+            if (!$this->check_connection()) {
+                return false;
+            }
+
             foreach ((array)$folders as $i => $folder) {
                 $folders[$i] = $folder;
 

Modified: branches/devel-framework/roundcubemail/program/include/rcube_imap_cache.php
===================================================================
--- branches/devel-framework/roundcubemail/program/include/rcube_imap_cache.php	2012-01-12 10:51:05 UTC (rev 5758)
+++ branches/devel-framework/roundcubemail/program/include/rcube_imap_cache.php	2012-01-12 13:57:08 UTC (rev 5759)
@@ -888,6 +888,10 @@
             return;
         }
 
+        if (!$this->imap->check_connection()) {
+            return;
+        }
+
         // NOTE: make sure the mailbox isn't selected, before
         // enabling QRESYNC and invoking SELECT
         if ($this->imap->conn->selected !== null) {

Modified: branches/devel-framework/roundcubemail/program/include/rcube_storage.php
===================================================================
--- branches/devel-framework/roundcubemail/program/include/rcube_storage.php	2012-01-12 10:51:05 UTC (rev 5758)
+++ branches/devel-framework/roundcubemail/program/include/rcube_storage.php	2012-01-12 13:57:08 UTC (rev 5759)
@@ -465,7 +465,7 @@
      */
     public function get_body($uid, $part = 1)
     {
-        $headers = $this->get_headers($uid);
+        $headers = $this->get_message_headers($uid);
         return rcube_charset_convert($this->get_message_part($uid, $part, null),
             $headers->charset ? $headers->charset : $this->default_charset);
     }
@@ -486,6 +486,7 @@
      * Returns the message headers as string
      *
      * @param int $uid  Message UID
+     *
      * @return string Message headers string
      */
     abstract function get_raw_headers($uid);
@@ -493,8 +494,6 @@
 
     /**
      * Sends the whole message source to stdout
-     *
-     * @param int $uid Message UID
      */
     abstract function print_raw_body($uid);
 

Modified: branches/devel-framework/roundcubemail/program/localization/en_US/messages.inc
===================================================================
--- branches/devel-framework/roundcubemail/program/localization/en_US/messages.inc	2012-01-12 10:51:05 UTC (rev 5758)
+++ branches/devel-framework/roundcubemail/program/localization/en_US/messages.inc	2012-01-12 13:57:08 UTC (rev 5759)
@@ -21,7 +21,7 @@
 $messages['loginfailed']  = 'Login failed.';
 $messages['cookiesdisabled'] = 'Your browser does not accept cookies.';
 $messages['sessionerror'] = 'Your session is invalid or expired.';
-$messages['imaperror'] = 'Connection to IMAP server failed.';
+$messages['storageerror'] = 'Connection to storage server failed.';
 $messages['servererror'] = 'Server Error!';
 $messages['servererrormsg'] = 'Server Error: $msg';
 $messages['dberror'] = 'Database Error!';

Modified: branches/devel-framework/roundcubemail/program/steps/mail/func.inc
===================================================================
--- branches/devel-framework/roundcubemail/program/steps/mail/func.inc	2012-01-12 10:51:05 UTC (rev 5758)
+++ branches/devel-framework/roundcubemail/program/steps/mail/func.inc	2012-01-12 13:57:08 UTC (rev 5759)
@@ -28,23 +28,9 @@
     $DRAFTS_MBOX => array('subject'=>1, 'to'=>1)
 );
 
-// actions that do not require imap connection here
-$NOSTORAGE_ACTIONS = array('addcontact', 'autocomplete', 'upload', 'display-attachment', 'remove-attachment', 'get');
-
-// always instantiate imap object (but not yet connect to server)
+// always instantiate storage object (but not connect to server yet)
 $RCMAIL->storage_init();
 
-// log in to imap server
-if (!in_array($RCMAIL->action, $NOSTORAGE_ACTIONS) && !$RCMAIL->storage_connect()) {
-  $RCMAIL->kill_session();
-
-  if ($OUTPUT->ajax_call)
-    $OUTPUT->redirect(array(), 2000);
-
-  $OUTPUT->set_env('task', 'login');
-  $OUTPUT->send('login');
-}
-
 // set imap properties and session vars
 if (strlen(trim($mbox = get_input_value('_mbox', RCUBE_INPUT_GPC, true))))
   $RCMAIL->storage->set_folder(($_SESSION['mbox'] = $mbox));

Modified: branches/devel-framework/roundcubemail/program/steps/settings/edit_folder.inc
===================================================================
--- branches/devel-framework/roundcubemail/program/steps/settings/edit_folder.inc	2012-01-12 10:51:05 UTC (rev 5758)
+++ branches/devel-framework/roundcubemail/program/steps/settings/edit_folder.inc	2012-01-12 13:57:08 UTC (rev 5759)
@@ -21,13 +21,12 @@
 
 // WARNING: folder names in UI are encoded with RCMAIL_CHARSET
 
-// init IMAP connection
-$RCMAIL->storage_connect();
-
 function rcmail_folder_form($attrib)
 {
     global $RCMAIL;
 
+    $storage = $RCMAIL->get_storage();
+
     // edited folder name (empty in create-folder mode)
     $mbox      = trim(get_input_value('_mbox', RCUBE_INPUT_GPC, true));
     $mbox_imap = rcube_charset_convert($mbox, RCMAIL_CHARSET, 'UTF7-IMAP');
@@ -36,13 +35,13 @@
     $parent      = trim(get_input_value('_path', RCUBE_INPUT_GPC, true));
     $parent_imap = rcube_charset_convert($parent, RCMAIL_CHARSET, 'UTF7-IMAP');
 
-    $threading_supported = $RCMAIL->storage->get_capability('THREAD');
-    $delimiter = $RCMAIL->storage->get_hierarchy_delimiter();
+    $threading_supported = $storage->get_capability('THREAD');
+    $delimiter = $storage->get_hierarchy_delimiter();
 
     // Get mailbox parameters
     if (strlen($mbox)) {
         $options   = rcmail_folder_options($mbox_imap);
-        $namespace = $RCMAIL->storage->get_namespace();
+        $namespace = $storage->get_namespace();
 
         $path   = explode($delimiter, $mbox_imap);
         $folder = array_pop($path);
@@ -57,14 +56,14 @@
 
         // allow creating subfolders of INBOX folder
         if ($path == 'INBOX') {
-            $path = $RCMAIL->storage->mod_folder($path, 'in');
+            $path = $storage->mod_folder($path, 'in');
         }
     }
 
     // remove personal namespace prefix
     if (strlen($path)) {
         $path_id = $path;
-        $path    = $RCMAIL->storage->mod_folder($path.$delimiter);
+        $path    = $storage->mod_folder($path.$delimiter);
         if ($path[strlen($path)-1] == $delimiter) {
             $path = substr($path, 0, -1);
         }
@@ -193,7 +192,7 @@
         );
 
         if ((!$options['noselect'] && !$options['is_root']) || $mbox_imap == 'INBOX') {
-            $msgcount = $RCMAIL->storage->count($mbox_imap, 'ALL', true, false);
+            $msgcount = $storage->count($mbox_imap, 'ALL', true, false);
 
             // Size
             if ($msgcount) {

Modified: branches/devel-framework/roundcubemail/program/steps/settings/folders.inc
===================================================================
--- branches/devel-framework/roundcubemail/program/steps/settings/folders.inc	2012-01-12 10:51:05 UTC (rev 5758)
+++ branches/devel-framework/roundcubemail/program/steps/settings/folders.inc	2012-01-12 13:57:08 UTC (rev 5759)
@@ -23,20 +23,20 @@
 // WARNING: folder names in UI are encoded with RCMAIL_CHARSET
 
 // init IMAP connection
-$RCMAIL->storage_connect();
+$STORAGE = $RCMAIL->get_storage();
 
 // subscribe mailbox
 if ($RCMAIL->action == 'subscribe')
 {
     $mbox = get_input_value('_mbox', RCUBE_INPUT_POST, true, 'UTF7-IMAP');
     if (strlen($mbox)) {
-        $result = $RCMAIL->storage->subscribe(array($mbox));
+        $result = $STORAGE->subscribe(array($mbox));
 
         // Handle virtual (non-existing) folders
-        if (!$result && $RCMAIL->storage->get_error_code() == -1 &&
-            $RCMAIL->storage->get_response_code() == rcube_storage::TRYCREATE
+        if (!$result && $STORAGE->get_error_code() == -1 &&
+            $STORAGE->get_response_code() == rcube_storage::TRYCREATE
         ) {
-            $result = $RCMAIL->storage->create_folder($mbox, true);
+            $result = $STORAGE->create_folder($mbox, true);
             if ($result) {
                 // @TODO: remove 'virtual' class of folder's row
             }
@@ -62,7 +62,7 @@
 {
     $mbox = get_input_value('_mbox', RCUBE_INPUT_POST, true, 'UTF7-IMAP');
     if (strlen($mbox)) {
-        $result = $RCMAIL->storage->unsubscribe(array($mbox));
+        $result = $STORAGE->unsubscribe(array($mbox));
         if ($result)
             $OUTPUT->show_message('folderunsubscribed', 'confirmation');
         else
@@ -80,7 +80,7 @@
         $plugin = $RCMAIL->plugins->exec_hook('folder_delete', array('name' => $mbox));
 
         if (!$plugin['abort']) {
-            $deleted = $RCMAIL->storage->delete_folder($plugin['name']);
+            $deleted = $STORAGE->delete_folder($plugin['name']);
         }
         else {
             $deleted = $plugin['result'];
@@ -126,19 +126,19 @@
 {
     $mbox_utf8 = get_input_value('_mbox', RCUBE_INPUT_POST, true);
     $mbox      = rcube_charset_convert($mbox_utf8, RCMAIL_CHARSET, 'UTF7-IMAP');
-    $delimiter = $RCMAIL->storage->get_hierarchy_delimiter();
+    $delimiter = $STORAGE->get_hierarchy_delimiter();
     $trash_regexp = '/^' . preg_quote($CONFIG['trash_mbox'] . $delimiter, '/') . '/';
 
     // we should only be purging trash (or their subfolders)
     if (!strlen($CONFIG['trash_mbox']) || $mbox == $CONFIG['trash_mbox']
         || preg_match($trash_regexp, $mbox)
     ) {
-        $success = $RCMAIL->storage->delete_message('*', $mbox);
+        $success = $STORAGE->delete_message('*', $mbox);
         $delete = true;
     }
     // copy to Trash
     else {
-        $success = $RCMAIL->storage->move_message('1:*', $CONFIG['trash_mbox'], $mbox);
+        $success = $STORAGE->move_message('1:*', $CONFIG['trash_mbox'], $mbox);
         $delete = false;
     }
 
@@ -164,7 +164,7 @@
 {
     $name = trim(get_input_value('_mbox', RCUBE_INPUT_POST, true));
 
-    $size = $RCMAIL->storage->folder_size($name);
+    $size = $STORAGE->folder_size($name);
 
     // @TODO: check quota and show percentage usage of specified mailbox?
 
@@ -199,13 +199,15 @@
         $table->add_header('subscribed', '');
     }
 
+    $STORAGE = $RCMAIL->get_storage();
+
     // get folders from server
-    $RCMAIL->storage->clear_cache('mailboxes', true);
+    $STORAGE->clear_cache('mailboxes', true);
 
-    $a_unsubscribed = $RCMAIL->storage->list_folders();
-    $a_subscribed   = $RCMAIL->storage->list_folders_subscribed('', '*', null, null, true); // unsorted
-    $delimiter      = $RCMAIL->storage->get_hierarchy_delimiter();
-    $namespace      = $RCMAIL->storage->get_namespace();
+    $a_unsubscribed = $STORAGE->list_folders();
+    $a_subscribed   = $STORAGE->list_folders_subscribed('', '*', null, null, true); // unsorted
+    $delimiter      = $STORAGE->get_hierarchy_delimiter();
+    $namespace      = $STORAGE->get_namespace();
     $a_js_folders   = array();
     $seen           = array();
     $list_folders   = array();
@@ -213,7 +215,7 @@
     // pre-process folders list
     foreach ($a_unsubscribed as $i => $folder) {
         $folder_id     = $folder;
-        $folder        = $RCMAIL->storage->mod_folder($folder);
+        $folder        = $STORAGE->mod_folder($folder);
         $foldersplit   = explode($delimiter, $folder);
         $name          = rcube_charset_convert(array_pop($foldersplit), 'UTF7-IMAP');
         $parent_folder = join($delimiter, $foldersplit);
@@ -283,7 +285,7 @@
         }
 
         if (!$protected) {
-            $attrs = $RCMAIL->storage->folder_attributes($folder['id']);
+            $attrs = $STORAGE->folder_attributes($folder['id']);
             $noselect = in_array('\\Noselect', $attrs);
         }
 
@@ -367,13 +369,14 @@
 {
     global $RCMAIL;
 
-    $delimiter = $RCMAIL->storage->get_hierarchy_delimiter();
+    $storage   = $RCMAIL->get_storage();
+    $delimiter = $storage->get_hierarchy_delimiter();
 
     $plugin = $RCMAIL->plugins->exec_hook('folder_rename', array(
         'oldname' => $oldname, 'newname' => $newname));
 
     if (!$plugin['abort']) {
-        $renamed =  $RCMAIL->storage->rename_folder($oldname, $newname);
+        $renamed =  $storage->rename_folder($oldname, $newname);
     }
     else {
         $renamed = $plugin['result'];
@@ -405,7 +408,7 @@
 
 $OUTPUT->set_pagetitle(rcube_label('folders'));
 $OUTPUT->include_script('list.js');
-$OUTPUT->set_env('quota', $RCMAIL->storage->get_capability('QUOTA'));
+$OUTPUT->set_env('quota', $STORAGE->get_capability('QUOTA'));
 
 // add some labels to client
 $OUTPUT->add_label('deletefolderconfirm', 'purgefolderconfirm', 'folderdeleting',

Modified: branches/devel-framework/roundcubemail/program/steps/settings/func.inc
===================================================================
--- branches/devel-framework/roundcubemail/program/steps/settings/func.inc	2012-01-12 10:51:05 UTC (rev 5758)
+++ branches/devel-framework/roundcubemail/program/steps/settings/func.inc	2012-01-12 13:57:08 UTC (rev 5759)
@@ -317,8 +317,8 @@
       );
     }
 
-    $RCMAIL->storage_connect();
-    $threading_supported = $RCMAIL->storage->get_capability('THREAD');
+    $storage             = $RCMAIL->get_storage();
+    $threading_supported = $storage->get_capability('THREAD');
 
     if (!isset($no_override['autoexpand_threads']) && $threading_supported) {
       $field_id = 'rcmfd_autoexpand_threads';
@@ -682,9 +682,6 @@
 
     // Configure special folders
     if (!isset($no_override['default_folders'])) {
-
-      $RCMAIL->storage_connect();
-
       // load folders list only when needed
       if ($current) {
         $select = rcmail_mailbox_select(array(
@@ -849,7 +846,7 @@
 {
     global $RCMAIL;
 
-    $options = $RCMAIL->storage->folder_info($mailbox);
+    $options = $RCMAIL->get_storage()->folder_info($mailbox);
     $options['protected'] = $options['is_root'] || ($options['special'] && $RCMAIL->config->get('protect_default_folders'));
 
     return $options;
@@ -867,11 +864,12 @@
 {
     global $RCMAIL, $CONFIG, $OUTPUT;
 
-    $delimiter    = $RCMAIL->storage->get_hierarchy_delimiter();
+    $storage      = $RCMAIL->get_storage();
+    $delimiter    = $storage->get_hierarchy_delimiter();
     $name_utf8    = rcube_charset_convert($name, 'UTF7-IMAP');
     $protected    = ($CONFIG['protect_default_folders'] == true && in_array($name, $CONFIG['default_folders']));
 
-    $foldersplit  = explode($delimiter, $RCMAIL->storage->mod_folder($name));
+    $foldersplit  = explode($delimiter, $storage->mod_folder($name));
     $level        = count($foldersplit) - 1;
     $display_name = str_repeat('    ', $level)
         . Q($protected ? rcmail_localize_foldername($name) : rcube_charset_convert($foldersplit[$level], 'UTF7-IMAP'));

Modified: branches/devel-framework/roundcubemail/program/steps/settings/save_folder.inc
===================================================================
--- branches/devel-framework/roundcubemail/program/steps/settings/save_folder.inc	2012-01-12 10:51:05 UTC (rev 5758)
+++ branches/devel-framework/roundcubemail/program/steps/settings/save_folder.inc	2012-01-12 13:57:08 UTC (rev 5759)
@@ -22,7 +22,7 @@
 // WARNING: folder names in UI are encoded with RCMAIL_CHARSET
 
 // init IMAP connection
-$RCMAIL->storage_connect();
+$STORAGE = $RCMAIL->get_storage();
 
 
 $name = trim(get_input_value('_name', RCUBE_INPUT_POST, true));
@@ -33,7 +33,7 @@
 $old_imap  = rcube_charset_convert($old, RCMAIL_CHARSET, 'UTF7-IMAP');
 // $path is in UTF7-IMAP already
 
-$delimiter = $RCMAIL->storage->get_hierarchy_delimiter();
+$delimiter = $STORAGE->get_hierarchy_delimiter();
 $options = strlen($old_imap) ? rcmail_folder_options($old_imap) : array();
 
 // Folder name checks
@@ -66,13 +66,13 @@
         $name_imap = $path . $delimiter . $name_imap;
     }
     else {
-        $name_imap = $RCMAIL->storage->mod_folder($name_imap, 'in');
+        $name_imap = $STORAGE->mod_folder($name_imap, 'in');
     }
 }
 
 // Check access rights to the parent folder
 if (!$error && strlen($path) && (!strlen($old_imap) || $old_imap != $name_imap)) {
-    $parent_opts = $RCMAIL->storage->folder_info($path);
+    $parent_opts = $STORAGE->folder_info($path);
     if ($parent_opts['namespace'] != 'personal'
         && (empty($parent_opts['rights']) || !preg_match('/[ck]/', implode($parent_opts)))
     ) {
@@ -103,7 +103,7 @@
     $folder = $plugin['record'];
 
     if (!$plugin['abort']) {
-        $created = $RCMAIL->storage->create_folder($folder['name'], $folder['subscribe']);
+        $created = $STORAGE->create_folder($folder['name'], $folder['subscribe']);
     }
     else {
         $created = $plugin['result'];
@@ -143,7 +143,7 @@
 
     if (!$plugin['abort']) {
         if ($rename) {
-            $updated = $RCMAIL->storage->rename_folder($folder['oldname'], $folder['name']);
+            $updated = $STORAGE->rename_folder($folder['oldname'], $folder['name']);
         }
         else {
             $updated = true;

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



More information about the Svn mailing list