Index: trunk/expressoMail1_2/setup/phpgw_pt-br.lang
===================================================================
--- trunk/expressoMail1_2/setup/phpgw_pt-br.lang	(revision 4843)
+++ trunk/expressoMail1_2/setup/phpgw_pt-br.lang	(revision 4929)
@@ -622,4 +622,5 @@
 Your message was sent to queue	expressoMail1_2	pt-br	Sua mensagem foi enviada com sucesso para a fila
 Your search argument must be longer than %1 characters.	expressoMail1_2	pt-br	Seus argumentos para a pesquisa precisam ter mais que %1 dígitos.
+Your search argument must be longer than %1 characters. Use quotes to refine your search	expressoMail1_2	pt-br	Seus argumentos para a pesquisa precisam ter mais que %1 dígitos. Use aspas para refinar a sua pesquisa.
 Your session could not be verified.	expressoMail1_2	pt-br	Sua sessão expirou. Entre novamente no Expresso.
 Your Spam folder was empty.	expressoMail1_2	pt-br	Sua pasta Spam foi limpa.
Index: trunk/expressoMail1_2/inc/class.ldap_functions.inc.php
===================================================================
--- trunk/expressoMail1_2/inc/class.ldap_functions.inc.php	(revision 4457)
+++ trunk/expressoMail1_2/inc/class.ldap_functions.inc.php	(revision 4929)
@@ -87,11 +87,25 @@
 		include_once("class.functions.inc.php");
 		$functions = new functions;
-		
+
+//		$search_for	= utf8_encode($params['search_for']);
+  //Testa se a busca foi realizada com aspas
+		$search_for	= utf8_encode($params['search_for']);
+                $search_len = (strlen($search_for)) - 1;
+                $quote_status=false;
+
+                if((($search_for{0}) == "\"") && (($search_for{$search_len}) == "\"")){
+                    $search_for{0} = " ";
+                    $search_for{$search_len} = " ";
+                    $quote_status=true;
+                }
+
+
+
 		$field		= $params['field'];
 		$ID			= $params['ID'];
-
+		
                 $ldapService = ServiceLocator::getService('ldap');
                 $filter =  $ldapService->getSearchFilter($params['search_for']);
-	
+
 		$contacts_result = array();
 		$contacts_result['field'] = $field;
@@ -101,8 +115,33 @@
 		// follow the referral
 		$this->ldapConnect(true);
-                
+
 		if ($this->ds)
-        {
-                $ldapService->connection = $this->ds;
+		{
+			if (($field != 'null') && ($ID != 'null'))
+			{
+				$filter="(& (&(|(phpgwAccountType=u)(phpgwAccountType=g)(phpgwAccountType=l))(mail=*)) (|(cn=*$search_for*)(mail=*$search_for*)) (!(phpgwaccountvisible=-1)) )";
+				if($extendedinfo)
+				$justthese = array("cn", "mail", "telephoneNumber", "mobile", "phpgwAccountVisible", "uid", "employeeNumber", "ou");
+				else
+				    $justthese = array("cn", "mail", "telephoneNumber", "mobile", "phpgwAccountVisible", "uid");
+			}
+			else
+			{
+				if($quote_status){
+                                	$filter="(& (phpgwAccountType=u) (|(cn=* $search_for *)(cn=$search_for *)(cn=* $search_for)) (!(phpgwaccountvisible=-1)) )";
+                            	}
+                            	else{
+					$filter="(& (phpgwAccountType=u)(cn=*$search_for*) (!(phpgwaccountvisible=-1)) )";
+                            	}
+			//	$filter="(& (phpgwAccountType=u)(cn=*$search_for*) (!(phpgwaccountvisible=-1)) )";
+				if($extendedinfo)
+				$justthese = array("cn", "mail", "telephoneNumber", "mobile", "phpgwAccountVisible","jpegPhoto", "uid", "employeeNumber", "ou");
+				else
+				    $justthese = array("cn", "mail", "telephoneNumber", "mobile", "phpgwAccountVisible","jpegPhoto", "uid");
+			}
+			$sr=@ldap_search($this->ds, $this->ldap_context, $filter, $justthese, 0, $this->max_result + 1);
+			if(!$sr)
+				return null;
+			$count_entries = ldap_count_entries($this->ds,$sr);
 
                 $justthese = array("cn", "mail", "telephonenumber", "mobile", "phpgwaccountvisible", "uid", "employeenumber", "ou");
@@ -110,5 +149,5 @@
 
                 if( $field == 'null' || $ID == 'null' )
-                {
+ 			{
                     $justthese[] = "jpegphoto";
                     $types = 'u';
@@ -119,8 +158,8 @@
 		$sr=@ldap_search($this->ds, $this->ldap_context, $filter, $justthese, 0, $this->max_result);
 			
-		if(!$sr)
-		    return null;
-
-		$count_entries = ldap_count_entries($this->ds,$sr);
+				if(!$sr)
+					return null;
+
+				$count_entries = ldap_count_entries($this->ds,$sr);
 
                 $info = ldap_get_entries($this->ds, $sr);
@@ -130,101 +169,101 @@
 	    {
                 $overload = $count_entries;
-	    }
-	    else
-	    {
-		$catalogsNum=count($this->external_srcs);
+				}
+				else
+				{
+				$catalogsNum=count($this->external_srcs);
 		for ($i=0; $i<=$catalogsNum; $i++)	{
-			if ($this->external_srcs[$i]["quicksearch"]) {
-				$this->ldapConnect(true,$i);
-				$filter="(|(cn=*$search_for*)(mail=*$search_for*))";
-				$justthese = array("cn", "mail", "telephoneNumber", "mobile", "phpgwAccountVisible", "uid","employeeNumber", "ou");
-				$sr=@ldap_search($this->ds, $this->ldap_context, $filter, $justthese, 0, $this->max_result+1);
-				if(!$sr)
-					return null;
-				$count_entries = ldap_count_entries($this->ds,$sr);
-				$search = ldap_get_entries($this->ds, $sr);
-				for ($j=0; $j<$search["count"]; $j++) {
-					$info[] = $search[$j];
-				}
-				$info["count"] = count($info)-1;
-			}
-		}
-	    }
+					if ($this->external_srcs[$i]["quicksearch"]) {
+						$this->ldapConnect(true,$i);
+						$filter="(|(cn=*$search_for*)(mail=*$search_for*))";
+						$justthese = array("cn", "mail", "telephoneNumber", "mobile", "phpgwAccountVisible", "uid","employeeNumber", "ou");
+						$sr=@ldap_search($this->ds, $this->ldap_context, $filter, $justthese, 0, $this->max_result+1);
+						if(!$sr)
+							return null;
+						$count_entries = ldap_count_entries($this->ds,$sr);
+						$search = ldap_get_entries($this->ds, $sr);
+						for ($j=0; $j<$search["count"]; $j++) {
+							$info[] = $search[$j];
+						}
+						$info["count"] = count($info)-1;
+					}
+				}
+			}
 
 	    $tmp = array();
 	    $tmp_users_from_user_org = array();
 
-	    for ($i=0; $i<$info["count"]; $i++)
-	    {
+			for ($i=0; $i<$info["count"]; $i++)
+			{
 		$key = $info[$i]["mail"][0] . '%' . $info[$i]["telephonenumber"][0] . '%'. $info[$i]["mobile"][0] . '%' . 			$info[$i]["uid"][0] . '%' . $info[$i]["jpegphoto"]['count'] . '%' . $info[$i]["employeenumber"][0] . '%' . 	$info[$i]["ou"][0];
 
 		if (/*(!$quickSearch_only_in_userSector) &&*/ preg_match("/$user_sector_dn/i", $info[$i]['dn']))
-		{
+				{
 			$tmp_users_from_user_org[$key] = utf8_decode($info[$i]["cn"][0]);
 			continue;
-		}
+				}
 
 		$tmp[$key] = utf8_decode($info[$i]["cn"][0]);
-	    }
-
-	    natcasesort($tmp_users_from_user_org);
-	    natcasesort($tmp);
-
-	    if (($field != 'null') && ($ID != 'null'))
-	    {
-		    $i = 0;
-
-		    $tmp = array_merge($tmp, $tmp_users_from_user_org);
-		    natcasesort($tmp);
-
-		    foreach ($tmp as $info => $cn)
-		    {
-			    $contacts_result[$i] = array();
-			    $contacts_result[$i]["cn"] = $cn;
-			    list ($contacts_result[$i]["mail"], $contacts_result[$i]["phone"], $contacts_result[$i]["mobile"], $contacts_result[$i]["uid"], $contacts_result[$i]["jpegphoto"], $contacts_result[$i]["employeenumber"], $contacts_result[$i]["ou"]) = split ('%', $info);
-			    $i++;
-		    }
-		    $contacts_result['quickSearch_only_in_userSector'] = $quickSearch_only_in_userSector;
+					}
+
+			natcasesort($tmp_users_from_user_org);
+			natcasesort($tmp);
+
+			if (($field != 'null') && ($ID != 'null'))
+			{
+				$i = 0;
+
+				$tmp = array_merge($tmp, $tmp_users_from_user_org);
+				natcasesort($tmp);
+
+				foreach ($tmp as $info => $cn)
+				{
+					$contacts_result[$i] = array();
+					$contacts_result[$i]["cn"] = $cn;
+					list ($contacts_result[$i]["mail"], $contacts_result[$i]["phone"], $contacts_result[$i]["mobile"], $contacts_result[$i]["uid"], $contacts_result[$i]["jpegphoto"], $contacts_result[$i]["employeenumber"], $contacts_result[$i]["ou"]) = split ('%', $info);
+					$i++;
+				}
+				$contacts_result['quickSearch_only_in_userSector'] = $quickSearch_only_in_userSector;
 		    $contacts_result['maxResult'] = $ldapService->limit;
-	    }
-	    else
-	    {
-		    $options_users_from_user_org = '';
-		    $options = '';
+			}
+			else
+			{
+				$options_users_from_user_org = '';
+				$options = '';
 
 	    
-		    $i = 0;
-		    foreach ($tmp_users_from_user_org as $info => $cn)
-		    {
-			    $contacts_result[$i] = array();
-			    $options_users_from_user_org .= $this->make_quicksearch_card($info, $cn);
-			    $i++;
-		    }
+				$i = 0;
+				foreach ($tmp_users_from_user_org as $info => $cn)
+				{
+					$contacts_result[$i] = array();
+					$options_users_from_user_org .= $this->make_quicksearch_card($info, $cn);
+					$i++;
+				}
 
 	    
-		    foreach ($tmp as $info => $cn)
-		    {
-			    $contacts_result[$i] = array();
-			    $options .= $this->make_quicksearch_card($info, $cn);
-			    $i++;
-		    }
-
-
-		    if (($options_users_from_user_org != '') && ($options != ''))
-		    {					
-			    $head_option0 =
-				    '<tr class="quicksearchcontacts_unselected">' .
-					    '<td colspan="2" width="100%" align="center" style="background:#EEEEEE"><B>' .
-						    $this->functions->getLang('Users from your organization') . '</B> ['.count($tmp_users_from_user_org).']';
-					    '</td>' .
-				    '</tr>';
-
-			    $head_option1 =
-				    '<tr class="quicksearchcontacts_unselected">' .
-					    '<td colspan="2" width="100%" align="center" style="background:#EEEEEE"><B>' .
-						    $this->functions->getLang('Users from others organizations') . '</B> ['.count($tmp).']';
-					    '</td>' .
-				    '</tr>';
-		    }
+				foreach ($tmp as $info => $cn)
+				{
+					$contacts_result[$i] = array();
+					$options .= $this->make_quicksearch_card($info, $cn);
+					$i++;
+				}
+
+
+					if (($options_users_from_user_org != '') && ($options != ''))
+					{
+						$head_option0 =
+							'<tr class="quicksearchcontacts_unselected">' .
+								'<td colspan="2" width="100%" align="center" style="background:#EEEEEE"><B>' .
+									$this->functions->getLang('Users from your organization') . '</B> ['.count($tmp_users_from_user_org).']';
+								'</td>' .
+							'</tr>';
+
+						$head_option1 =
+							'<tr class="quicksearchcontacts_unselected">' .
+								'<td colspan="2" width="100%" align="center" style="background:#EEEEEE"><B>' .
+									$this->functions->getLang('Users from others organizations') . '</B> ['.count($tmp).']';
+								'</td>' .
+							'</tr>';
+					}
 		    
 		    $head_option = '';
@@ -238,10 +277,10 @@
 		    $contacts_result = $head_option.$head_option0 . $options_users_from_user_org . $head_option1. $options;
 
-		}
-	    }
-
-	    ldap_close($this->ds);
-
-	    return $contacts_result;
+				}
+			}
+
+		ldap_close($this->ds);
+
+		return $contacts_result;
 	}
 
@@ -385,11 +424,11 @@
 	//Busca usuarios de um contexto e ja retorna as options do select - usado por template serpro;
 	function search_users($params)
-    {
-        	$owner = $_SESSION['phpgw_info']['expressomail']['user']['owner'];
+        {
+	        $owner = $_SESSION['phpgw_info']['expressomail']['user']['owner'];
 			$ldapService = ServiceLocator::getService('ldap');
 			$ldapService->connect($_SESSION['phpgw_info']['expressomail']['server']['ldap_host'],
 			$_SESSION['phpgw_info']['expressomail']['server']['ldap_root_dn'],
 			$_SESSION['phpgw_info']['expressomail']['server']['ldap_root_pw']);
-			
+
 			$groups = $ldapService->accountSearch($params['filter'], array("gidNumber","cn"), $params['context'] , 'g', 'cn'); 
 			$users = $ldapService->accountSearch($params['filter'], array("uidNumber","cn"), $params['context'] , 'u', 'cn');
@@ -397,19 +436,19 @@
 			$user_options  = array();
 			foreach($groups as $group)
-			{
+	        {
 				$group_options[] = '"'.$group['gidNumber'].'U'.'":"'.$group['cn'].'"';
 	        }
-			
+
 	        foreach($users as $user) 
-	        {
+	            {
 				if($owner != $user['uidNumber'])
 					$user_options[] = '"'.$user['uidNumber'].'U'.'":"'.$user['cn'].'"';
-			}
-			
+	            }
+	
 			$user_options = '{'.implode( ',', $user_options ).'}';
 			$group_options = '{'.implode( ',', $group_options ).'}';
-        	
+
 	        return array("users" => $user_options, "groups" => $group_options);
-    }
+        }
 
 	function catalogsearch($params)
@@ -420,5 +459,5 @@
 		$catalog = $params['catalog'];
 		$error = False;
-		
+
 		//if($_SESSION['phpgw_info']['user']['preferences']['expressoMail']['extended_info'])
 		    //$extendedinfo=true;
@@ -432,7 +471,7 @@
 
 		if ($this->ds) {
-			$justthese = array("cn", "mail", "phpgwaccounttype", "phpgwAccountVisible", "employeeNumber", "ou");
+				$justthese = array("cn", "mail", "phpgwaccounttype", "phpgwAccountVisible", "employeeNumber", "ou");
 			$sr=@ldap_search($this->ds, $user_context, $filter, $justthese, 0, $ldapService->limit+1);
-			
+
 			if(!$sr)
 				return null;
@@ -571,14 +610,14 @@
 		$_SESSION['phpgw_info']['expressomail']['server']['ldap_root_dn'],
 		$_SESSION['phpgw_info']['expressomail']['server']['ldap_root_pw']);
-		
+
 		$entries = $ldapService->accountSearch($params['sentence'], array('cn', 'uid'), $params['context'], 'u', 'cn');
-		
+
 		$options = array();
-		
+
 		foreach ($entries as $value) 
 			$options[] = '"'.$value['uid'].'"'.':'.'"'.$value['cn'].'"';
-		
+
 		return "{".implode(',',$options)."}";		
-	}
+				}
 
 	function uid2cn($uid)
Index: trunk/expressoMail1_2/js/common_functions.js
===================================================================
--- trunk/expressoMail1_2/js/common_functions.js	(revision 4855)
+++ trunk/expressoMail1_2/js/common_functions.js	(revision 4929)
@@ -607,5 +607,6 @@
 
 	if (search_for.length < preferences.search_characters_number){
-            alert(get_lang('Your search argument must be longer than %1 characters.', preferences.search_characters_number));
+            //alert(get_lang('Your search argument must be longer than %1 characters.', preferences.search_characters_number));
+	    alert(get_lang('Your search argument must be longer than %1 characters. Use quotes to refine your search', preferences.search_characters_number));
             return false;
 	}
