Skip to content

Commit

Permalink
Limit email autocomplete entries to 20 per search term
Browse files Browse the repository at this point in the history
  • Loading branch information
slusarz committed Oct 10, 2014
1 parent 1707431 commit 9241f47
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
6 changes: 5 additions & 1 deletion imp/js/compose-dimp.js
Expand Up @@ -31,6 +31,7 @@ var DimpCompose = {
// tasks

ac: $H(),
ac_limit: 20,
checkbox_context: $H({
ctx_atc: $H({
pgppubkey: 'pgp_attach_pubkey',
Expand Down Expand Up @@ -1307,7 +1308,10 @@ var DimpCompose = {
this.ac.set(
id,
new IMP_Autocompleter(id, {
autocompleterParams: { type: 'email' },
autocompleterParams: {
limit: this.ac_limit,
type: 'email'
},
boxClass: 'hordeACBox impACBox',
boxClassFocus: 'impACBoxFocus',
deleteIcon: DimpCore.conf.ac_delete,
Expand Down
17 changes: 15 additions & 2 deletions imp/lib/Ajax/Application/Handler/Dynamic.php
Expand Up @@ -1274,6 +1274,7 @@ public function mailboxSize()
* AJAX Action: Do an autocomplete search.
*
* Variables used:
* - limit: (integer) If set, limits to this many results.
* - search: (string) Search string.
* - type: (string) Autocomplete search type.
*
Expand All @@ -1299,7 +1300,10 @@ public function autocompleteSearch()
array('levenshtein' => true)
);

$out->results = $this->_autocompleteSearchEmail($addr);
$out->results = $this->_autocompleteSearchEmail(
$addr,
$this->vars->limit
);
break;
}

Expand All @@ -1310,11 +1314,16 @@ public function autocompleteSearch()
* Creates the output list for the 'email' autocomplete search.
*
* @param Horde_Mail_Rfc822_List $alist Address list.
* @param integer $limit Limit to this many entries.
*
* @return array See autocompleteSearch().
*/
protected function _autocompleteSearchEmail(Horde_Mail_Rfc822_List $alist)
protected function _autocompleteSearchEmail(
Horde_Mail_Rfc822_List $alist, $limit = 0
)
{
$i = 0;
$limit = intval($limit);
$out = array();

foreach ($alist as $val) {
Expand All @@ -1338,6 +1347,10 @@ protected function _autocompleteSearchEmail(Horde_Mail_Rfc822_List $alist)
}

$out[] = $tmp;

if ($limit && (++$i > $limit)) {
break;
}
}

return $out;
Expand Down

0 comments on commit 9241f47

Please sign in to comment.