Index: trunk/expressoMail1_2/index.php
===================================================================
--- trunk/expressoMail1_2/index.php	(revision 1526)
+++ trunk/expressoMail1_2/index.php	(revision 1608)
@@ -70,4 +70,5 @@
     $_SESSION['phpgw_info']['user']['preferences']['expressoMail']['use_signature_digital_cripto'] = $GLOBALS['phpgw_info']['user']['preferences']['expressoMail']['use_signature_digital_cripto'] ? $GLOBALS['phpgw_info']['user']['preferences']['expressoMail']['use_signature_digital_cripto'] : "0";
     $_SESSION['phpgw_info']['user']['preferences']['expressoMail']['use_signature_digital'] = $GLOBALS['phpgw_info']['user']['preferences']['expressoMail']['use_signature_digital'] ? $GLOBALS['phpgw_info']['user']['preferences']['expressoMail']['use_signature_digital'] : "0";
+    $_SESSION['phpgw_info']['user']['preferences']['expressoMail']['search_result_number'] = $GLOBALS['phpgw_info']['user']['preferences']['expressoMail']['search_result_number'] ? $GLOBALS['phpgw_info']['user']['preferences']['expressoMail']['search_result_number'] : "50";
     $_SESSION['phpgw_info']['user']['preferences']['expressoMail']['num_max_certs_to_cipher'] = $GLOBALS['phpgw_info']['server']['num_max_certs_to_cipher'] ?  $GLOBALS['phpgw_info']['server']['num_max_certs_to_cipher'] : "10";
     $_SESSION['phpgw_info']['user']['preferences']['expressoMail']['use_signature_cripto'] = $GLOBALS['phpgw_info']['user']['preferences']['expressoMail']['use_signature_cripto'] ? $GLOBALS['phpgw_info']['user']['preferences']['expressoMail']['use_signature_cripto'] : "0";
Index: trunk/expressoMail1_2/inc/class.imap_functions.inc.php
===================================================================
--- trunk/expressoMail1_2/inc/class.imap_functions.inc.php	(revision 1586)
+++ trunk/expressoMail1_2/inc/class.imap_functions.inc.php	(revision 1608)
@@ -2967,8 +2967,10 @@
 		if($search){
 			$search_criteria = '';
+                        $search_result_number = $_SESSION['phpgw_info']['user']['preferences']['expressoMail']['search_result_number'];
+                        $acumulated_results = 0;
 			foreach($search as $tmp)
 			{
 				$tmp1 = explode("##",$tmp);
-				$name_box = $tmp1[0];
+                                $name_box = $tmp1[0];
 				unset($filter);
 				foreach($tmp1 as $index => $criteria)
@@ -2998,4 +3000,5 @@
 					imap_reopen($mbox_stream, "{".$this->imap_server.":".$this->imap_port.$this->imap_options."}".$name_box);
 
+                                $sum = 0;
 				if (preg_match("/^.?\bALL\b/", $filter)){ // Quick Search, note: this ALL isn't the same ALL from imap_search
 
@@ -3007,24 +3010,33 @@
 						$search_criteria = imap_search($mbox_stream, $_filter, SE_UID);
 
-						if($search_criteria && count($search_criteria) < 50)
+						if($search_criteria) //&& count($search_criteria) < 50)
 						{
 							foreach($search_criteria as $new_search){
 								$m_token = trim("##".mb_convert_encoding( $name_box, "ISO_8859-1", "UTF7-IMAP" ) . "--" . $this->get_msg($new_search,$name_box,$mbox_stream) . "--".$new_search."##"."\n");
 								if(!@strstr($retorno,$m_token))
-									$retorno .= $m_token;
+                                                                {
+                                                                    $retorno .= $m_token;
+                                                                    $sum += 1;
+                                                                }
 							}
 						}
-						else if(count($search_criteria) >= 50)
-							return "many results";
 					}
 				}
 				else {
-					$search_criteria = imap_search($mbox_stream, $filter, SE_UID);
-					if( is_array( $search_criteria) )
-					{
-						foreach($search_criteria as $new_search)
-							$retorno .= trim("##".mb_convert_encoding( $name_box, "ISO_8859-1", "UTF7-IMAP" ) . "--" . $this->get_msg($new_search,$name_box,$mbox_stream) . "--" . $new_search."##"."\n");
-					}
-				}
+                                    $search_criteria = imap_search($mbox_stream, $filter, SE_UID);
+                                    if( is_array( $search_criteria) )
+                                    {
+                                            foreach($search_criteria as $new_search)
+                                                    $retorno .= trim("##".mb_convert_encoding( $name_box, "ISO_8859-1", "UTF7-IMAP" ) . "--" . $this->get_msg($new_search,$name_box,$mbox_stream) . "--" . $new_search."##"."\n");
+                                    }
+                                    $sum += count($search_criteria);
+				}
+
+                                $acumulated_results += $sum;
+
+                                if ($search_result_number != '65536' && $acumulated_results >= $search_result_number)
+                                {
+                                    return "many results";
+                                }
 			}
 		}
Index: trunk/expressoMail1_2/inc/hook_settings.inc.php
===================================================================
--- trunk/expressoMail1_2/inc/hook_settings.inc.php	(revision 1605)
+++ trunk/expressoMail1_2/inc/hook_settings.inc.php	(revision 1608)
@@ -153,4 +153,16 @@
 	'40' => lang('big')
 );
+
+$default =  array(
+    '50'    => '50',
+    '100'   => '100',
+    '150'   => '150',
+    '200'   => '200',
+    '300'   => '300',
+    '400'   => '400',
+    '65536' => lang('unlimited')
+);
+
+create_select_box('What is the maximum number of results in an e-mail search?','search_result_number',$default,'');
 
 create_select_box('What is the height of the lines in the list of messages?','line_height',$default,'');
Index: trunk/expressoMail1_2/js/search.js
===================================================================
--- trunk/expressoMail1_2/js/search.js	(revision 1604)
+++ trunk/expressoMail1_2/js/search.js	(revision 1608)
@@ -789,7 +789,12 @@
 			}
 			if((data == "none") && (countTmp.length==0)){alert(get_lang("None result was found."));}
-			else if(countTmp.length > 50){alert(get_lang("More than %1 results. Please, try to refine your search.",50));}
-			else if(data == "many results"){alert(get_lang("More than %1 results. Please, try to refine your search.",50));}
-			else{EsearchE.mount_result((data=='none')?tmp:(countTmp.length==0)?data:data+tmp);}
+			if (preferences.search_result_number == '65536' || (data != 'many results' && countTmp.length < preferences.search_result_number))
+                        {
+                            EsearchE.mount_result((data=='none')?tmp:(countTmp.length==0)?data:data+tmp);
+                        }
+                        else if (data == 'many results' || countTmp.length >= preferences.search_result_number)
+                        {
+                            alert(get_lang("More than %1 results. Please, try to refine your search.",preferences.search_result_number));
+                        }
 		}
 		var args   = "$this.imap_functions.search_msg";
