From cbde304b98e4e0fc2ff33fd84068d63ae3e86c45 Mon Sep 17 00:00:00 2001
From: alecpl <alec@alec.pl>
Date: Thu, 01 Apr 2010 02:25:29 -0400
Subject: [PATCH] - Use MDB2's Manager module for listing tables

---
 program/include/rcmail.php |   74 +++++++++++++++++++++++++++++++------
 1 files changed, 62 insertions(+), 12 deletions(-)

diff --git a/program/include/rcmail.php b/program/include/rcmail.php
index 04c7151..f1e9d3f 100644
--- a/program/include/rcmail.php
+++ b/program/include/rcmail.php
@@ -244,6 +244,7 @@
   /**
    * Return instance of the internal address book class
    *
+   * @param string  Address book identifier
    * @param boolean True if the address book needs to be writeable
    * @return object rcube_contacts Address book object
    */
@@ -274,11 +275,62 @@
         }
       }
     }
-    else {
+    else { // $id == 'sql'
       $contacts = new rcube_contacts($this->db, $this->user->ID);
     }
     
     return $contacts;
+  }
+
+
+  /**
+   * Return address books list
+   *
+   * @param boolean True if the address book needs to be writeable
+   * @return array  Address books array
+   */
+  public function get_address_sources($writeable = false)
+  {
+    $abook_type = strtolower($this->config->get('address_book_type'));
+    $ldap_config = (array)$this->config->get('ldap_public');
+    $autocomplete = (array)$this->config->get('autocomplete_addressbooks');
+    $list = array();
+
+    // We are using the DB address book
+    if ($abook_type != 'ldap') {
+      $contacts = new rcube_contacts($this->db, null);
+      $list['0'] = array(
+        'id' => 0,
+        'name' => rcube_label('personaladrbook'),
+        'groups' => $contacts->groups,
+        'readonly' => false,
+        'autocomplete' => in_array('sql', $autocomplete)
+      );
+    }
+
+    if (is_array($ldap_config)) {
+      foreach ($ldap_config as $id => $prop)
+        $list[$id] = array(
+          'id' => $id,
+          'name' => $prop['name'],
+          'groups' => false,
+          'readonly' => !$prop['writable'],
+          'autocomplete' => in_array('sql', $autocomplete)
+        );
+    }
+
+    $plugin = $this->plugins->exec_hook('address_sources', array('sources' => $list));
+    $list = $plugin['sources'];
+
+    if ($writeable && !empty($list)) {
+      foreach ($list as $idx => $item) {
+        if ($item['readonly']) {
+          unset($list[$idx]);
+        }
+      }
+    }
+    
+    return $list;
   }
   
   
@@ -361,7 +413,6 @@
     $this->imap = new rcube_imap($this->db);
     $this->imap->debug_level = $this->config->get('debug_level');
     $this->imap->skip_deleted = $this->config->get('skip_deleted');
-    $this->imap->index_sort = $this->config->get('index_sort', true);
 
     // enable caching of imap data
     if ($this->config->get('enable_caching')) {
@@ -378,6 +429,7 @@
       'delimiter' => isset($_SESSION['imap_delimiter']) ? $_SESSION['imap_delimiter'] : $this->config->get('imap_delimiter'),
       'rootdir' => isset($_SESSION['imap_root']) ? $_SESSION['imap_root'] : $this->config->get('imap_root'),
       'debug_mode' => (bool) $this->config->get('imap_debug', 0),
+      'force_caps' => (bool) $this->config->get('imap_force_caps'),
     );
 
     $this->imap->set_options($options);
@@ -405,21 +457,21 @@
    */
   public function imap_connect()
   {
-    $conn = false;
-
     if (!$this->imap)
       $this->imap_init();
     
-    if ($_SESSION['imap_host'] && !$this->imap->conn) {
-      if (!($conn = $this->imap->connect($_SESSION['imap_host'], $_SESSION['username'], $this->decrypt($_SESSION['password']), $_SESSION['imap_port'], $_SESSION['imap_ssl']))) {
+    if ($_SESSION['imap_host'] && !$this->imap->conn->connected()) {
+      if (!$this->imap->connect($_SESSION['imap_host'], $_SESSION['username'], $this->decrypt($_SESSION['password']), $_SESSION['imap_port'], $_SESSION['imap_ssl'])) {
         if ($this->output)
           $this->output->show_message($this->imap->error_code == -1 ? 'imaperror' : 'sessionerror', 'error');
       }
-
-      $this->set_imap_prop();
+      else {
+        $this->set_imap_prop();
+        return $this->imap->conn;
+      }
     }
 
-    return $conn;
+    return false;
   }
 
 
@@ -906,10 +958,8 @@
    */
   public function shutdown()
   {
-    if (is_object($this->imap)) {
+    if (is_object($this->imap))
       $this->imap->close();
-      $this->imap->write_cache();
-    }
 
     if (is_object($this->smtp))
       $this->smtp->disconnect();

--
Gitblit v1.9.1