diff --git a/plugins/kolab_addressbook/lib/rcube_kolab_contacts.php b/plugins/kolab_addressbook/lib/rcube_kolab_contacts.php index b646e73c..625a9941 100644 --- a/plugins/kolab_addressbook/lib/rcube_kolab_contacts.php +++ b/plugins/kolab_addressbook/lib/rcube_kolab_contacts.php @@ -62,6 +62,7 @@ class rcube_kolab_contacts extends rcube_addressbook private $contacts; private $distlists; private $groupmembers; + private $id2uid; private $filter; private $result; private $namespace; @@ -512,6 +513,7 @@ class rcube_kolab_contacts extends rcube_addressbook $contact = $this->_to_rcube_contact($object); $id = $contact['ID']; $this->contacts[$id] = $contact; + $this->id2uid[$id] = $object['uid']; $insert_id = $id; } } @@ -533,8 +535,8 @@ class rcube_kolab_contacts extends rcube_addressbook { $updated = false; $this->_fetch_contacts(); - if ($this->contacts[$id]) { - $old = $this->contactstorage->getObject($id); + if ($this->contacts[$id] && ($uid = $this->id2uid[$id])) { + $old = $this->contactstorage->getObject($uid); $object = array_merge($old, $this->_from_rcube_contact($save_data)); $saved = $this->contactstorage->save($object, $uid); @@ -570,23 +572,25 @@ class rcube_kolab_contacts extends rcube_addressbook $count = 0; foreach ($ids as $id) { - $deleted = $this->contactstorage->delete($id); + if ($uid = $this->id2uid[$id]) { + $deleted = $this->contactstorage->delete($uid); - if (PEAR::isError($deleted)) { - raise_error(array( - 'code' => 600, 'type' => 'php', - 'file' => __FILE__, 'line' => __LINE__, - 'message' => "Error deleting a contact object from the Kolab server:" . $deleted->getMessage()), - true, false); - } - else { - // remove from distribution lists - foreach ((array)$this->groupmembers[$id] as $gid) - $this->remove_from_group($gid, $id); + if (PEAR::isError($deleted)) { + raise_error(array( + 'code' => 600, 'type' => 'php', + 'file' => __FILE__, 'line' => __LINE__, + 'message' => "Error deleting a contact object from the Kolab server:" . $deleted->getMessage()), + true, false); + } + else { + // remove from distribution lists + foreach ((array)$this->groupmembers[$id] as $gid) + $this->remove_from_group($gid, $id); - // clear internal cache - unset($this->contacts[$id], $this->groupmembers[$id]); - $count++; + // clear internal cache + unset($this->contacts[$id], $this->id2uid[$id], $this->groupmembers[$id]); + $count++; + } } } @@ -603,6 +607,7 @@ class rcube_kolab_contacts extends rcube_addressbook if (!PEAR::isError($this->contactstorage->deleteAll())) { $this->contacts = array(); + $this->id2uid = array(); $this->result = null; } } @@ -645,8 +650,9 @@ class rcube_kolab_contacts extends rcube_addressbook return false; } else { + $id = md5($list['uid']); $this->distlists[$record['ID']] = $list; - $result = array('id' => $list['uid'], 'name' => $name); + $result = array('id' => $id, 'name' => $name); } return $result; @@ -734,10 +740,11 @@ class rcube_kolab_contacts extends rcube_addressbook $ids = array_diff($ids, $exists); foreach ($ids as $contact_id) { - if ($contact = $this->contacts[$contact_id]) { + if ($uid = $this->id2uid[$contact_id]) { + $contact = $this->contacts[$contact_id]; foreach ($this->get_col_values('email', $contact, true) as $email) { $list['member'][] = array( - 'uid' => $contact_id, + 'uid' => $uid, 'display-name' => $contact['name'], 'smtp-address' => $email, ); @@ -843,14 +850,16 @@ class rcube_kolab_contacts extends rcube_addressbook $this->_connect(); // read contacts - $this->contacts = array(); + $this->contacts = $this->id2uid = array(); foreach ((array)$this->contactstorage->getObjects() as $record) { // Because of a bug, sometimes group records are returned if ($record['__type'] == 'Group') continue; $contact = $this->_to_rcube_contact($record); - $this->contacts[$contact['ID']] = $contact; + $id = $contact['ID']; + $this->contacts[$id] = $contact; + $this->id2uid[$id] = $record['uid']; } // sort data arrays according to desired list sorting @@ -881,9 +890,9 @@ class rcube_kolab_contacts extends rcube_addressbook // FIXME: folders without any distribution-list objects return contacts instead ?! if ($record['__type'] != 'Group') continue; - $record['ID'] = $record['uid']; + $record['ID'] = md5($record['uid']); foreach ((array)$record['member'] as $i => $member) { - $mid = $member['uid']; + $mid = md5($member['uid']); $record['member'][$i]['ID'] = $mid; $this->groupmembers[$mid][] = $record['ID']; } @@ -899,7 +908,7 @@ class rcube_kolab_contacts extends rcube_addressbook private function _to_rcube_contact($record) { $out = array( - 'ID' => $record['uid'], + 'ID' => md5($record['uid']), 'email' => array(), 'phone' => array(), );