summaryrefslogtreecommitdiff
path: root/program
diff options
context:
space:
mode:
Diffstat (limited to 'program')
-rw-r--r--program/js/app.js2
-rw-r--r--program/lib/Roundcube/rcube_addressbook.php53
-rw-r--r--program/steps/mail/autocomplete.inc10
3 files changed, 62 insertions, 3 deletions
diff --git a/program/js/app.js b/program/js/app.js
index a3060a8c3..34871f798 100644
--- a/program/js/app.js
+++ b/program/js/app.js
@@ -4568,7 +4568,7 @@ function rcube_webmail()
// add each result line to list
if (results && (len = results.length)) {
for (i=0; i < len && maxlen > 0; i++) {
- text = typeof results[i] === 'object' ? results[i].name : results[i];
+ text = typeof results[i] === 'object' ? (results[i].display || results[i].name) : results[i];
type = typeof results[i] === 'object' ? results[i].type : '';
id = i + this.env.contacts.length;
$('<li>').attr('id', 'rcmkSearchItem' + id)
diff --git a/program/lib/Roundcube/rcube_addressbook.php b/program/lib/Roundcube/rcube_addressbook.php
index 4d9fa3db1..7566d6546 100644
--- a/program/lib/Roundcube/rcube_addressbook.php
+++ b/program/lib/Roundcube/rcube_addressbook.php
@@ -557,6 +557,59 @@ abstract class rcube_addressbook
}
/**
+ * Build contact display name for autocomplete listing
+ *
+ * @param array Hash array with contact data as key-value pairs
+ * @param string Optional email address
+ * @param string Optional name (self::compose_list_name() result)
+ *
+ * @return string Display name
+ */
+ public static function compose_search_name($contact, $email = null, $name = null)
+ {
+ static $template;
+
+ if (!isset($template)) { // cache this
+ $template = rcube::get_instance()->config->get('contact_search_name');
+ if (empty($template)) {
+ $template = '{name} <{email}>';
+ }
+ }
+
+ $result = $template;
+
+ if (preg_match_all('/\{[a-z]+\}/', $result, $matches)) {
+ foreach ($matches[0] as $key) {
+ $key = trim($key, '{}');
+
+ switch ($key) {
+ case 'name':
+ $value = $name ?: self::compose_list_name($contact);
+ break;
+
+ case 'email':
+ $value = $email;
+ break;
+ }
+
+ if (empty($value)) {
+ $value = strpos($key, ':') ? $contact[$key] : self::get_col_values($key, $contact, true);
+ if (is_array($value)) {
+ $value = $value[0];
+ }
+ }
+
+ $result = str_replace('{' . $key . '}', $value, $result);
+ }
+ }
+
+ $result = preg_replace('/\s+/', ' ', $result);
+ $result = trim($result);
+
+ return $result;
+ }
+
+ /**
* Create a unique key for sorting contacts
*/
public static function compose_contact_key($contact, $sort_col)
diff --git a/program/steps/mail/autocomplete.inc b/program/steps/mail/autocomplete.inc
index 71b337a53..c805cd009 100644
--- a/program/steps/mail/autocomplete.inc
+++ b/program/steps/mail/autocomplete.inc
@@ -90,8 +90,14 @@ if (!empty($book_types) && strlen($search)) {
// skip duplicates
if (!in_array($contact, $contacts)) {
- $contacts[] = array('name' => $contact, 'type' => $sql_arr['_type']);
- $sort_keys[] = sprintf('%s %03d', $sql_arr['name'] , $idx++);
+ $contact = array('name' => $contact, 'type' => $sql_arr['_type']);
+
+ if (($display = rcube_addressbook::compose_search_name($sql_arr, $email, $name)) && $display != $contact['name']) {
+ $contact['display'] = $display;
+ }
+
+ $contacts[] = $contact;
+ $sort_keys[] = sprintf('%s %03d', $contact['display'] ?: $name, $idx++);
if (count($contacts) >= $MAXNUM) {
break 2;