From 36d004e3d0ad9ff97b66b2e505f6b17fd6d23102 Mon Sep 17 00:00:00 2001
From: Aleksander Machniak <alec@alec.pl>
Date: Thu, 03 Jul 2014 08:25:19 -0400
Subject: [PATCH] Added 'contact_search_name' option to define autocompletion entry format

---
 program/steps/mail/autocomplete.inc |   10 ++++++++--
 1 files changed, 8 insertions(+), 2 deletions(-)

diff --git a/program/steps/mail/autocomplete.inc b/program/steps/mail/autocomplete.inc
index 71b337a..c805cd0 100644
--- a/program/steps/mail/autocomplete.inc
+++ b/program/steps/mail/autocomplete.inc
@@ -90,8 +90,14 @@
 
                     // 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;

--
Gitblit v1.9.1