Index: trunk/prototype/modules/mail/interceptors/Helpers.php
===================================================================
--- trunk/prototype/modules/mail/interceptors/Helpers.php	(revision 5533)
+++ trunk/prototype/modules/mail/interceptors/Helpers.php	(revision 5540)
@@ -5,6 +5,7 @@
 
 /**
- * LABELS
+ * LABEL
  */ 
+	//labeled:after.find
 	public function deepnessLabeleds( &$uri , &$result , &$criteria , $original ){                
 
@@ -29,4 +30,5 @@
 	 * desvinculaÃ§Ã£o deste label com todas as mensagens a que estava vinculado
 	 */
+	//label:before.delete
 	public function clearAllLabeledsOfLabel( &$uri , &$result , &$criteria , $original ){
 		
@@ -45,7 +47,8 @@
 	}
 	/**
-	 * MÃ©todo a ser chamado ao listar os labeleds, uma vez que as funÃ§Ã£o de IMAP do PHP nÃ£o sÃ£o capazes de 
+	 * MÃ©todo a ser chamado ao listar os labeleds, uma vez que as funÃ§Ãµes de IMAP do PHP nÃ£o sÃ£o capazes de 
 	 * obter a lista de todos os labels e nem sÃ£o capazes de obter os labels de uma dada mensagem
 	 */
+	//labeled:before.find
 	public function makeLabelListFilter( &$uri , &$result , &$criteria , $original ){
 
@@ -76,9 +79,10 @@
 	
 /**
- * FOLLOWUPFLAGS
+ * FOLLOWUPFLAG
  */ 
 
+	//followupflagged:after.find
 	public function deepnessFollowupflaggeds( &$uri , &$result , &$criteria , $original ){                
-	
+
 		if(isset($original['criteria']['deepness']))
 		{
@@ -87,5 +91,5 @@
 				if(isset($v['followupflagId']))
 				{
-					$followupflag = Controller::find( array( 'concept' => 'followupflag' ) , false, array( 'filter' => array('=', 'id'  ,  $v['followupflagId']) ));     
+					$followupflag = Controller::find(array('concept' => 'followupflag'), false, array('filter' => array('=', 'id', $v['followupflagId']) ));     
 					$result[$i]['followupflag'] = $followupflag[0];
 				}
@@ -93,5 +97,5 @@
 				if(isset($v['messageNumber']) && isset($v['folderName']))
 				{
-					$details = $criteria['deepness'] == '1' ? 'headers' : 'all';
+					$details = $original['criteria']['deepness'] == '1' ? 'headers' : 'all';
 					
 					$imapService = new imap_functions();
@@ -104,6 +108,62 @@
 		return $result;
 	}	
-
+	
+	//followupflagged:PostgreSQL.before.find
+	public function clearFilterAtFind( &$uri , &$params , &$criteria , $original ) {
+
+		if ($criteria['filter'] && !self::in_arrayr('id', $criteria['filter'])) {
+			unset($criteria['filter']);
+		}
+	}
+	
+	/**
+	 * MÃ©todo a ser chamado ao listar os sinalizadores, uma vez que as funÃ§Ãµes de IMAP do PHP nÃ£o sÃ£o capazes de 
+	 * obter a lista de todos os sinalizadores e nem sÃ£o capazes de obter os sinalizadores de uma dada mensagem
+	 */
+	//followupflagged:PostgreSQL.after.find
+	public function doImapFind( &$uri , &$result , &$criteria , $original ){
+
+		if (!self::in_arrayr('id', $original['criteria']['filter'])) {
+			if ($result) {
+				$list = array();
+				foreach ($result as $followupflagged)
+					$list[] = $followupflagged['id'];
+					
+				$filter = array( 'IN' , 'id' , $list );
+				
+				if (isset($original['criteria']['filter']) && $original['criteria']['filter']!=NULL && count($original['criteria']['filter']) != 0)
+					$criteria['filter'] = array( 'AND', $original['criteria']['filter'], $filter );
+				else
+					$criteria['filter'] =  $filter;
+			}
+		}	
+		
+		$imap_uri = $uri;
+		$imap_uri['service'] = 'Imap';
+		$imap_result = Controller::find($imap_uri, $params, $criteria);
+		
+		/**
+		 * Mescla os dados vindos do PostgreSQL com os dados vindos do Imap
+		 */
+		$merge_result = array ();
+		foreach ($imap_result as $ir) {
+			list($messageId, $flagId) = explode('#', $ir['id']);
+			
+			foreach($result as $r) {
+				if ($r['id'] == $flagId) {
+					$r['messageNumber'] = $ir['messageNumber'];
+					$r['folderName'] = $ir['folderName'];
+					
+					$merge_result[] = $r;
+				}
+			}
+		}
+			
+		return $merge_result;
+	}
+
+	//followupflagged:PostgreSQL.before.create
 	public function letFollowupflaggedKeepUnique (&$uri , &$params , &$criteria , $original ){
+	
 		if (isset($params['folderName']) && isset($params['messageNumber'])) {
 			$filter = array ( 'AND', array('=', 'folderName', $params['folderName']), array('=', 'messageNumber', $params['messageNumber']) );
@@ -119,5 +179,5 @@
 */	
 
-	//PostgreSQL.after.create
+	//followupflagged:PostgreSQL.after.create
 	public function doImapCreate( &$uri , &$params , &$criteria , $original ) {
 	
@@ -134,28 +194,13 @@
 	}
 	
-	//PostgreSQL.before.find
-	public function doImapFind( &$uri , &$params , &$criteria , $original ) {
-		$imap_uri = $uri;
-		$imap_uri['service'] = 'Imap';
-		$result = Controller::find($imap_uri, $params, $criteria);
-		
-		if($result) {
-			/** TODO:
-			 *	- se achar no Imap, passar as referencias para o PostgresSQL para que
-			 *  seja conferida a consistÃªncia dos dados no postgres (Nota: os dados podem
-			 *  ficar inconsistentes no postgres se a mensagem for movida no Imap, assim
-			 *  messageNumber e/ou folderName podem estar desatualizados no postgres)
-			 */
-		}
-	}
-	
-	//PostgreSQL.before.read
+	//followupflagged:PostgreSQL.before.read
 	public function doImapRead( &$uri , &$params , &$criteria , $original ) {
-		$imap_uri = $uri;
-		$imap_uri['service'] = 'Imap';
-		$result = Controller::read($imap_uri, $params, $criteria);
-	}
-	
-	//PostgreSQL.before.delete
+		//TODO - read
+		//$imap_uri = $uri;
+		//$imap_uri['service'] = 'Imap';
+		//$result = Controller::read($imap_uri, $params, $criteria);
+	}	
+	
+	//followupflagged:PostgreSQL.before.delete
 	public function doImapDelete( &$uri , &$params , &$criteria , $original ) {
 		$toGetURI = $uri;
@@ -179,5 +224,5 @@
 	}
 	
-	//PostgreSQL.before.update
+	//followupflagged:PostgreSQL.before.update
 	public function doImapUpdate( &$uri , &$params , &$criteria , $original ) {
 		//TODO - update
@@ -186,9 +231,5 @@
 		//$result = Controller::update($imap_uri, $params, $criteria);
 	}
-	/*
-    public function createCalendarToSchedulable( &$uri , &$result , &$criteria , $original ){
-		Controller::create(array('concept' => 'calendarToSchedulable'), array('calendar' => $original['properties']['calendar'], 'schedulable' => $result['id'] ));
-	}
-	*/
+
 }
 
Index: trunk/prototype/modules/mail/interceptors/LabelSecure.php
===================================================================
--- trunk/prototype/modules/mail/interceptors/LabelSecure.php	(revision 5533)
+++ trunk/prototype/modules/mail/interceptors/LabelSecure.php	(revision 5540)
@@ -2,4 +2,5 @@
 class LabelSecure {	
 
+	//label:before.find
 	public function addVerifyOwnerFilter (&$uri , &$params , &$criteria , $original ){
 		
Index: trunk/prototype/modules/mail/interceptors/FollowupflagSecure.php
===================================================================
--- trunk/prototype/modules/mail/interceptors/FollowupflagSecure.php	(revision 5533)
+++ trunk/prototype/modules/mail/interceptors/FollowupflagSecure.php	(revision 5540)
@@ -2,4 +2,5 @@
 class FollowupflagSecure {	
 	
+	//followupflag:before.find
 	public function addVerifyOwnerFilter (&$uri , &$params , &$criteria , $original ){
 		
@@ -13,4 +14,5 @@
 	}  
 
+	//followupflag:before.find
 	public function addDefaultElementsFilter (&$uri , &$params , &$criteria , $original ){
 		
