From 7f7ed2d9df1dc531e8500c1c8706c068920adb0a Mon Sep 17 00:00:00 2001
From: alecpl <alec@alec.pl>
Date: Tue, 02 Aug 2011 12:42:29 -0400
Subject: [PATCH] - Fix get_address_book() to call get_address_sources() internally when looking for default source

---
 program/include/rcmail.php |   18 +++++++-----------
 1 files changed, 7 insertions(+), 11 deletions(-)

diff --git a/program/include/rcmail.php b/program/include/rcmail.php
index 33956c3..d38f771 100644
--- a/program/include/rcmail.php
+++ b/program/include/rcmail.php
@@ -378,6 +378,7 @@
    *
    * @param string  Address book identifier
    * @param boolean True if the address book needs to be writeable
+   *
    * @return rcube_contacts Address book object
    */
   public function get_address_book($id, $writeable = false)
@@ -407,18 +408,13 @@
       if ($plugin['instance'] instanceof rcube_addressbook) {
         $contacts = $plugin['instance'];
       }
+      // get first source from the list
       else if (!$id) {
-        if ($abook_type == 'ldap') {
-          // Use the first writable LDAP address book.
-          foreach ($ldap_config as $id => $prop) {
-            if (!$writeable || $prop['writable']) {
-              $contacts = new rcube_ldap($prop, $this->config->get('ldap_debug'), $this->config->mail_domain($_SESSION['imap_host']));
-              break;
-            }
-          }
-        }
-        else { // $id == 'sql'
-          $contacts = new rcube_contacts($this->db, $this->user->ID);
+        $source = reset($this->get_address_sources($writeable));
+        if (!empty($source)) {
+          $contacts = $this->get_address_book($source['id']);
+          if ($contacts)
+            $id = $source['id'];
         }
       }
     }

--
Gitblit v1.9.1