From c8174100f6102fb98c46cdd5ce63f743522a92dc Mon Sep 17 00:00:00 2001 From: Aleksander Machniak Date: Mon, 9 Sep 2013 12:40:00 +0200 Subject: [PATCH 1/5] Small improvements in contacts list/search handling --- .../kolab_addressbook/lib/rcube_kolab_contacts.php | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/plugins/kolab_addressbook/lib/rcube_kolab_contacts.php b/plugins/kolab_addressbook/lib/rcube_kolab_contacts.php index b0096c49..4baef45f 100644 --- a/plugins/kolab_addressbook/lib/rcube_kolab_contacts.php +++ b/plugins/kolab_addressbook/lib/rcube_kolab_contacts.php @@ -286,19 +286,20 @@ class rcube_kolab_contacts extends rcube_addressbook } $ids = array_keys($this->contacts); - $this->result->count = count($this->contacts); } else if (is_array($this->filter['ids'])) { $ids = $this->filter['ids']; - if ($this->result->count = count($ids)) { + if (count($ids)) { $uids = array_map(array($this, 'id2uid'), $this->filter['ids']); $this->_fetch_contacts(array(array('uid', '=', $uids))); } + else { + $this->contacts = array(); + } } else { $this->_fetch_contacts(); $ids = array_keys($this->contacts); - $this->result->count = count($ids); } // sort data arrays according to desired list sorting @@ -309,6 +310,8 @@ class rcube_kolab_contacts extends rcube_addressbook $ids = array_values(array_intersect(array_keys($this->contacts), $ids)); else $ids = array_keys($this->contacts); + + $this->result->count = count($ids); } // fill contact data into the current result set @@ -420,6 +423,11 @@ class rcube_kolab_contacts extends rcube_addressbook $this->filter['ids'][] = $id; } + // dummy result with contacts count + if (!$select) { + return new rcube_result_set(count($this->filter['ids']), ($this->list_page-1) * $this->page_size); + } + // list records (now limited by $this->filter) return $this->list_records(); } From 80afe69e4074e43949e2af2e439821abf5a07e5b Mon Sep 17 00:00:00 2001 From: Aleksander Machniak Date: Tue, 10 Sep 2013 15:25:15 +0200 Subject: [PATCH 2/5] First argument of validate() is a reference --- plugins/kolab_addressbook/lib/rcube_kolab_contacts.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/kolab_addressbook/lib/rcube_kolab_contacts.php b/plugins/kolab_addressbook/lib/rcube_kolab_contacts.php index 4baef45f..365e2510 100644 --- a/plugins/kolab_addressbook/lib/rcube_kolab_contacts.php +++ b/plugins/kolab_addressbook/lib/rcube_kolab_contacts.php @@ -933,7 +933,7 @@ class rcube_kolab_contacts extends rcube_addressbook * * @return boolean True if input is valid, False if not. */ - public function validate($save_data) + public function validate(&$save_data) { // validate e-mail addresses $valid = parent::validate($save_data); From cdd23787e2b72cad74d84b1bbc1b4650d7ad2f0a Mon Sep 17 00:00:00 2001 From: Aleksander Machniak Date: Wed, 11 Sep 2013 14:01:38 +0200 Subject: [PATCH 3/5] Fix so kolab_delegation plugin can modify list of addresses in identity form (Bug #2191) --- plugins/kolab_auth/kolab_auth.php | 4 ++++ plugins/kolab_auth/kolab_auth_ldap.php | 4 +++- plugins/kolab_delegation/kolab_delegation.php | 24 +++++++++++++++++++ 3 files changed, 31 insertions(+), 1 deletion(-) diff --git a/plugins/kolab_auth/kolab_auth.php b/plugins/kolab_auth/kolab_auth.php index e6171d21..7c615537 100644 --- a/plugins/kolab_auth/kolab_auth.php +++ b/plugins/kolab_auth/kolab_auth.php @@ -490,6 +490,10 @@ class kolab_auth extends rcube_plugin $emails = array_merge($emails, array_filter($values)); } + // kolab_delegation might want to modify this addresses list + $plugin = $rcmail->plugins->exec_hook('kolab_auth_emails', array('emails' => $emails)); + $emails = $plugin['emails']; + if (!empty($emails)) { $args['form']['addressing']['content']['email'] = array( 'type' => 'select', diff --git a/plugins/kolab_auth/kolab_auth_ldap.php b/plugins/kolab_auth/kolab_auth_ldap.php index 4584c60b..2cddb3f5 100644 --- a/plugins/kolab_auth/kolab_auth_ldap.php +++ b/plugins/kolab_auth/kolab_auth_ldap.php @@ -119,6 +119,7 @@ class kolab_auth_ldap extends rcube_ldap_generic $entries = $result->entries(true); $dn = key($entries); $entry = array_pop($entries); + $entry = rcube_ldap_generic::normalize_entry($entry); $entry = $this->field_mapping($dn, $entry); return $entry; @@ -287,7 +288,8 @@ class kolab_auth_ldap extends rcube_ldap_generic if ($limit && $limit <= $i) { break; } - $dn = $result->get_dn(); + $dn = $result->get_dn(); + $entry = rcube_ldap_generic::normalize_entry($entry); $list[$dn] = $this->field_mapping($dn, $entry); $i++; } diff --git a/plugins/kolab_delegation/kolab_delegation.php b/plugins/kolab_delegation/kolab_delegation.php index 156e81f4..23e0107c 100644 --- a/plugins/kolab_delegation/kolab_delegation.php +++ b/plugins/kolab_delegation/kolab_delegation.php @@ -55,6 +55,9 @@ class kolab_delegation extends rcube_plugin $this->add_hook('calendar_list_filter', array($this, 'calendar_list_filter')); $this->add_hook('calendar_load_itip', array($this, 'calendar_load_itip')); + // delegation support in kolab_auth plugin + $this->add_hook('kolab_auth_emails', array($this, 'kolab_auth_emails')); + if ($this->rc->task == 'settings') { // delegation management interface $this->register_action('plugin.delegation', array($this, 'controller_ui')); @@ -240,6 +243,27 @@ class kolab_delegation extends rcube_plugin } } + /** + * Delegation support in kolab_auth plugin + */ + public function kolab_auth_emails($args) + { + // Add delegators addresses to address selector in user identity form + + if (!empty($_SESSION['delegators'])) { + // @TODO: Consider not adding all delegator addresses to the list. + // Instead add only address of currently edited identity + foreach ($_SESSION['delegators'] as $emails) { + $args['emails'] = array_merge($args['emails'], $emails); + } + + $args['emails'] = array_unique($args['emails']); + sort($args['emails']); + } + + return $args; + } + /** * Delegation UI handler */ From 8002f2b0ca319f6c903e2ca483bff796a36a39d1 Mon Sep 17 00:00:00 2001 From: Aleksander Machniak Date: Wed, 11 Sep 2013 14:07:50 +0200 Subject: [PATCH 4/5] Take identities_level setting into consideration when identity form is going to be modified --- plugins/kolab_auth/kolab_auth.php | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/plugins/kolab_auth/kolab_auth.php b/plugins/kolab_auth/kolab_auth.php index 7c615537..13d4e865 100644 --- a/plugins/kolab_auth/kolab_auth.php +++ b/plugins/kolab_auth/kolab_auth.php @@ -475,13 +475,20 @@ class kolab_auth extends rcube_plugin */ public function identity_form($args) { + $rcmail = rcube::get_instance(); + $ident_level = intval($rcmail->config->get('identities_level', 0)); + + // do nothing if email address modification is disabled + if ($ident_level == 1 || $ident_level == 3) { + return $args; + } + $ldap = self::ldap(); if (!$ldap || !$ldap->ready || empty($_SESSION['kolab_dn'])) { return $args; } - $emails = array(); - $rcmail = rcube::get_instance(); + $emails = array(); $user_record = $ldap->get_record($_SESSION['kolab_dn']); foreach ((array)$rcmail->config->get('kolab_auth_email', array()) as $col) { From 610036138a85c83a4fa9a838b52a3f452e111035 Mon Sep 17 00:00:00 2001 From: "Jeroen van Meeuwen (Kolab Systems)" Date: Wed, 11 Sep 2013 16:31:19 +0100 Subject: [PATCH 5/5] Add the possibility to set the a mailhost attribute value to be used as the IMAP server address to connect to. --- plugins/kolab_auth/kolab_auth.php | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/plugins/kolab_auth/kolab_auth.php b/plugins/kolab_auth/kolab_auth.php index 13d4e865..b8c5996b 100644 --- a/plugins/kolab_auth/kolab_auth.php +++ b/plugins/kolab_auth/kolab_auth.php @@ -326,11 +326,21 @@ class kolab_auth extends rcube_plugin $email_attr = $rcmail->config->get('kolab_auth_email'); $org_attr = $rcmail->config->get('kolab_auth_organization'); $role_attr = $rcmail->config->get('kolab_auth_role'); + $imap_attr = $rcmail->config->get('kolab_auth_mailhost'); if (!empty($role_attr) && !empty($record[$role_attr])) { $_SESSION['user_roledns'] = (array)($record[$role_attr]); } + if (!empty($imap_attr) && !empty($record[$role_attr])) { + $default_host = $rcmail->config->get('default_host'); + if (!empty($default_host)) { + rcube::write_log("errors", "Both default host and kolab_auth_mailhost set. Incompatible."); + } else { + $args['host'] = "tls://" . $record[$role_attr]; + } + } + // Login As... if (!empty($loginas) && $admin_login) { // Authenticate to LDAP