Index: /trunk/prototype/modules/mail/templates/listContacts.ejs
===================================================================
--- /trunk/prototype/modules/mail/templates/listContacts.ejs	(revision 6528)
+++ /trunk/prototype/modules/mail/templates/listContacts.ejs	(revision 6592)
@@ -1,17 +1,46 @@
+<% 
+	var decodeType = {
+		'/dynamiccontacts': {
+			css: 'recent', 
+			img: 'recent', 
+			text: 'Contato dinâmico'
+		},
+		'/contacts':{
+			css: 'personal',
+			img: 'personal',
+			text: 'Contato pessoal',
+		},
+		'/sharedcontact':{
+			css: 'personal',
+			img: 'sharedcontact',
+			text: 'Contato compartilhado',
+		},
+		'/groups':{
+			css: 'group',
+			img: 'group',
+			text: 'Grupo pessoal',
+		},
+		'/sharedgroup':{
+			css: 'group',
+			img: 'sharedgroup',
+			text: 'Grupo compartilhado',
+		}
+	} 
+%>
 <%if (data.type == 'linha'){%>
-<li>
+<li class="dynamic-separator">
 	<div class="line-separator">
 		&nbsp;
 	</div>
 <%}else{%>
-<li class="dynamic-<%=(data.type =='' ? 'recent' : (data.type == 'P' ? 'personal' : 'group'))%>">
-	<a style="width:<%= (data.type == '' ? '91%' : '97.5%')%>; display: inline-block;">
-		<img style="position:relative; top:2px; "src="../prototype/modules/mail/img/<%=data.type == '' ? 'recent' : (data.type== 'P' ? 'personal' : 'group')%>.png" title="<%=data.type == '' ? 'Contato Recente' : (data.type== 'P' ? 'Contato Pessoal' : 'Grupo de Contatos')%>"/>
-		<%= (data.name ? data.name + " - " : "") %><%= data.email %>
-		<% if(data.type == ''){ %>
+<li class="dynamic-<%=decodeType[data.type].css%>">
+	<a style="width:<%= (data.type == '/dynamiccontacts' ? '91%' : '97.5%')%>; display: inline-block;">
+		<img style="position:relative; top:2px; "src="../prototype/modules/mail/img/<%=decodeType[data.type].img%>.png" title="<%=decodeType[data.type].text%>"/>
+		<%= (data.name ? (data.name.length > 20? data.name.substring(0,17)+"..." : data.name)+ " - " : "") %><%= data.mail %>
+		<% if(data.type == '/dynamiccontacts'){ %>
 			<div class="dynamic-stars" style="display: inline-block;float: right;"/>
 		<% } %>
 	</a>
-	<span style="width:16px; height:16px; top:5px; <%=data.type == '' ?  '': 'display:none'%>">Excluir contato recente</span>	
+	<span style="width:16px; height:16px; top:5px; <%=data.type == '/dynamiccontacts' ?  '': 'display:none'%>">Excluir contato recente</span>	
 <%}%>
 </li>
Index: /trunk/prototype/rest/catalog/UserContactsResource.php
===================================================================
--- /trunk/prototype/rest/catalog/UserContactsResource.php	(revision 6572)
+++ /trunk/prototype/rest/catalog/UserContactsResource.php	(revision 6592)
@@ -150,5 +150,5 @@
 		    if (($value['user'] == Config::me("uidNumber")) || ($acl[$value['user']]['read'])) {
 
-			$i = new Item($request->resources, ($value['user'] == Config::me("uidNumber") ? 'GroupsResource' : 'SharedGroupsResource'), $value['id']);
+			$i = new Item($request->resources, ($value['user'] == Config::me("uidNumber") ? 'GroupsResource' : 'SharedGroupResource'), $value['id']);
 
 			$d = new Data();
@@ -183,5 +183,5 @@
 
 			$d = new Data();
-			$d->setName('email');
+			$d->setName('mail');
 			$d->setValue($value['email']);
 			$d->setPrompt('Email do Grupo');
@@ -275,5 +275,5 @@
 
 			$d = new Data();
-			$i = new Item($request->resources, (($value['user'] == Config::me("uidNumber")) ? 'ContactsResource' : 'SharedContactsResource'), $value['id']);
+			$i = new Item($request->resources, (($value['user'] == Config::me("uidNumber")) ? 'ContactsResource' : 'SharedContactResource'), $value['id']);
 			$d->setName('id');
 			$d->setValue($value['id']);
@@ -309,5 +309,5 @@
 
 			$d = new Data();
-			$d->setName('email');
+			$d->setName('mail');
 			$d->setValue(isset($value['email']) ? $value['email'] : null);
 			$d->setPrompt('Email do Contato');
Index: /trunk/expressoMail1_2/js/main.js
===================================================================
--- /trunk/expressoMail1_2/js/main.js	(revision 6587)
+++ /trunk/expressoMail1_2/js/main.js	(revision 6592)
@@ -14,4 +14,5 @@
 var dynamicContactList = new Array();
 var topContact = 0;
+DataLayer.get("folder", true);
 
 //Os IE's < 9 não possui suporte a trim() introduzida no JavaScript 1.8.1
@@ -235,4 +236,7 @@
 	});
 
+	DataLayer.get("folder", true);
+	cExecute("$this.imap_functions.get_folders_list&onload=true", update_menu);	
+	
 	setTimeout('auto_refresh()', time_refresh);
 	
@@ -2438,4 +2442,5 @@
 		var arrayCCo = content.find(".cco-tr").find(".box").clone();
 		save_dynamic_contacts(arrayCCo);
+		cache = new Array();
  	}
 	else{
@@ -2482,5 +2487,6 @@
 /*Função que grava o destinatário nos contatos dinâmicos*/
 function save_dynamic_contacts(array){
-		if(parseInt(preferences.use_dynamic_contacts)){
+	if(parseInt(preferences.use_dynamic_contacts)){
+		
 		$.each(array, function(i, value){
 			var stop = false;
@@ -2494,5 +2500,5 @@
 				var exist = 0;
 				$.each(dynamicContacts, function(x, valuex){
-					if(valuex.email == $(value).find("input").val().match(reComplexEmail)[1]){
+					if(valuex.mail == $(value).find("input").val().match(reComplexEmail)[1]){
 						exist = valuex.id;
 						return false;
Index: /trunk/expressoMail1_2/js/draw_api.js
===================================================================
--- /trunk/expressoMail1_2/js/draw_api.js	(revision 6580)
+++ /trunk/expressoMail1_2/js/draw_api.js	(revision 6592)
@@ -9,5 +9,5 @@
  */
 onceOpenedHeadersMessages = {};
-
+var cache = new Array();
 var openTab = {
 	'type' : [], // 8 types of tabs, further info. see expressolivre.org/dev/wiki/mail/Documentacao
@@ -3551,5 +3551,5 @@
 
 //DESENHO DAS CAIXA DE EMAIL
-function draw_email_box(input_data, location, personal){
+function draw_email_box(input_data, location, personal, shared){
 	if($.trim(input_data) != ""){
 		var box_data = valid_emails(input_data);
@@ -3559,5 +3559,5 @@
 			if((preferences.expressoMail_ldap_identifier_recipient || personal)&& $(newBox).hasClass("invalid-email-box")){
 				//$(newBox).find(".loading").css("background-image", "../prototype/modules/mail/img/ajax-loader.gif");
-				show_detais(newBox, input_data, personal);
+				show_detais(newBox, input_data, personal, shared);
 			}else{
 				$(newBox).find(".box-loading").remove();
@@ -3855,10 +3855,10 @@
 
 //MOSTRA OS DETALHES DAS CAIXA DE EMAIL NOS CAMPOS PARA - CC - CCO
-function show_detais(box, value, personal){
+function show_detais(box, value, personal, shared){
 	var ldap_id = preferences.expressoMail_ldap_identifier_recipient;
 	var group = (personal != undefined ? (personal == "G" ? true : false) : false);
-	
+	shared = shared ? shared : false;
 	if(group){
-		REST.get("/group/"+value, {}, function(data){
+		REST.get("/"+ (shared ? "shared" : "") +"group/"+value, {}, function(data){
 			if(!data.error){
 				if(data.collection.error)
@@ -3886,5 +3886,5 @@
 	
 	if(personal){
-		REST.get("/contact/"+value, {}, function(data){
+		REST.get("/"+ (shared ? "shared" : "") +"contact/"+value, {}, function(data){
 			if(!data.error){
 				if(data.collection.error)
@@ -3989,10 +3989,10 @@
 				currentType = "";
 				$.each( items, function( index, item ) {
-					if ( item.type != currentType) {
-						if(item.type == "G" && $(ul).find(".dynamic-recent").length)
+					if ( item.typel != currentType) {
+						if(item.typel == "/groups" && $(ul).find(".dynamic-recent").length)
 							self._renderItem( ul, {name:"", value:"", type:"linha"} );
-						if(item.type == "P" && ($(ul).find(".dynamic-group").length || $(ul).find(".dynamic-recent").length))
+						if(item.typel == "/contacts" && ($(ul).find(".dynamic-group").length || $(ul).find(".dynamic-recent").length))
 							self._renderItem( ul, {name:"", value:"", type:"linha"} );	
-						currentType = item.type;
+						currentType = item.typel;
 					}
 					self._renderItem( ul, item );
@@ -4001,5 +4001,5 @@
 						half : true,
 						hints : ['','','','',''],
-						score    : ((parseInt(item.qtd)*5)/topContact),
+						score    : ((item.number_of_messages*5)/topContact),
 						starOn  : '../../prototype/plugins/jq-raty/img/star-on.png',
 						starOff : '../../prototype/plugins/jq-raty/img/star-off.png',
@@ -4007,4 +4007,7 @@
 					});
 				});
+				if($(ul).find("li:last").hasClass("dynamic-separator")){
+					$(ul).find("li:last").remove();
+				}
 			}
 		});
@@ -4013,5 +4016,27 @@
 			minLength: 1,			
 			source: function(request, response){
-				response( $.ui.autocomplete.filter(dynamicContactList, request.term ) );
+				if ( request.term in cache ) {
+					response( cache[ request.term ] );
+					return;
+				}
+				dynamicContacts = new Array();
+				REST.get("/usercontacts", false, function(data){
+					dynamicData = data.collection.itens;
+					if(dynamicData){
+						$.each(dynamicData, function(index, value){
+							dynamic = {};
+							$.each(value.data, function(index, value){
+								dynamic[value.name] = value.value;
+							});
+							dynamic['value'] = (dynamic.name ? dynamic.name +' - ': '') + dynamic.mail;
+							dynamic['type'] = value.dataType;
+							dynamic['typel'] = (value.dataType.substring(0,7) == "/shared" ? "/"+value.dataType.substring(7,value.dataType.length)+"s" : value.dataType) ;
+							dynamicContacts.push(dynamic);
+						});
+					}
+					var data = $.ui.autocomplete.filter(dynamicContacts, request.term );
+					cache[ request.term ] = data;
+					response( data );
+				});
 			},
 			focus: function() {
@@ -4023,10 +4048,10 @@
 				event.preventDefault();
 				$(this).val("");
-				if(ui.item.type == "P")
-					draw_email_box(""+ui.item.id, $(this), true);
-				else if(ui.item.type == "G")
-					draw_email_box(""+ui.item.id, $(this), "G");
+				if(ui.item.typel == "/contacts")
+					draw_email_box(""+ui.item.id, $(this), true, (ui.item.type.substring(0,7) == "/shared" ? true : false));
+				else if(ui.item.typel == "/groups")
+					draw_email_box(""+ui.item.id, $(this), "G", (ui.item.type.substring(0,7) == "/shared" ? true : false));
 				else
-					draw_email_box(ui.item.name ? "\""+ui.item.name+"\" <"+ui.item.email+">" : ui.item.email, $(this));
+					draw_email_box(ui.item.name ? "\""+ui.item.name+"\" <"+ui.item.mail+">" : ui.item.mail, $(this));
 				return false;
 			},
@@ -4041,32 +4066,36 @@
 		//MONTAGEM DA LISTA DE CONTATOS DINÂMICOS DO AUTO COMPLETE
 		.data( "catcomplete" )._renderItem = function( ul, item ) {
-			var autocomplete = $(this)[0].element;
-			ul.css({"min-width":"400px", "width":"50%", "max-height" : "180px", "overflow-y" : "auto", "min-height": "30px"});
-			var listContacts = DataLayer.render("../prototype/modules/mail/templates/listContacts.ejs", item);
-			return $(listContacts).data( "item.autocomplete", item ).appendTo( ul ).find("span:last").button({
-					icons : {
-					primary : "ui-icon-close"
-				},
-				text: false
-			}).click(function(event){
-				var removeLi = $(this).parents("li:first");
-				if(!event.keyCode)
-					autocomplete.catcomplete( "close" );
-				$.Zebra_Dialog('Deseja remover <b>'+(item.name ? item.name+" - " : "")+ item.email+'</b>?', {
-						'type':     'question',
-						'custom_class': (is_ie ? 'configure-zebra-dialog' : ''),
-						'title':    'Atenção',
-						'buttons': ['Sim','Não'],		
-						'overlay_opacity': '0.5',
-						'onClose':  function(caption) {
-							if(caption == 'Sim'){
-								$(removeLi).remove();
-								REST.delete("/dynamiccontact/"+item.id);
-								updateDynamicContact();
-								updateDynamicContactList();
+			if($(ul).find("li").length < 50){
+				var autocomplete = $(this)[0].element;
+				ul.css({"min-width":"500px", "width":"50%", "max-height" : "180px", "overflow-y" : "auto", "min-height": "30px"});
+				var listContacts = DataLayer.render("../prototype/modules/mail/templates/listContacts.ejs", item);
+				return $(listContacts).data( "item.autocomplete", item ).appendTo( ul ).find("span:last").button({
+						icons : {
+						primary : "ui-icon-close"
+					},
+					text: false
+				}).click(function(event){
+					var removeLi = $(this).parents("li:first");
+					if(!event.keyCode)
+						autocomplete.catcomplete( "close" );
+					$.Zebra_Dialog('Deseja remover <b>'+(item.name ? item.name+" - " : "")+ item.email+'</b>?', {
+							'type':     'question',
+							'custom_class': (is_ie ? 'configure-zebra-dialog' : ''),
+							'title':    'Atenção',
+							'buttons': ['Sim','Não'],		
+							'overlay_opacity': '0.5',
+							'onClose':  function(caption) {
+								if(caption == 'Sim'){
+									$(removeLi).remove();
+									REST.delete("/dynamiccontact/"+item.id);
+									updateDynamicContact();
+									updateDynamicContactList();
+									cache = new Array();
+								}
 							}
-						}
+					});
 				});
-			});
+			}
+			return;
 		};
 	}
