From 8c16e12c176e17c394452258ff8d6a5c8a71cd05 Mon Sep 17 00:00:00 2001 From: Michael M Slusarz Date: Thu, 7 Aug 2014 12:04:50 -0600 Subject: [PATCH] Bug #12480: Don't do email filter on name if name is not part of the search result --- turba/lib/Api.php | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/turba/lib/Api.php b/turba/lib/Api.php index 7e1601f0edd..5cb452651c1 100644 --- a/turba/lib/Api.php +++ b/turba/lib/Api.php @@ -1267,20 +1267,26 @@ public function search($names = null, array $opts = array()) ($attributes[$key]['type'] == 'email')) { $e_val = $ob->getValue($key); - /* Ticket #12480: Don't return email if it - * doesn't contain the search string, since - * an entry can contain multiple e-mail - * fields. Return all e-mails if it - * occurs in the name. */ - if (!isset($tname)) { - $tname = Horde_String_Transliterate::toAscii($name); - } - if (!isset($tdisplay_name)) { - $tdisplay_name = Horde_String_Transliterate::toAscii($display_name); + if (strlen($trimname)) { + /* Ticket #12480: Don't return email if it + * doesn't contain the search string, since + * an entry can contain multiple e-mail + * fields. Return all e-mails if it + * occurs in the name. */ + if (!isset($tname)) { + $tname = Horde_String_Transliterate::toAscii($name); + } + if (!isset($tdisplay_name)) { + $tdisplay_name = Horde_String_Transliterate::toAscii($display_name); + } + + $add = ((Horde_String::ipos(Horde_String_Transliterate::toAscii($e_val), $tname) !== false) || + (Horde_String::ipos($tdisplay_name, $tname) !== false)); + } else { + $add = true; } - if ((Horde_String::ipos($tdisplay_name, $tname) !== false) || - (Horde_String::ipos(Horde_String_Transliterate::toAscii($e_val), $tname) !== false)) { + if ($add) { // Multiple addresses support $email->add($rfc822->parseAddressList($e_val, array( 'limit' => (isset($attributes[$key]['params']) && is_array($attributes[$key]['params']) && !empty($attributes[$key]['params']['allow_multi'])) ? 0 : 1