Index: /trunk/prototype/modules/mail/interceptors/Helpers.php
===================================================================
--- /trunk/prototype/modules/mail/interceptors/Helpers.php	(revision 5611)
+++ /trunk/prototype/modules/mail/interceptors/Helpers.php	(revision 5625)
@@ -164,5 +164,5 @@
 		$imap_uri = $uri;
 		$imap_uri['service'] = 'Imap';
-		$imap_result = Controller::find($imap_uri, $params, $criteria);
+		$imap_result = Controller::find($imap_uri, $result, $criteria);
 		
 		/**
Index: /trunk/prototype/modules/mail/js/label.js
===================================================================
--- /trunk/prototype/modules/mail/js/label.js	(revision 5607)
+++ /trunk/prototype/modules/mail/js/label.js	(revision 5625)
@@ -32,5 +32,5 @@
 			$(span).html($(".label-list").find(".edit-value-list").val())
 			.parent().find('.edit').removeClass("hidden").parents("li").click(configureLabel).trigger("click");
-			save_editLabel(nameLabel);
+			save_editLabel(nameLabel, applyToSelectedMessages);
 			
 		}else if( event.keyCode == 27){
@@ -89,5 +89,5 @@
 }		
 	
-function save_editLabel(nameLabel){	
+function save_editLabel(nameLabel, apply){	
 	
 	var lengthSpace = $.trim(nameLabel);
@@ -152,5 +152,5 @@
 		} else {
 			var nameLabel = winElement.find(".input-nome").val();
-			new_label(nameLabel, false);				
+			new_label(nameLabel, false, apply);				
 			winElement.find(".insert-label").val("");
 			$.Watermark.ShowAll();				
@@ -208,5 +208,5 @@
 }
 
-function new_label(nameLabel, isNew){
+function new_label(nameLabel, isNew, apply){
 	var labelCreated = {
 		uid: User.me.id,
@@ -232,5 +232,10 @@
 			borderColor : !!isNew ? '#000000' : winElement.find("input[name='borderColor']").val()
 		};
-
+		
+		/** Marca as mensagens selecionadas com o marcador criado*/
+		if(apply){
+			labeledMessages(newLabel.id)
+		}
+		
 		$(".label-list-container ul").find(".empty-item").css("display","none");
 		$(".label-list-container ul")
@@ -382,5 +387,5 @@
 		
 		if(lengthSpace.length >= 4){
-			new_label(nameLabel, true);
+			new_label(nameLabel, true, data.applyToSelectedMessages);
 			$.Watermark.ShowAll();
 			winElement.find(".insert-label").val("");
@@ -413,5 +418,5 @@
 	winElement.find(".buttons .save-label").click(function(){
 		var nameLabel = winElement.find(".input-nome").val();
-		save_editLabel(nameLabel);
+		save_editLabel(nameLabel, data.applyToSelectedMessages);
 	});	
 	//desfazer marcador
Index: /trunk/prototype/modules/mail/js/followupflag.js
===================================================================
--- /trunk/prototype/modules/mail/js/followupflag.js	(revision 5610)
+++ /trunk/prototype/modules/mail/js/followupflag.js	(revision 5625)
@@ -1,2 +1,35 @@
+function updateCacheFollowupflag(msgNumber, msgFolder, op){
+	if(op){
+		if(typeof msgNumber == 'object'){
+			var extend = DataLayer.get('followupflagged', {
+				filter: ['AND', ['IN', 'messageNumber', msgNumber], ['IN', 'folderName', msgFolder]],
+				criteria: {deepness: 1}
+			}, true);
+		} else{
+			var extend = DataLayer.get('followupflagged', {
+				filter: ['AND', ['=', 'messageNumber', msgNumber], ['=', 'folderName', msgFolder]],
+				criteria: {deepness: 1}
+			}, true);
+		}
+
+		
+		if(extend != "" || extend != 'undefined' || extend != []){
+			for(var i = 0; i < extend.length; i++){
+				if(onceOpenedHeadersMessages[extend[i].folderName]){
+					if(onceOpenedHeadersMessages[extend[i].folderName][extend[i].messageNumber]){
+						onceOpenedHeadersMessages[extend[i].folderName][extend[i].messageNumber]['followupflagged'] = {};
+						DataLayer.merge(onceOpenedHeadersMessages[extend[i].folderName][extend[i].messageNumber]['followupflagged'], extend[i]);
+					}
+				}
+
+			}
+		}
+	}else{
+		onceOpenedHeadersMessages[msgFolder][msgNumber]['followupflagged'] = undefined;	
+	}
+}
+
+
+
 function init_followup(data){
 
@@ -219,29 +252,13 @@
 			winElement.find('.menu-configure-followupflag .save').button("option", "disabled", true);
 			winElement.find('.menu-configure-followupflag .delete').button("option", "disabled", false);
+			updateCacheFollowupflag(selectedMessageIds, folders, true);
 		});
-		
-		var extend = DataLayer.get('followupflagged', {
-			filter: ['AND', ['IN', 'messageNumber', selectedMessageIds], ['IN', 'folderName', folders]],
-			criteria: {deepness: 1}
-		});
-		
-		if(extend != "" || extend != 'undefined' || extend != []){
-			for(var i = 0; i < extend.length; i++){
-				if(onceOpenedHeadersMessages[extend[i].folderName]){
-					if(onceOpenedHeadersMessages[extend[i].folderName][extend[i].messageNumber]){
-						onceOpenedHeadersMessages[extend[i].folderName][extend[i].messageNumber]['followupflagged'] = {};
-						DataLayer.merge(onceOpenedHeadersMessages[extend[i].folderName][extend[i].messageNumber]['followupflagged'], extend[i]);
-					}
-				}
-
-			}
-		} else {
-			alert('erro ao salvar');
-		}
 	}).end()
 	
 	.filter('.menu-configure-followupflag .delete').click(function(){
 		if (selectedMessageIds.length == 0) $(this).button("option", "disabled", true);
-		
+			/** TODO Mudar quando melhorias forem implementadas na API de atualização do cache */
+			DataLayer.remove('followupflagged', false);
+			DataLayer.get('followupflagged');
 			var roles = get_selected_messages_search_role().split(',');
 			for (var i=0; i < selectedMessageIds.length; i++ ){
@@ -270,6 +287,5 @@
 							.find("img").attr("src", "../prototype/modules/mail/img/flagEditor.png").css("margin-left","0");
 					}
-
-					onceOpenedHeadersMessages[folder_name][messageNumber]['followupflagged'] = undefined;
+					updateCacheFollowupflag(messageNumber, folder_name, false);
 				}
 			}
Index: /trunk/expressoMail1_2/js/search.js
===================================================================
--- /trunk/expressoMail1_2/js/search.js	(revision 5605)
+++ /trunk/expressoMail1_2/js/search.js	(revision 5625)
@@ -568,6 +568,13 @@
 						}					
 						aux.followupflagged.id = DataLayer.put('followupflagged', aux.followupflagged);
+						DataLayer.commit();
+						var extend = DataLayer.get('followupflagged', {
+							filter: ['AND', ['IN', 'messageNumber', messageClickedId], ['IN', 'folderName', mailbox]],
+							criteria: {deepness: 1}
+						}, true);
 						
-					}else if(aux.followupflagged.id){
+						updateCacheFollowupflag(messageClickedId, mailbox, true);
+						
+					}else if(onceOpenedHeadersMessages[mailbox][messageClickedId]['followupflagged'].id){
 						/**
 						* Remover followupflag de Acompanhamento (DFD0078:RI25)
@@ -583,4 +590,6 @@
 								'tr[role="'+messageClickedId+'_'+mailbox+'"] #td_message_followup_search_' + messageClickedId).find(".flag-edited")
 								.find("img").attr("src", "../prototype/modules/mail/img/flagEditor.png").css("margin-left","0");
+							DataLayer.commit();	
+							updateCacheFollowupflag(messageClickedId, mailbox, false);
 						}else{
 							$('tr[role="'+messageClickedId+'_'+mailbox+'"] #td_message_followup_search_' + messageClickedId).find(".flag-edited").css("background", '#CCC');
@@ -591,5 +600,5 @@
 						//TODO - open dialog
 					}
-					if(!DataLayer.commit()){}
+					//if(!){}
 
 				});				
Index: /trunk/expressoMail1_2/js/draw_api.js
===================================================================
--- /trunk/expressoMail1_2/js/draw_api.js	(revision 5624)
+++ /trunk/expressoMail1_2/js/draw_api.js	(revision 5625)
@@ -1033,5 +1033,5 @@
 			filter: ['AND', ['IN', 'messageNumber', messageNumbers], ['=', 'folderName', msg_folder]],
 			criteria: {deepness: 2}
-		});
+		}, true);
 
 	if(labeleds) {
@@ -1056,5 +1056,5 @@
 				deepness: 1
 			}
-		});
+		}, true);
 
 	if(followupflaggeds) {
@@ -1696,6 +1696,10 @@
 				//$(this).find(".flag-edited").css("background", headers_msgs.followupflagged.backgroundColor);
 				headers_msgs.followupflagged.id = DataLayer.put('followupflagged', headers_msgs.followupflagged);
+				DataLayer.commit(false, false, function(){
+					updateCacheFollowupflag(messageClickedId, msg_folder, true);
+				});
 				
-			} else if (headers_msgs.followupflagged.followupflag.name == 'Follow up') {
+				
+			} else if (onceOpenedHeadersMessages[msg_folder][messageClickedId]['followupflagged'].followupflag.name == 'Follow up') {
 				/**
 				 * Remove followupflag de Acompanhamento
@@ -1709,4 +1713,6 @@
 					'tr[role="'+messageClickedId+'_'+msg_folder+'"] #td_message_followup_search_' + messageClickedId).find(".flag-edited")
 					.find("img").attr("src", "../prototype/modules/mail/img/flagEditor.png").css("margin-left","0");
+				DataLayer.commit();	
+				updateCacheFollowupflag(messageClickedId, msg_folder, false);
 			} else {
 				$(tr_element).addClass('selected_msg').find(':checkbox').trigger('click');
@@ -1714,5 +1720,4 @@
 			}
 			
-			DataLayer.commit();
 			
 		});	
Index: /trunk/expressoMail1_2/js/doiMenuData.js
===================================================================
--- /trunk/expressoMail1_2/js/doiMenuData.js	(revision 5605)
+++ /trunk/expressoMail1_2/js/doiMenuData.js	(revision 5625)
@@ -1,43 +1,6 @@
-function openListUsers(border_id) {
-	connector.loadScript("QuickCatalogSearch");
-	if (typeof(QuickCatalogSearch) == 'undefined'){
-					setTimeout('openListUsers('+border_id+')',500);
-					return false;
-				}
-	QuickCatalogSearch.showCatalogList(border_id);
-}
-
-
-/**
- * Cria a lista de marcadores para o submenu "Marcadores"
- */
-function getLabels(){
-	var labels = DataLayer.get('label',{criteria:{order: 'name'}});
-	var menuLabelItems = {};
-	for(var i=0; i<labels.length; i++) {
-		menuLabelItems["label"+labels[i].id] = {
-			"name" : labels[i].name,
-		}
-	}
-	return menuLabelItems;
-}
-
-/**
- *	Carrega o menu de opÃ§Ã£o de uma mensagem
- */
-function loadMenu(){
-	var labelItems = getLabels();
-	$.contextMenu({
-		selector: ".table_box tbody tr",
-		callback: function(key, options) {
-			//TODO - default actions
-			
-			/** 
-			 * Apply labels to selected messages
-			 */
-			var isLabel = key.match(/label(.*)/);
-			if (isLabel && isLabel.length > 1) {
+function labeledMessages(isLabel){
+			if (isLabel) {
 				var label = {
-					id: isLabel[1]
+					id: isLabel
 				}	
 				var lableleds = new Array();
@@ -77,10 +40,11 @@
 
 				for (var i=0; i < messages.length; i++) {
-					var hasLabel = DataLayer.get('labeled', [
+					var hasLabel = DataLayer.get('labeled', {
+						filter: [
 							'AND',
 							['=', 'labelId', label.id], 
 							['=', 'folderName', messages[i].msg_folder], 
 							['=', 'messageNumber', messages[i].msg_number]
-					]);
+					]});
 					if (!hasLabel || hasLabel == "") {
 						lableleds.push(
@@ -94,10 +58,60 @@
 					}
 				}
-				DataLayer.commit();
-				for (var i=0; i < messages.length; i++) {
-					updateLabelsColumn({msg_number:messages[i].msg_number, boxname:messages[i].msg_folder, labels:false});
+				DataLayer.commit(false, false, function(data){
+					for (var i=0; i < messages.length; i++) {
+						updateLabelsColumn({msg_number:messages[i].msg_number, boxname:messages[i].msg_folder, labels:false});
+					}		
+				});
+				
+
+			}
+}
+
+function openListUsers(border_id) {
+	connector.loadScript("QuickCatalogSearch");
+	if (typeof(QuickCatalogSearch) == 'undefined'){
+					setTimeout('openListUsers('+border_id+')',500);
+					return false;
 				}
-
+	QuickCatalogSearch.showCatalogList(border_id);
+}
+
+
+/**
+ * Cria a lista de marcadores para o submenu "Marcadores"
+ */
+function getLabels(){
+	var labels = DataLayer.get('label',{criteria:{order: 'name'}});
+	var menuLabelItems = {};
+		menuLabelItems["new"] = {
+			"name" : 'Novo Marcador',
+			callback:function() {configureLabels({applyToSelectedMessages:true});}
+		};
+	for(var i=0; i<labels.length; i++) {
+		menuLabelItems["label"+labels[i].id] = {
+			"name" : labels[i].name,
+		}
+	}
+	return menuLabelItems;
+}
+
+/**
+ *	Carrega o menu de opÃ§Ã£o de uma mensagem
+ */
+function loadMenu(){
+	var labelItems = getLabels();
+	$.contextMenu({
+		selector: ".table_box tbody tr",
+		callback: function(key, options) {
+			//TODO - default actions
+			
+			/** 
+			 * Apply labels to selected messages
+			 */
+			var isLabel = key.match(/label(.*)/);
+			if (isLabel && isLabel.length > 1) {
+				labeledMessages(isLabel[1]);
 			}
+
 		},
 		items: {
