Index: trunk/prototype/modules/filters/interceptors/FilterMapping.php
===================================================================
--- trunk/prototype/modules/filters/interceptors/FilterMapping.php	(revision 5539)
+++ trunk/prototype/modules/filters/interceptors/FilterMapping.php	(revision 5601)
@@ -81,6 +81,6 @@
 		foreach( $rules as $name => $data )
 		{
-			//if( $data['enabled'] )
-				//continue;
+			if( !$data['enabled'] )
+				continue;
 
 			$criteria = $data['criteria'];
@@ -121,6 +121,6 @@
 						$require_vacation = true;
 						$vacation = true;
-						$script_match = "vacation";
-						break;
+						//$script_match = "vacation";
+						continue;
 					default:
 						$script_criteria .= "header :";
@@ -191,7 +191,7 @@
 						$require_vacation = true;
 						$action[$k]['parameter'] = "\"" . $action[$k]['parameter'] . "\"";
-						$script_action = " :subject \"Fora do EscritÃ³rio\" " . $action[$k]['parameter'] . ";";
+						$vacation_action = " :subject \"Fora do EscritÃ³rio\" " . $action[$k]['parameter'] . ";";
 						$vacation = true;
-						break;
+						continue;
 					case 'setflag':
 						$require_flag = true;
@@ -201,8 +201,8 @@
 						break;
 				}
-				if ($vacation == false) $script_action .= $action[$k]['type'] . " \"" . $action[$k]['parameter'] . "\";\r\n ";
+				/*if ($vacation == false)*/ $script_action .= $action[$k]['type'] . " \"" . $action[$k]['parameter'] . "\";\r\n ";
 			}
 
-			if ($vacation == false) $script_action .= "}";
+			/*if ($vacation == false)*/ $script_action .= "}";
 
 			$script_rules .= $script_match . $script_criteria . $script_action . "\r\n";
@@ -224,4 +224,9 @@
 		}
 
+		if( $vacation )
+		{
+		  $script_rules .= "vacation" . $vacation_action . "\r\n";
+		}
+
 		$json_data = json_encode($rules);
 		
@@ -313,23 +318,25 @@
 	public function applySieveFilter( &$uri , &$result , &$criteria , $original  )
 	{
+		 $result['id'] = $uri['id'];
+
 		 if( $original['properties']['applyMessages'] )
 		 {
-			  $filter = Controller::read($uri);
-			  
-			  $proc = array();
-			  $proc['keep'] = false;
-			  
-			  foreach ($filter['actions'] as $v){
-				  if($v['type'] == 'keep')
-					  $proc['keep'] = true;
-				  else{
-					  $proc['type'] = $v['type'];
-					  $proc['parameter'] = $v['parameter'];
-				  }
-			  }
-
-		  $imap = Controller::service( 'Imap' );
-			  $imap->apliSieveFilter($original['properties']['applyMessages'] , $proc ); 
-			  return $result;
+		      $filter = Controller::read($uri);
+
+		      $proc = array();
+		      $proc['keep'] = false;
+		      
+		      foreach ($filter['actions'] as $v){
+			      if($v['type'] == 'keep')
+				      $proc['keep'] = true;
+			      else{
+				      $proc['type'] = $v['type'];
+				      $proc['parameter'] = $v['parameter'];
+			      }
+		      }
+
+		      $imap = Controller::service( 'Imap' );
+		      $imap->apliSieveFilter($original['properties']['applyMessages'] , $proc ); 
+		      return $result;
 		  }
 	}
@@ -373,26 +380,19 @@
 	*/
 	public function setRule( &$uri , &$params , &$criteria , $original  )
-	{		
-	  if( !$this->rules )
+	{
+	    if( !$this->rules )
 		$this->rules = $this->getRules();
-	
-      $params['id'] = isset($params['id']) ? $params['id'] : $params['name'];
-      $update = false;
-
-      foreach( $this->rules as $i => $rule )
-		  if( $update = ($rule['id'] === $params['id']) )
-		  {
-			  $this->rules[$i] = $params;
-			  break;
-		  }
-
-      if( !$update )
-		$this->rules[] = $params;
-
-      $content = $this->formatSieveScript( $this->rules );
-	  
-	  $params = array( 'name' => $this->service->config['user'],
-		       'content' => $content,
-                       'active' => true );
+
+	    $uri['id'] = $params['id'] = isset($params['id']) ? $params['id'] : urlencode($params['name']);
+
+	    $i = 0;
+
+	    for( ;$this->rules[$i] && $this->rules[$i]['id'] !== $params['id']; $i++ );
+
+	    $this->rules[$i] = $params;
+
+	    $params = array( 'name' => $this->service->config['user'],
+			     'content' => $this->formatSieveScript( $this->rules ),
+			     'active' => true );
 	}
 
@@ -414,15 +414,19 @@
 	public function deleteRule( &$uri, &$params, &$criteria, $original )
 	{
-		if( !$this->rules )
-		  $this->rules = $this->getRules();
-
+		if( !$this->rules ) {	
+			$this->rules = $this->getRules();
+		}	  
 		$params['id'] = $uri['id'];
 
 		$update = false;
+		
+		$rules = array();
 
 		foreach( $this->rules as $i => $rule )
-			if( $rule['id'] === $uri['id'] )
-				unset( $this->rules[$i] );
-
+			if( $rule['id'] !== $uri['id'] )
+				$rules[] = $this->rules[$i];
+
+		$this->rules = $rules;
+		
 		$uri['id'] = '';
 
@@ -433,5 +437,5 @@
 		$URI = Controller::URI( $uri['concept'], $this->service->config['user'] );
 		$this->service->update( $URI, $params );
-
+	
 		return( false );
 	}
Index: trunk/prototype/modules/filters/filters.js
===================================================================
--- trunk/prototype/modules/filters/filters.js	(revision 5598)
+++ trunk/prototype/modules/filters/filters.js	(revision 5601)
@@ -185,5 +185,5 @@
 
 		}),
-		enabled : "enabled",
+		enabled : true,
 		applyMessages: allMessages? !$.isEmptyObject( selectedMessages ) ?
 		keys( selectedMessages ) : allMessages : ""
@@ -676,5 +676,5 @@
 	$(".ui-dialog-titlebar").after("<div class='dialog-head-buttonpane ui-dialog-buttonpane ui-widget-content ui-helper-clearfix' style='background-color: rgb(224, 238, 238); '><div class='ui-dialog-buttonset header-buttonpane'></div></div>");
 	$(".dialog-head-buttonpane").css("padding", "5px").
-	find(".header-buttonpane").html("<a href='#' class='button add' title='Adicionar nova regra'>Nova regra</a><a href='#' class='button add vacation' title='Adicionar regra 'Fora do escritorio''>Fora do escritorio</a>").find(".button").button();
+	find(".header-buttonpane").html("<a href='#' class='button add' title='Adicionar nova regra'>Nova regra</a><!--<a href='#' class='button add vacation' title='Adicionar regra 'Fora do escritorio''>Fora do escritorio</a>-->").find(".button").button();
 	
 	$(".ui-dialog-buttonpane.ui-widget-content").css("background-color", "#E0EEEE");
@@ -752,5 +752,5 @@
 	}).click(function(){
 		var id = $(this).parents("li.rule").find('.title').html();
-		DataLayer.put( 'filter', id, { enabled: "disable"  });
+		DataLayer.put( 'filter', id, { enabled: false  });
 		DataLayer.commit("filter");
 		DataLayer.render( BASE_PATH + 'modules/filters/init.ejs', {},list_filters);
@@ -764,5 +764,5 @@
 	}).click(function(){
 		var id = $(this).parents("li.rule").find('.title').html();
-		DataLayer.put( 'filter', id, { enabled: "enabled" });
+		DataLayer.put( 'filter', id, { enabled: true });
 		DataLayer.commit("filter");
 		DataLayer.render( BASE_PATH + 'modules/filters/init.ejs', {},list_filters);
Index: trunk/prototype/modules/filters/filter-list.ejs
===================================================================
--- trunk/prototype/modules/filters/filter-list.ejs	(revision 5539)
+++ trunk/prototype/modules/filters/filter-list.ejs	(revision 5601)
@@ -7,4 +7,5 @@
 		<li class="rule <%= (data.rules[i].name=='vacation')?'vacation':'' %>" title="<%= data.rules[i].name %>">
 			<strong class="title <%= (data.rules[i].enabled)? 'enable':'disable' %>"><%= data.rules[i].name %></strong>
+			<input type="hidden" class="id" value="<%= data.rules[i].id %>">
 			<dl class="rule-briefing">
 				<dt>CritÃ©rios:</dt>
