* Mail- List mailing lists before contacts when searching for email addresses

This commit is contained in:
nathangray 2017-03-07 10:18:06 -07:00
parent eba4ce0549
commit a14a8681fc

View File

@ -3392,6 +3392,32 @@ class mail_compose
$include_lists = (boolean)$_REQUEST['include_lists']; $include_lists = (boolean)$_REQUEST['include_lists'];
$contacts_obj = new Api\Contacts(); $contacts_obj = new Api\Contacts();
$results = array();
// Add up to 5 matching mailing lists
if($include_lists)
{
$lists = array_filter(
$contacts_obj->get_lists(Acl::READ),
function($element) use($_searchString) {
return (stripos($element, $_searchString) !== false);
}
);
$list_count = 0;
foreach($lists as $key => $list_name)
{
$results[] = array(
'id' => $key,
'name' => $list_name,
'label' => $list_name,
'class' => 'mailinglist',
'title' => lang('Mailinglist'),
'data' => $key
);
if($list_count++ > 5) break;
}
}
if ($GLOBALS['egw_info']['user']['apps']['addressbook'] && strlen($_searchString)>=$_searchStringLength) if ($GLOBALS['egw_info']['user']['apps']['addressbook'] && strlen($_searchString)>=$_searchStringLength)
{ {
//error_log(__METHOD__.__LINE__.array2string($_searchString)); //error_log(__METHOD__.__LINE__.array2string($_searchString));
@ -3428,7 +3454,7 @@ class mail_compose
unset($accounts); unset($accounts);
} }
} }
$results = array();
if(is_array($contacts)) { if(is_array($contacts)) {
foreach($contacts as $contact) { foreach($contacts as $contact) {
foreach(array($contact['email'],$contact['email_home']) as $email) { foreach(array($contact['email'],$contact['email_home']) as $email) {
@ -3489,29 +3515,6 @@ class mail_compose
); );
} }
// Add up to 5 matching mailing lists
if($include_lists)
{
$lists = array_filter(
$contacts_obj->get_lists(Acl::READ),
function($element) use($_searchString) {
return (stripos($element, $_searchString) !== false);
}
);
$list_count = 0;
foreach($lists as $key => $list_name)
{
$results[] = array(
'id' => $key,
'name' => $list_name,
'label' => $list_name,
'class' => 'mailinglist',
'title' => lang('Mailinglist'),
'data' => $key
);
if($list_count++ > 5) break;
}
}
// switch regular JSON response handling off // switch regular JSON response handling off
Api\Json\Request::isJSONRequest(false); Api\Json\Request::isJSONRequest(false);