diff --git a/imp/js/compose-dimp.js b/imp/js/compose-dimp.js index 76410e57b34..dc8e97f202f 100644 --- a/imp/js/compose-dimp.js +++ b/imp/js/compose-dimp.js @@ -31,6 +31,7 @@ var DimpCompose = { // tasks ac: $H(), + ac_limit: 20, checkbox_context: $H({ ctx_atc: $H({ pgppubkey: 'pgp_attach_pubkey', @@ -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, diff --git a/imp/lib/Ajax/Application/Handler/Dynamic.php b/imp/lib/Ajax/Application/Handler/Dynamic.php index 842007192aa..0832a1140f2 100644 --- a/imp/lib/Ajax/Application/Handler/Dynamic.php +++ b/imp/lib/Ajax/Application/Handler/Dynamic.php @@ -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. * @@ -1299,7 +1300,10 @@ public function autocompleteSearch() array('levenshtein' => true) ); - $out->results = $this->_autocompleteSearchEmail($addr); + $out->results = $this->_autocompleteSearchEmail( + $addr, + $this->vars->limit + ); break; } @@ -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) { @@ -1338,6 +1347,10 @@ protected function _autocompleteSearchEmail(Horde_Mail_Rfc822_List $alist) } $out[] = $tmp; + + if ($limit && (++$i > $limit)) { + break; + } } return $out;