Index: /trunk/prototype/modules/mail/js/followupflag.js
===================================================================
--- /trunk/prototype/modules/mail/js/followupflag.js	(revision 5547)
+++ /trunk/prototype/modules/mail/js/followupflag.js	(revision 5548)
@@ -275,7 +275,18 @@
 		var alarmDate = false;
 		var doneDate  = false;
-		
+		var folder_name;
+		var folders = [];
+		var messages = [];
 		for (var i=0; i < selectedMessageIds.length; i++ ){
+			if (currentTab == 0) {
+				folder_name = current_folder;
+			}else{
+				var id_border = currentTab.replace(/[a-zA-Z_]+/, "");
+				var tr = Element(selectedMessageIds[i]+'_s'+id_border);
+				folder_name = tr.getAttribute('name');
+			}
 			var messageNumber   = selectedMessageIds[i];
+			folders.push(folder_name);
+			
 			//var followupflag = DataLayer.get('followupflag', followupflagId.toString()),
 			var idFollowupflagged = winElement.find('.id-followup').val();
@@ -283,5 +294,5 @@
 				uid : User.me.id,
 				followupflagId : followupflagId, 
-				folderName : current_folder, 
+				folderName : folder_name, 
 				messageNumber : messageNumber, 
 				//alarmDeadline : winElement.find('[name="alarmDate"]').datepicker("getDate"), 
@@ -313,6 +324,5 @@
 			
 			$('#td_message_followup_' + messageNumber + ', ' + 
-			  '#td_message_followup_search_' + messageNumber).find(".flag-edited").css("background", backgroundColor);
-			  
+			  '#td_message_followup_search_' + messageNumber).find(".flag-edited").css("background", backgroundColor); 
 			DataLayer.put('followupflagged', followupflagged);
 		}
@@ -322,12 +332,15 @@
 			winElement.find('.id-followup').val(id);
 		});		
-		
-		//onceOpenedHeadersMessages[current_folder][followupflagged.messageNumber]['followupflagged']['followupflag'] = {};
 		var extend = DataLayer.get('followupflagged', {
-		filter: ['AND', ['IN', 'messageNumber', selectedMessageIds], ['=', 'folderName', current_folder]],criteria: {deepness: 1}});
+		filter: ['AND', ['IN', 'messageNumber', selectedMessageIds], ['IN', 'folderName', folders]],criteria: {deepness: 1}});
 		if(extend != "" || extend != 'undefined' || extend != []){
 			for(var ex = 0; ex < extend.length; ex++){
-				onceOpenedHeadersMessages[current_folder][extend[ex].messageNumber]['followupflagged'] = {};
-				DataLayer.merge(onceOpenedHeadersMessages[current_folder][extend[ex].messageNumber]['followupflagged'], extend[ex]);
+				if(onceOpenedHeadersMessages[extend[ex].folderName]){
+					if(onceOpenedHeadersMessages[extend[ex].folderName][extend[ex].messageNumber]){
+						onceOpenedHeadersMessages[extend[ex].folderName][extend[ex].messageNumber]['followupflagged'] = {};
+						DataLayer.merge(onceOpenedHeadersMessages[extend[ex].folderName][extend[ex].messageNumber]['followupflagged'], extend[ex]);
+					}
+				}
+
 			}
 		} else {
@@ -338,10 +351,22 @@
 	.filter('.menu-configure-followupflag .delete').click(function(){
 		for(i = 0; i < selectedMessageIds.length; i++){
+			var folder_name;
+			if (currentTab == 0) {
+				folder_name = current_folder;
+			}else{
+				var id_border = currentTab.replace(/[a-zA-Z_]+/, "");
+				var tr = Element(selectedMessageIds[i]+'_s'+id_border);
+				folder_name = tr.getAttribute('name');
+			}
 			var messageNumber   = selectedMessageIds[i];
-			var flag_id = onceOpenedHeadersMessages[current_folder][messageNumber]['followupflagged'].id;
-			var flagged = $('#td_message_followup_' + messageNumber + ', ' + '#td_message_followup_search_' + messageNumber).find(".flag-edited");
-			DataLayer.remove('followupflagged', flag_id);
-			flagged.css("background", '#cccccc');
-			flagged.find("img").attr("src", "../prototype/modules/mail/img/flagEditor.png").css("margin-left","0");
+			if(onceOpenedHeadersMessages[folder_name][messageNumber]['followupflagged']){
+				var flag_id = onceOpenedHeadersMessages[folder_name][messageNumber]['followupflagged'].id;
+				DataLayer.remove('followupflagged', flag_id);
+				$('#td_message_followup_' + messageNumber + ', ' + 
+				  '#td_message_followup_search_' + messageNumber).find(".flag-edited").css("background", '#CCC');
+				$('#td_message_followup_' + messageNumber + ', ' + 
+					'#td_message_followup_search_' + messageNumber).find(".flag-edited")
+					.find("img").attr("src", "../prototype/modules/mail/img/flagEditor.png").css("margin-left","0");
+			}
 		}
 		DataLayer.commit();
Index: /trunk/expressoMail1_2/inc/class.imap_functions.inc.php
===================================================================
--- /trunk/expressoMail1_2/inc/class.imap_functions.inc.php	(revision 5541)
+++ /trunk/expressoMail1_2/inc/class.imap_functions.inc.php	(revision 5548)
@@ -5193,5 +5193,4 @@
 				{
 					$followupflag = Controller::read( array( 'concept' => 'followupflag', 'id' => $followupflagged[0]['followupflagId'] ));     
-					//$followupflagged[0]['followupflag'] = [];
 					$followupflagged[0]['followupflag'] = $followupflag;
 					$return['msgs'][$i]['followupflagged'] = $followupflagged[0];
Index: /trunk/expressoMail1_2/js/search.js
===================================================================
--- /trunk/expressoMail1_2/js/search.js	(revision 5533)
+++ /trunk/expressoMail1_2/js/search.js	(revision 5548)
@@ -442,5 +442,4 @@
 	
 	searchE.prototype.make_tr_message = function(aux,border_id,i) {
-	console.log(aux);
 	/**
 	 * Preenche a estrutura de cache de mensagens para posterior consulta de 
@@ -460,4 +459,6 @@
 		var uid_msg = aux.uid;
 		var subject = aux.subject;
+		var labels = aux.labels;
+		var followupflagged = aux.followupflagged;
 
 		tr.id = uid_msg+"_s"+numBox;
@@ -555,5 +556,7 @@
 							followupflag: DataLayer.get('followupflag', '1')
 						};
-						$(this).find(".flag-edited").css("background", aux.followupflagged.backgroundColor);
+						$('#td_message_followup_' + messageClickedId + ', ' + 
+						'#td_message_followup_search_' + messageClickedId).find(".flag-edited").css("background", aux.followupflagged.backgroundColor);						
+						//$(this).find(".flag-edited").css("background", aux.followupflagged.backgroundColor);
 						aux.followupflagged.id = DataLayer.put('followupflagged', aux.followupflagged);
 						
@@ -567,6 +570,8 @@
 						DataLayer.remove('followupflagged', flagged[0].id);
 						$('#td_message_followup_' + messageClickedId + ', ' + 
-						'#td_message_followup_search_' + messageClickedId).find(".flag-edited")
-						.find("img").attr("src", "../prototype/modules/mail/img/flagEditor.png").css("margin-left","0");
+						  '#td_message_followup_search_' + messageClickedId).find(".flag-edited").css("background", '#CCC');
+						$('#td_message_followup_' + messageClickedId + ', ' + 
+							'#td_message_followup_search_' + messageClickedId).find(".flag-edited")
+							.find("img").attr("src", "../prototype/modules/mail/img/flagEditor.png").css("margin-left","0");
 					} else {
 						//TODO - open dialog
@@ -717,4 +722,5 @@
 				}
 				
+
 				tr.appendChild(td);
 			}
@@ -792,4 +798,59 @@
 		if ( data == undefined )
 			return;
+
+		//////////////////////////////////////////////////////////////////////
+		/**
+		 * Get the labels aplyed to the messages and saves the information 
+		 * into message array 
+		 */
+
+		var msg_folder = get_current_folder(); 
+		var messageNumbers = new Array();
+		var messageFolders = new Array();
+		for (var i=0; i<data.length; i++) {
+			messageNumbers.push(data[i].uid);
+			messageFolders.push(data[i].boxname);
+		}
+		
+
+		// var labeleds = DataLayer.get('labeled', {
+				// filter: ['AND', ['IN', 'messageNumber', messageNumbers], ['=', 'folderName', messageFolders]],
+				// criteria: {deepness: 2}
+		// });
+
+		// if(labeleds) {
+			// for (var i=0; i<data.length; i++) {
+				// for (var j=0; j<labeleds.length; j++) {
+					// if (labeleds[j].messageNumber == data[i].uid) {
+						// if (!data[i].labels)
+							// data[i].labels = {};
+						// data[i].labels[labeleds[j].label.id] = labeleds[j].label;
+					// }
+				// }
+			// }
+		// }
+
+		/**
+		 * Get the followupflags aplyed to the messages and saves the information 
+		 * into message array 
+		 */
+		 
+		// var followupflaggeds = DataLayer.get('followupflagged', {
+				// filter: ['AND', ['IN', 'messageNumber', messageNumbers], ['=', 'folderName', messageFolders]],
+				// criteria: {deepness: 2}
+			// });
+
+		// if(followupflaggeds) {
+			// for (var i=0; i<data.length; i++) {
+				// for (var j=0; j<followupflaggeds.length; j++) {
+					// if (followupflaggeds[j].messageNumber == data[i].uid) {
+						// if (!data[i].followupflagged)
+							// data[i].followupflagged = {};
+						// data[i].followupflagged = followupflaggeds[j];
+					// }
+				// }
+			// }
+		// }
+		/////////////////////////////////////////////////////////////////////////
 	
 		var cont = parseInt(0);
Index: /trunk/expressoMail1_2/js/draw_api.js
===================================================================
--- /trunk/expressoMail1_2/js/draw_api.js	(revision 5544)
+++ /trunk/expressoMail1_2/js/draw_api.js	(revision 5548)
@@ -1687,5 +1687,7 @@
 					followupflag: DataLayer.get('followupflag', '1')
 				};
-				$(this).find(".flag-edited").css("background", headers_msgs.followupflagged.backgroundColor);
+				$('#td_message_followup_' + messageClickedId + ', ' + 
+				'#td_message_followup_search_' + messageClickedId).find(".flag-edited").css("background", headers_msgs.followupflagged.backgroundColor);
+				//$(this).find(".flag-edited").css("background", headers_msgs.followupflagged.backgroundColor);
 				headers_msgs.followupflagged.id = DataLayer.put('followupflagged', headers_msgs.followupflagged);
 				
@@ -1696,9 +1698,10 @@
 				 $(this).find(".flag-edited").css("background", "#cccccc");
 
-
 				DataLayer.remove('followupflagged', flagged[0].id);
 				$('#td_message_followup_' + messageClickedId + ', ' + 
-				'#td_message_followup_search_' + messageClickedId).find(".flag-edited")
-				.find("img").attr("src", "../prototype/modules/mail/img/flagEditor.png").css("margin-left","0");
+				  '#td_message_followup_search_' + messageClickedId).find(".flag-edited").css("background", '#CCC');
+				$('#td_message_followup_' + messageClickedId + ', ' + 
+					'#td_message_followup_search_' + messageClickedId).find(".flag-edited")
+					.find("img").attr("src", "../prototype/modules/mail/img/flagEditor.png").css("margin-left","0");
 			} else {
 				$(tr_element).addClass('selected_msg').find(':checkbox').trigger('click');
Index: /trunk/expressoMail1_2/js/doiMenuData.js
===================================================================
--- /trunk/expressoMail1_2/js/doiMenuData.js	(revision 5539)
+++ /trunk/expressoMail1_2/js/doiMenuData.js	(revision 5548)
@@ -42,9 +42,25 @@
 				}	
 				var lableleds = new Array();
-				
+				var msg_folder = current_folder;
+				var messages = [];
 				if(currentTab == 0){
-					var messages = get_selected_messages().split(',');
+					var id = get_selected_messages().split(',');
+					for (i = 0; i < id.length; i++){
+						messages.push({
+							"msg_number": id[i],
+							"msg_folder": msg_folder,
+						});
+					}
 				}else{
-					var messages = get_selected_messages_search().split(',');
+					var id = get_selected_messages_search().split(',');
+					var id_border = currentTab.replace(/[a-zA-Z_]+/, "");
+					for (i = 0; i < id.length; i++){
+						var tr = Element(id[i]+'_s'+id_border);
+						msg_folder = tr.getAttribute('name'); 
+						messages.push({
+							"msg_number": id[i],
+							"msg_folder": msg_folder,
+						});
+					}	
 				}
 
@@ -53,6 +69,6 @@
 							'AND',
 							['=', 'labelId', label.id], 
-							['=', 'folderName', current_folder], 
-							['=', 'messageNumber', messages[i]]
+							['=', 'folderName', messages[i].msg_folder], 
+							['=', 'messageNumber', messages[i].msg_number]
 					]);
 					if (!hasLabel) {
@@ -60,6 +76,6 @@
 							DataLayer.put('labeled', {
 								labelId:label.id, 
-								folderName:current_folder, 
-								messageNumber:messages[i]
+								folderName:messages[i].msg_folder, 
+								messageNumber:messages[i].msg_number
 							})
 						);
@@ -68,7 +84,7 @@
 				}
 				DataLayer.commit();
-				for (var i=0; i < messages.length; i++) {
-					updateLabelsColumn({msg_number:messages[i], labels:false});
-				}
+					for (var i=0; i < messages.length; i++) {
+						updateLabelsColumn({msg_number:messages[i].msg_number, boxname:messages[i].msg_folder, labels:false});
+					}
 			}
 		},
@@ -97,5 +113,5 @@
 		"i01": {"name": get_lang("Preferences"), "icon": "preferences-mail", callback: preferences_mail },
 		"i02": {"name": get_lang("Search"), "icon": "search-mail", callback: function(key, opt){ search_emails(""); }},
-		"103": {"name": get_lang("Edit filters"), "icon": "filter", callback: filterbox2 },
+		"103": {"name": get_lang("Edit filters"), "icon": "filter", callback: filterbox },
 		"i04": {"name": get_lang("Edit folders"), "icon": "edit-folder", callback: folderbox },
 		"i05": {"name": get_lang("Share mailbox"), "icon": "share-mailbox", callback: sharebox },
@@ -144,7 +160,15 @@
 
 function updateLabelsColumn(messageInfo) {
-	$('#td_message_labels_' + messageInfo.msg_number +', #td_message_labels_search_' + messageInfo.msg_number)
+	var msg_number = messageInfo.msg_number;
+	if(messageInfo.uid != '' && messageInfo.uid != 'undefined' && messageInfo.uid != null){
+		msg_number = messageInfo.uid;
+	}
+	$('#td_message_labels_' + msg_number +', #td_message_labels_search_' + msg_number)
 	.html('<img src="../prototype/modules/mail/img/tag.png">');
-
+	
+	var msg_folder = current_folder;
+	if(messageInfo.boxname != '' && messageInfo.boxname != 'undefined' && messageInfo.boxname != null){
+		msg_folder = messageInfo.boxname;
+	}
 	var menuItems = {};
 	if (messageInfo.labels) {
@@ -152,10 +176,11 @@
 	} else {
 		var labeleds = DataLayer.get('labeled', {
+			criteria: {deepness: '2',
 			filter: [
 				'AND',
-				['=', 'folderName', current_folder], 
-				['=', 'messageNumber', messageInfo.msg_number]
-			],
-			criteria: {deepness: 2}
+				['=', 'folderName', msg_folder], 
+				['=', 'messageNumber', msg_number]
+			]}
+			
 		});
 		if (labeleds) {
@@ -168,8 +193,8 @@
 	}
 
-	$.contextMenu( 'destroy', '#td_message_labels_' + messageInfo.msg_number +', #td_message_labels_search_' + messageInfo.msg_number);
+	$.contextMenu( 'destroy', '#td_message_labels_' + msg_number +', #td_message_labels_search_' + msg_number);
 
 	$.contextMenu({
-		selector: '#td_message_labels_' + messageInfo.msg_number +', #td_message_labels_search_' + messageInfo.msg_number,
+		selector: '#td_message_labels_' + msg_number +', #td_message_labels_search_' + msg_number,
 		trigger: 'hover',
 		delay:100,
