Index: /sandbox/2.4.1-3/prototype/rest/catalog/ContactResource.php
===================================================================
--- /sandbox/2.4.1-3/prototype/rest/catalog/ContactResource.php	(revision 6437)
+++ /sandbox/2.4.1-3/prototype/rest/catalog/ContactResource.php	(revision 6460)
@@ -99,5 +99,5 @@
 		$d = new Data();
 		$d->setName('email');
-		$d->setValue($value['email']);
+		$d->setValue($contact[0]['email']);
 		$d->setPrompt('Email do Contato');
 		$d->setDataType('string');
@@ -110,5 +110,5 @@
 		$d = new Data();
 		$d->setName('telephone');
-		$d->setValue($value['telephone']);
+		$d->setValue($contact[0]['telephone']);
 		$d->setPrompt('Telefone do Contato');
 		$d->setDataType('string');
Index: /sandbox/2.4.1-3/prototype/rest/user/UserResource.php
===================================================================
--- /sandbox/2.4.1-3/prototype/rest/user/UserResource.php	(revision 6429)
+++ /sandbox/2.4.1-3/prototype/rest/user/UserResource.php	(revision 6460)
@@ -35,132 +35,106 @@
 	    //Se nao foi encontrado usuario na consulta
 	    if($user===false){
-		$error = new Error();
-		$error->setCode(Response::NOTFOUND);
-		$error->setTitle('UserLDAP not found');
-		$error->setDescription('User not found.');
+			$error = new Error();
+			$error->setCode(Response::NOTFOUND);
+			$error->setTitle('UserLDAP not found');
+			$error->setDescription('User not found.');
 
-		$c->setError($error);
-		$h->setCollection($c);
+			$c->setError($error);
+			$h->setCollection($c);
 
-		$response->code = Response::NOTFOUND;
-		$response->body = $h->getHypermedia($request->accept[10][0]);
-		return $response;
+			$response->code = Response::NOTFOUND;
+			$response->body = $h->getHypermedia($request->accept[10][0]);
+			return $response;
 	    }
 
-            foreach($user as $value){
+		$t = new Template();
 		$d = new Data();
-                $i = new Item($request->resources, 'UserResource', $value['uid']);
 
 		$d->setName('name');
-                $d->setValue($value['name']);
-                $d->setPrompt('Nome do Usuário');
-                $d->setDataType('string');
-                $d->setMaxLength('100');
-                $d->setMinLength(null);
-                $d->setRequired(true);
+		$d->setValue(null);
+		$d->setPrompt('Nome do Usuário');
+		$d->setDataType('string');
+		$d->setMaxLength(100);
+		$d->setMinLength(null);
+		$d->setRequired(true);
 
-                $i->addData($d);
+		$t->addData($d);
+		$d = new Data();
+
+		$d->setName('email');
+		$d->setValue(null);
+		$d->setPrompt('Email do Usuário');
+		$d->setDataType('string');
+		$d->setMaxLength(100);
+		$d->setMinLength(null);
+		$d->setRequired(true);
+
+		$t->addData($d);
 
 		$d = new Data();
-                $d->setName('email');
-                $d->setValue($value['mail']);
-                $d->setPrompt('Email do Usuário');
-                $d->setDataType('string');
-                $d->setMaxLength('100');
-                $d->setMinLength(null);
-                $d->setRequired(true);
+		$d->setName('telefone');
+		$d->setValue(null);
+		$d->setPrompt('Telefone do Usuário');
+		$d->setDataType('string');
+		$d->setMaxLength(100);
+		$d->setMinLength(null);
+		$d->setRequired(true);
 
-                $i->addData($d);
+		$t->addData($d);
 
-                $d = new Data();
-                $d->setName('telephoneNumber');
-                $d->setValue($value['telephoneNumber']);
-                $d->setPrompt('Telefone do Usuário');
-                $d->setDataType('string');
-                $d->setMaxLength('100');
-                $d->setMinLength(null);
-                $d->setRequired(true);
+		$c->setTemplate($t);
+		
+		$d = new Data();
+		$d->setName('name');
+		$d->setValue($user[0]['name']);
+		$d->setPrompt('Nome do Usuário');
+		$d->setDataType('string');
+		$d->setMaxLength('100');
+		$d->setMinLength(null);
+		$d->setRequired(true);
 
-                $i->addData($d);
+		$c->addData($d);
+		
+		$d = new Data();
+		$d->setName('email');
+		$d->setValue($user[0]['mail']);
+		$d->setPrompt('Email do Usuário');
+		$d->setDataType('string');
+		$d->setMaxLength('100');
+		$d->setMinLength(null);
+		$d->setRequired(true);
+		
+		$c->addData($d);
+		
+		$d = new Data();
+		$d->setName('telephoneNumber');
+		$d->setValue($user[0]['telephoneNumber']);
+		$d->setPrompt('Telefone do Usuário');
+		$d->setDataType('string');
+		$d->setMaxLength('100');
+		$d->setMinLength(null);
+		$d->setRequired(true);
+			
+		$c->addData($d);
+		
+		$l = new Link();
+		$l->setHref('');
+		$l->setRel('delete');
+		$l->setAlt('Remover');
+		$l->setPrompt('Remover');
+		$l->setRender('link');
 
-                $l = new Link();
+		$c->addLink($l);
 
-                $l->setHref('');
-                $l->setRel('delete');
-                $l->setAlt('Remover');
-                $l->setPrompt('Remover');
-                $l->setRender('link');
+		$l = new Link();
+		$l->setHref('');
+		$l->setRel('put');
+		$l->setAlt('Atualizar');
+		$l->setPrompt('Atualizar');
+		$l->setRender('link');
 
-                $i->addLink($l);
+		$c->addLink($l);
 
-                $l = new Link();
-                $l->setHref('');
-                $l->setRel('put');
-                $l->setAlt('Atualizar');
-                $l->setPrompt('Atualizar');
-                $l->setRender('link');
-
-                $i->addLink($l);
-
-                $l = new Link();
-                $l->setHref($i->getHref());
-                $l->setRel('get');
-                $l->setAlt('Buscar');
-                $l->setPrompt('Buscar');
-                $l->setRender('link');
-
-                $i->addLink($l);
-                $c->addItem($i);
-	    }
-
-            $t = new Template();
-            $d = new Data();
-
-            $d->setName('name');
-            $d->setValue(null);
-            $d->setPrompt('Nome do Usuário');
-            $d->setDataType('string');
-            $d->setMaxLength(100);
-            $d->setMinLength(null);
-            $d->setRequired(true);
-
-            $t->addData($d);
-            $d = new Data();
-
-            $d->setName('email');
-            $d->setValue(null);
-            $d->setPrompt('Email do Usuário');
-            $d->setDataType('string');
-            $d->setMaxLength(100);
-            $d->setMinLength(null);
-            $d->setRequired(true);
-
-            $t->addData($d);
-
-            $d = new Data();
-            $d->setName('telefone');
-            $d->setValue(null);
-            $d->setPrompt('Telefone do Usuário');
-            $d->setDataType('string');
-            $d->setMaxLength(100);
-            $d->setMinLength(null);
-            $d->setRequired(true);
-
-            $t->addData($d);
-
-            $c->setTemplate($t);
-            $d = new Data();
-
-            $d->setName('Usuário LDAP');
-            $d->setValue(null);
-            $d->setPrompt('Usuário do LDAP');
-            $d->setDataType(null);
-            $d->setMaxLength(null);
-            $d->setMinLength(null);
-            $d->setRequired(null);
-
-            $c->addData($d);
-
-            $h->setCollection($c);
+		$h->setCollection($c);
 
 	}catch (Exception $ex){
Index: /sandbox/2.4.1-3/expressoMail1_2/js/draw_api.js
===================================================================
--- /sandbox/2.4.1-3/expressoMail1_2/js/draw_api.js	(revision 6422)
+++ /sandbox/2.4.1-3/expressoMail1_2/js/draw_api.js	(revision 6460)
@@ -9,4 +9,7 @@
  */
 onceOpenedHeadersMessages = {};
+
+var dynamicPersonalContacts = new Array();
+var dynamicPersonalGroups = new Array();
 
 var openTab = {
@@ -3572,11 +3575,9 @@
 	input.keydown(function(e){
 		f9 = false;
-		var reEmail = /^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[_a-z0-9-]+(\.[_a-z0-9-]+)+$/;
-		var reEmail2 = /<([^<]*)>[\s]*$/;
 		var focusing = input.parent().find(".email-text");
 		//SE OS CONTATOS DINAMICOS ESTAO ATIVOS
 		if(parseInt(preferences.use_dynamic_contacts) && !input.hasClass("box-input")){
 			//SELECIONA O CONTATO E EVITA OUTROS COMANDOS
-			if ( e.keyCode === $.ui.keyCode.TAB && $( this ).data( "autocomplete" ).menu.active ) {
+			if ( e.keyCode === $.ui.keyCode.TAB && $( this ).data( "catcomplete" ).menu.active ) {
 				e.preventDefault();
 				return false;
@@ -3584,5 +3585,5 @@
 			
 			//FECHA OS CONTATOS DINÂMICOS
-			if( (e.keyCode == 27) && $( this ).data( "autocomplete" ).menu.active ){
+			if( (e.keyCode == 27) && $( this ).data( "catcomplete" ).menu.active ){
 				   e.stopPropagation();
 				   e.preventDefault();
@@ -3590,5 +3591,5 @@
 			
 			//SELECIONA O CONTATO E EVITA OUTROS COMANDOS
-			if(e.keyCode == $.ui.keyCode.ENTER && $( this ).data( "autocomplete" ).menu.active){
+			if(e.keyCode == $.ui.keyCode.ENTER && $( this ).data( "catcomplete" ).menu.active){
 				e.preventDefault();
 				return false;
@@ -3679,6 +3680,5 @@
 		
 		input_search = $(input).val();
-		if($(input).val().length >= 4)
-			$(input).val("");
+		$(input).val("");
 	})
 	//AO COLAR UM TEXTO NO CAMPO
@@ -3802,5 +3802,5 @@
 					box.find(".box-loading").removeClass("box-loading").addClass("box-info");
 					box.addClass("box-"+value).removeClass("invalid-email-box");
-					loadExtraLDAPBox(data.collection.itens[0].data, ".box-"+value);
+					loadExtraLDAPBox(data.collection.data, ".box-"+value);
 					box.unbind("dblclick").bind("dblclick", function(e){
 						new $.Zebra_Dialog('<strong>Impossivel editar</strong> um contato do catálogo pessoal\n' +
@@ -3811,6 +3811,6 @@
 							'auto_close': 3000
 						});
-					}).find(".box-input").val("\""+data.collection.itens[0].data[0].value+"\" <"+data.collection.itens[0].data[1].value+">");
-					box.find(".email-box-value").html( (data.collection.itens[0].data[0].value.length > 18 ? data.collection.itens[0].data[0].value.substring(0, 15)+"...": data.collection.itens[0].data[0].value))
+					}).find(".box-input").val("\""+data.collection.data[0].value+"\" <"+data.collection.data[1].value+">");
+					box.find(".email-box-value").html( (data.collection.data[0].value.length > 18 ? data.collection.data[0].value.substring(0, 15)+"...": data.collection.data[0].value))
 				}
 			}else{
@@ -3893,46 +3893,50 @@
 		//PREPARAÇÃO DA ARRAY DOS CONTATOS DINÂMICOS
 		var dynamicContactList = new Array();
-		var myArray = contacts.split(",");
-		//Variavel de teste...Remover depois...
-		var flag = true;
-		for(var i in myArray){
-			var dynamicContact = myArray[i].split(";");
-						
-			/* if(dynamicContact.length > 1)
-				dynamicContactList.push({name : dynamicContact[0], email: dynamicContact[1], value : (dynamicContact[0] +" - "+dynamicContact[1])});
-			else
-				dynamicContactList.push({name : "", email: dynamicContact[0], value :dynamicContact[0]}); */
-				
-			//Verificar outro modo para criar a divisão dos contatos dinâmicos
-			if( i <(myArray.length / 2)){
-				var type = 'recente';
-
-				if(dynamicContact.length > 1)
-					dynamicContactList.push({name : dynamicContact[0], email: dynamicContact[1], value : (dynamicContact[0] +" - "+dynamicContact[1]), type:type });
-				else
-					dynamicContactList.push({name : "", email: dynamicContact[0], value :dynamicContact[0], type:type});
-			
-			}else{
-				var type = 'pessoal';
-
-				if(flag){
-					dynamicContactList.push({name : "", email: "", value :"", type:"linha"});
-					flag = false;
-				}
-				
-				if(dynamicContact.length > 1)
-					dynamicContactList.push({name : dynamicContact[0], email: dynamicContact[1], value : (dynamicContact[0] +" - "+dynamicContact[1]), type:type });
-				else
-					dynamicContactList.push({name : "", email: dynamicContact[0], value :dynamicContact[0], type:type});
-			}	
-		}
-		
+		var groupsData = DataLayer.read("/groups").collection.itens;
+		var contactsData = DataLayer.read("/contacts").collection.itens;
+		dynamicPersonalGroups = new Array();
+		
+		$.each(groupsData, function(index, value){
+			var group = {
+				id : parseInt(value.data[0].value),
+				name : value.data[2].value,
+				email : value.data[2].value,
+				value: value.data[2].value + " - " + value.data[2].value,
+				type: "G"
+			};
+			dynamicContactList.push(group);
+			dynamicPersonalGroups.push(group);
+		});
+		
+		dynamicPersonalContacts = new Array();
+		
+		$.each(contactsData, function(index, value){
+			var contact = {
+				id : parseInt(value.data[0].value),
+				name : value.data[1].value,
+				email : value.data[2].value,
+				value: value.data[1].value + " - " + value.data[2].value,
+				type: "P"
+			};
+			dynamicContactList.push(contact);
+			dynamicPersonalGroups.push(contact);
+		});
+		$.widget( "custom.catcomplete", $.ui.autocomplete, {
+			_renderMenu: function( ul, items ) {
+				var self = this,
+				currentType = "G";
+				$.each( items, function( index, item ) {
+					if ( item.type != currentType) {
+						self._renderItem( ul, {name:"", value:"", type:"linha"} );
+						currentType = item.type;
+					}
+					self._renderItem( ul, item );
+				});
+			}
+		});
 		//INSERÇÃO DO AUTO COMPLETE AO INPUT
-		div.find("input").autocomplete({
-			minLength: 0,			
-			source: function( request, response ) {
-				response( $.ui.autocomplete.filter(
-					dynamicContactList, extractLast( request.term ) ) );
-			},
+		div.find("input").catcomplete({
+			minLength: 1,			
+			source: dynamicContactList,
 			focus: function() {
 				return false;
@@ -3946,13 +3950,9 @@
 				return false;
 			},
-			autoFocus: true,
-			open : function(){
-				if($.trim($(this).val()) == "")
-					$(this).autocomplete( "close" );
-			}
+			autoFocus: true
 		})
 		
 		//MONTAGEM DA LISTA DE CONTATOS DINÂMICOS DO AUTO COMPLETE
-		.data( "autocomplete" )._renderItem = function( ul, item ) {
+		.data( "catcomplete" )._renderItem = function( ul, item ) {
 			ul.css({"min-width":"280px", "width":"50%", "max-height" : "180px", "overflow-y" : "auto"});
 			if( $(ul).find("li").length > 10 ){
@@ -3985,5 +3985,6 @@
 	//FUNÇÃO DOS BOTÕES PARA - CC - CCO
 	div.parents("tr:first").find("button").button().click(function(){
-		emQuickSearch(($(this).parents("tr:first").find("input").val() ? $(this).parents("tr:first").find("input").val() : input_search), "."+$(this).parents("tr:first").attr('class').split("-")[0], ID, undefined, true);
+		if(!$(":focus").hasClass("new-message-input"))
+			emQuickSearch(($(this).parents("tr:first").find("input").val() ? $(this).parents("tr:first").find("input").val() : input_search), "."+$(this).parents("tr:first").attr('class').split("-")[0], ID, undefined, true);
 	});
 }
Index: /sandbox/2.4.1-3/expressoMail1_2/js/doiMenuData.js
===================================================================
--- /sandbox/2.4.1-3/expressoMail1_2/js/doiMenuData.js	(revision 6374)
+++ /sandbox/2.4.1-3/expressoMail1_2/js/doiMenuData.js	(revision 6460)
@@ -306,5 +306,11 @@
 
 function loadExtraLDAPBox(data, element){
-	//menuItensLabel[index] = {type: "label", customName: menuItems[index].name};		
+	menuItensLabel = {};
+	menuItensLabel["Name"] = {name: "<b>"+data[0].value+"</b>", disabled: true};		
+	menuItensLabel["Email"] = {name: data[1].value, disabled: true};	
+	if(data[2].value){
+		menuItensLabel["TelefoneLabel"] = {name: "<b>Telefone</b>", disabled: true};
+		menuItensLabel["TelefoneValue"] = {name: data[2].value, disabled: true};
+	}
 	$.contextMenu({
 		selector: "#content_id_"+currentTab+" "+element+" .box-info",
@@ -312,10 +318,5 @@
 		delay:100,
 		autoHide:true,
-		items: {
-			"Name" : {name: "<b>"+data[0].value+"</b>", disabled: true} ,
-			"Email" : {name: data[1].value, disabled: true},
-			"TelefoneLabel" : {name: "<b>Telefone</b>", disabled: true},
-			"TelefoneValue" : {name: data[2].value, disabled: true}
-		}
+		items: menuItensLabel
 	});	
 }
