Index: /trunk/prototype/modules/filters/interceptors/FilterMapping.php
===================================================================
--- /trunk/prototype/modules/filters/interceptors/FilterMapping.php	(revision 6377)
+++ /trunk/prototype/modules/filters/interceptors/FilterMapping.php	(revision 6392)
@@ -58,5 +58,5 @@
 {
 	var $service;
-	
+	var $msgs_apply = array();
 	/**
 	* Método que cria o ID da regra que está sendo criada.
@@ -282,4 +282,10 @@
 		{
 		  $script_rules .= "vacation" . $vacation_action . "\r\n";
+		}
+
+		foreach ($rules as &$values) {						
+			if($values['applyMessages'])
+				$this->msgs_apply[] = $values['applyMessages'];
+			$values['applyMessages'] = array();
 		}
 
@@ -501,5 +507,4 @@
 			$this->rules = array();
 		}
-		
 		return( $this->rules );
 	}
@@ -522,36 +527,28 @@
 	public function applySieveFilter( &$uri , &$result , &$criteria , $original  )
 	{
+		$rule_apply = array(); 
+			
+		$filter = Controller::read($uri);
+		$filter_ = $this->parseSieveScript($filter['content']);
 		
-		//if() 			
-		//{						
-			$rule_apply = array(); 
+		foreach ($filter_ as $f_) {
+			if($f_['id'] == $uri['id']) { 
+				$rule_apply	= $f_;
+			}
+		}
+				
+		$actions = array();
+		$actions['type'] = $rule_apply['actions'][0]['type'];
+		$actions['parameter'] = $rule_apply['actions'][0]['parameter'];
+		/* Hardcoded */
+		$actions['keep'] = false;
+
+		//$messages = $rule_apply['applyMessages'];
+		$messages = $this->msgs_apply[0];
+		$this->msgs_apply = array();
 			
-			$filter = Controller::read($uri);
-			$filter_ = $this->parseSieveScript($filter['content']);
-			
-			foreach ($filter_ as $f_) {
-				if($f_['id'] == $uri['id']) { 
-					$rule_apply	= $f_;
-				}
-			}
-					
-			$actions = array();
-			$actions['type']      = $rule_apply['actions'][0]['type'];
-			$actions['parameter'] = $rule_apply['actions'][0]['parameter'];
-			/* Hardcoded */
-			$actions['keep']      = false;
-
-			$messages_to_apply = array();			
-
-			$messages = $rule_apply['applyMessages'];
-			/*	  
-			$proc = array();
-			$proc['keep'] = false;
-				 
-			*/
-			$imap = Controller::service( 'Imap' );
-			$imap->apliSieveFilter($messages, $actions); 
-			return $result;
-		//}
+		$imap = Controller::service( 'Imap' );
+		$imap->apliSieveFilter($messages, $actions); 
+		return $result;
 	}
 
@@ -596,5 +593,5 @@
 	{
 		if( !$this->rules )
-		$this->rules = $this->getRules();
+			$this->rules = $this->getRules();
 
 	    $uri['id'] = $params['id'] = isset($params['id']) ? $params['id'] : urlencode($params['name']);
@@ -633,6 +630,4 @@
 		$params['id'] = $uri['id'];
 
-		$update = false;
-		
 		$rules = array();
 
Index: /trunk/prototype/modules/filters/filters.js
===================================================================
--- /trunk/prototype/modules/filters/filters.js	(revision 6387)
+++ /trunk/prototype/modules/filters/filters.js	(revision 6392)
@@ -1,2 +1,3 @@
+/* Verifica se a regra fora de escritório está ativa */
 function outOfficeVerify() { 	
 	DataLayer.remove('filter', false);
@@ -17,4 +18,5 @@
 }
 
+/* Valida as informações do formulário de filtro de mensagens */
 valid_save = function(){
 	var accord = list_container.find(".rule-details-container").accordion({autoHeight: false});
@@ -92,5 +94,5 @@
 		}
 		var er_mail = RegExp(/^[A-Za-z0-9_\-\.]+@[A-Za-z0-9_\-\.]{2,}\.[A-Za-z0-9]{2,}(\.[A-Za-z0-9])?/);
-		if(er_mail.test($.trim(list_container.find('[value="redirect"]:checked').parent().find("input:text, textarea").val())) == false){
+		if(er_mail.test($.trim(list_container.find('[value="redirect"]:checked').parent().find("input:text").val())) == false && list_container.find('[name="actionType[]"]:checked').val() == 'redirect'){
 			$.Zebra_Dialog(get_lang("Invalid mail"),{
 				'onClose':  function(caption) {
@@ -103,4 +105,10 @@
 	return true;
 };
+
+function urlencode (str) {
+    str = (str + '').toString();
+    return encodeURIComponent(str).replace(/!/g, '%21').replace(/'/g, '%27').replace(/\(/g, '%28').
+    replace(/\)/g, '%29').replace(/\*/g, '%2A').replace(/%20/g, '+');
+}
 
 bytes2Size = function(bytes) {
@@ -144,4 +152,5 @@
 }
 
+/* Mostra os detalhes do filtro para edição */
 showDetails = function( filter ){
   
@@ -173,5 +182,4 @@
 }
 
-/* --- ------ --- */
 
 DataLayer.codec( "filter", "detail", {
@@ -190,8 +198,8 @@
 
 	var apply_messages_ = keys(selectedMessages);
-	delete selectedMessages; 
-
+	
+	action = '';
+	
     return {
-		//id: form.name,
 		name: form.name ? form.name.replace(/&/g,'&amp;').replace(/</g,'&lt;').replace(/>/g,'&gt;') : nameObj.val().replace(/&/g,'&amp;').replace(/</g,'&lt;').replace(/>/g,'&gt;'),
 		isExact: ( form.isExact === "and" ),
@@ -231,4 +239,5 @@
 			if (type == 'setflag') { 
 				the_parameter = form.valueSetFlag;
+				action = form.valueSetFlag;
 			}
 			return (!type) ? null:
@@ -253,9 +262,8 @@
 });
 
+/* Codec do datalayer */
 DataLayer.codec( "folder", "select", {
   
   decoder:function(){
-
-      
     
   },
@@ -293,7 +301,4 @@
 });
 
-
-
-
 var BASE_PATH = '../prototype/';
 
@@ -304,11 +309,11 @@
 var allMessages = false;
 
+/* Bloqueio de usuários na tela de mensagem do ExpressoMail */
 function block_user_email(email) { 
-	//var id = "block_"+email;
-	var idd = email;
+	delete selectedMessages;
+	var idd = urlencode(email);
 	/** TODO - Mudar quando API abstrair atualizações no cache */
 	DataLayer.remove('filter', false);
 	var filters = DataLayer.get('filter');
-	//var filters = DataLayer.get("filter", true);
 	for(var index in filters){
 		if(filters[index].name == email) {
@@ -341,4 +346,5 @@
 }
 
+/* Gerencia o grid das mensagens da caixa de entrada */
 function showGridMessages(thiss) {
 	var criteria_list = list_container.find('[name="criteriaValue[]"]');
@@ -453,4 +459,12 @@
 					}
 				},
+				onSelectAll: function (id, selected) {					
+					for (i in id) {
+						if(selected)
+							selectedMessages[id[i]] = true;
+						else
+							delete selectedMessages[id[i]];	
+					}
+				},
 				caption: 'Mensagens que atendem aos crit&eacute;rios'
 			}); // end jqGrid
@@ -459,7 +473,10 @@
 }
 
-
+/* Gerencia a listagem de filtros do usuário */
 function list_filters(html){
 	outOfficeVerify();
+	for (var index in selectedMessages) {
+		delete selectedMessages[index];
+	}
 	if(html){
 		if( ! $(".filters-windows").length )
@@ -553,14 +570,19 @@
 					else
 						return;
-					DataLayer.commit( 'filter', false,function(){
+					DataLayer.commit( 'filter', false,function(){						
+						if($('#gbox_fields-search-messages-grid').length > 0 && action != '') {	
+							for (var index in selectedMessages) {
+								set_message_flag(index, action, false);
+							}
+						}
 						DataLayer.render( BASE_PATH + 'modules/filters/init.ejs', {},list_filters);
 					});
 				}).end().filter('.button.search').click(function() {				
-				/* Valida se o usuário preencheu as informações */
-				if(valid_save())
-					showGridMessages($(this));
-				else
-					return;
-			})
+					/* Valida se o usuário preencheu as informações */
+					if(valid_save())
+						showGridMessages($(this));
+					else
+						return;
+				})
 			}else{
 				list_container.find(".vacation-details-container").removeClass("hidden");
@@ -650,6 +672,4 @@
 	});
 	
-	
-	
 	$(".button.alldelete").click(function(){
 		$.Zebra_Dialog(get_lang("Are you sure to delete the filters?"),{
@@ -662,6 +682,6 @@
 					DataLayer.remove('filter', false);
 					DataLayer.get('filter');
-					container.find('.rule-list').find('.rule').find('.select').find(':checked').parents('.rule').find('.title').each(function(i,o){
-						DataLayer.remove( 'filter', o.innerHTML );
+					container.find('.rule-list').find('.rule').find('.select').find(':checked').parents('.rule').find('.title').each(function(i,o){						
+						DataLayer.remove( 'filter', urlencode(o.innerHTML) );
 					});
 					DataLayer.commit("filter", false,function(){
@@ -698,4 +718,9 @@
 					return;
 				DataLayer.commit( 'filter',false,function(){
+					if($('#gbox_fields-search-messages-grid').length > 0 && action != '') {	
+						for (var index in selectedMessages) {
+							set_message_flag(index, action, false);
+						}
+					}
 					DataLayer.render( BASE_PATH + 'modules/filters/init.ejs', {},list_filters);
 				});
@@ -717,23 +742,20 @@
 			list_container.find(".button").button().filter(".back").click(function(){
 				DataLayer.render( BASE_PATH + 'modules/filters/init.ejs', {},list_filters);
-			}).end().filter(".submit").click(function(){
-			
-			if(list_container.find(".vacation-details-container .filter-textarea").val().length <= 0){
-					alert(get_lang('Write a message'));
-					list_container.find(".vacation-details-container .filter-textarea").focus();
-			}else{
-				$(this).submit();
-				DataLayer.commit( 'filter',false,function(){
-					DataLayer.render( BASE_PATH + 'modules/filters/init.ejs', {},list_filters);
-				});
-			}
-			
+			}).end().filter(".submit").click(function(){			
+				if(list_container.find(".vacation-details-container .filter-textarea").val().length <= 0){
+						$.Zebra_Dialog(get_lang('Write a message'));
+						list_container.find(".vacation-details-container .filter-textarea").focus();
+				}else{
+					$(this).submit();
+					DataLayer.commit( 'filter',false,function(){
+						DataLayer.render( BASE_PATH + 'modules/filters/init.ejs', {},list_filters);
+					});
+				}
 			});
 		});	
-		
-		
 	});
 }
 
+/* Inicializa os filtros e chama o list_filters */
 function  init_filters(){
 	var html = DataLayer.render( BASE_PATH + 'modules/filters/init.ejs', {});
