Index: sandbox/expressoServiceImap/prototype/services/ImapServiceAdapter.php
===================================================================
--- sandbox/expressoServiceImap/prototype/services/ImapServiceAdapter.php	(revision 6486)
+++ sandbox/expressoServiceImap/prototype/services/ImapServiceAdapter.php	(revision 6529)
@@ -88,29 +88,12 @@
 			case 'message':
 			{
-				//begin: for grid	
-// 				$page  = isset($criteria['page']) ? $criteria['page'] : 1 ; //{1}    get the requested page
-// 				$limit = isset($criteria['rows']) ? $criteria['rows'] : 10 ; //{10}   get how many rows we want to have into the grid
-// 				$sidx  = isset($criteria['sidx']) ? $criteria['sidx'] : 0; //{id}   get index row - i.e. user click to sort
-// 				$sord  = isset($criteria['sord']) ? $criteria['sord'] : ''; //{desc} get the direction
-
 				$filter =  isset($criteria['filter']) ? $criteria['filter'] : '';
-
-// 				if( !$sidx ) $sidx = 1;
 
 				$folder_name =  isset($URI['folder']) ?  $URI['folder'] : str_replace( '.', $this->imap_delimiter, isset($context['folder']) ?  $context['folder'] : 'INBOX');
 			
-				$count = imap_num_msg( $this->open_mbox( $folder_name ) );
-// 
-// 				$total_pages = $count > 0 ? ceil( $count/$limit ) : 0;
-// 
-// 				if( $page > $total_pages )
-// 					$page = $total_pages;
-// 
-// 				$start = $limit * $page - $limit;
-
-				// do not put $limit*($page - 1)
-				//end: for grid
-				
-				
+				if( isset($criteria['count']) )
+				{
+				    return imap_num_msg( $this->open_mbox( $folder_name ) );
+				}
 				/**
 				 * Trata o caso específico de retorno do atributo messageId
@@ -174,12 +157,4 @@
 					}
 
-// 					$msgNumber = array();
-// 
-// 					for( $i = $start; $i < $start + $limit && isset( $filter[2][$i] ); $i++ )
-// 					  $msgNumber[] = $filter[2][$i];
-// 
-// 					if( empty( $msgNumber ) )
-// 					return( false );
-
 					$result = $this->get_info_msgs( array( 'folder' => $folder_name, 
 									   'msgs_number' => implode( ',', $filter[2] ) ) );
@@ -204,7 +179,5 @@
 				//return var_export($result);
 
-				$response = array( "page" => $count > 0 ? ceil( $criteria['offset'] / $criteria['limit'] ) + 1 : 0, 
-						   "total" => $count > 0 ? ceil( $count/$criteria['limit'] ) : 0, 
-						   "records" => $count );
+				$response = array();
 				
 				for ($i=0; $i<count($result); $i++)
@@ -222,11 +195,11 @@
 					if (array_key_exists($i, $result))
 					{
-						$response["rows"][$i] = $result[$i];
-						$response["rows"][$i]['timestamp'] = $result[$i]['udate'] * 1000;
-						$response["rows"][$i]['flags'] = implode(',', $flags_enum);
-						$response["rows"][$i]['size'] = $response["rows"][$i]['Size'];
-						$response["rows"][$i]['folder'] = $folder_name; 
+						$response[$i] = $result[$i];
+						$response[$i]['timestamp'] = $result[$i]['udate'] * 1000;
+						$response[$i]['flags'] = implode(',', $flags_enum);
+						$response[$i]['size'] = $response["rows"][$i]['Size'];
+						$response[$i]['folder'] = $folder_name; 
 						//$response["rows"][$i]['udate'] = ( $result[$i]['udate'] + $this->functions->CalculateDateOffset()  * 1000 );
-						unset($response["rows"][$i]['Size']);
+						unset($response[$i]['Size']);
 					}
 				 }
Index: sandbox/expressoServiceImap/prototype/modules/attach_message/attach_message.js
===================================================================
--- sandbox/expressoServiceImap/prototype/modules/attach_message/attach_message.js	(revision 6509)
+++ sandbox/expressoServiceImap/prototype/modules/attach_message/attach_message.js	(revision 6529)
@@ -43,4 +43,5 @@
     
     current_folder = targetId.replace(dashes, '.');
+    current_count = DataLayer.get( 'message', { criteria: { count: true } }, true );
 
      $("#message_attacher_grid").trigger("reloadGrid")
@@ -70,6 +71,6 @@
 	    {name:'from.name', index:'msg_number', width:70,  sortable:false, formatter:NormaliseFrom},
 	    {name:'subject',   index:'subject',    width:245, sortable:false, formatter:NormaliseSubject},
-	    {name:'timestamp', index:'timestamp',  width:65,  sortable:false, formatter:date2Time,  align:"center"},
-	    {name:'size',      index:'size',       width:55,  sortable:false, formatter:bytes2Size, align:"right"}
+	    {name:'timestamp', index:'timestamp',  width:65,  sortable:false, formatter:date2Time,   align:"center"},
+	    {name:'size',      index:'size',       width:55,  sortable:false, formatter:bytes2Size,  align:"right"}
     ],
     jsonReader : {
Index: sandbox/expressoServiceImap/prototype/modules/filters/filters.js
===================================================================
--- sandbox/expressoServiceImap/prototype/modules/filters/filters.js	(revision 6486)
+++ sandbox/expressoServiceImap/prototype/modules/filters/filters.js	(revision 6529)
@@ -1,2 +1,13 @@
+keys = function( object ){
+
+  var array = [];
+
+  for( var key in object )
+       array[ array.length ] = key;
+
+  return( array );
+
+}
+
 /* Verifica se a regra fora de escritÃ³rio estÃ¡ ativa */
 function outOfficeVerify() {
@@ -112,45 +123,34 @@
 }
 
-bytes2Size = function(bytes) {
-	var sizes = ['B', 'KB', 'MB', 'GB', 'TB'];
-	if (bytes === 0) return 'n/a';
-	var i = parseInt(Math.floor(Math.log(bytes) / Math.log(1024)));
-	var size = (i<2) ? Math.round((bytes / Math.pow(1024, i))) : Math.round((bytes / Math.pow(1024, i)) * 100)/100;
-	return  size + ' ' + sizes[i];
-};
-
-flags2Class = function(cellvalue) {
-	var flags_enum = cellvalue.split(',');
-	var classes = '';
-	for (var i=0; i<flags_enum.length; i++){
-		classes += '<span class="icon-'+flags_enum[i].toLowerCase()+'"> </span>';
-	}
-	return classes;
-};
-
-date2Time = function (timestamp) {
-	var date = new Date();
-	if( typeof timestamp === "string" )
-	    timestamp = parseInt( timestamp, 10 );
-	if ((date.getTime() - timestamp) < (24*60*60*1000)) {
-		return '<span class="timable" title="'+timestamp+'"> </span>';
-	} else {
-		date = new Date(timestamp);
-		var b = date.toISOString().split("T")[0].split("-");
-		var c = b[2] + "/" + b[1] + "/" + b[0];
-		return '<span class="datable">' + c + '</span>';
-	}
-};
-
-keys = function( object ){
-
-  var array = [];
-
-  for( var key in object )
-       array[ array.length ] = key;
-
-  return( array );
-
-}
+// bytes2Size = function(bytes) {
+// 	var sizes = ['B', 'KB', 'MB', 'GB', 'TB'];
+// 	if (bytes === 0) return 'n/a';
+// 	var i = parseInt(Math.floor(Math.log(bytes) / Math.log(1024)));
+// 	var size = (i<2) ? Math.round((bytes / Math.pow(1024, i))) : Math.round((bytes / Math.pow(1024, i)) * 100)/100;
+// 	return  size + ' ' + sizes[i];
+// };
+
+// flags2Class2 = function(cellvalue) {
+// 	var flags_enum = cellvalue.split(',');
+// 	var classes = '';
+// 	for (var i=0; i<flags_enum.length; i++){
+// 		classes += '<span class="icon-'+flags_enum[i].toLowerCase()+'"> </span>';
+// 	}
+// 	return classes;
+// };
+
+// date2Time = function (timestamp) {
+// 	var date = new Date();
+// 	if( typeof timestamp === "string" )
+// 	    timestamp = parseInt( timestamp, 10 );
+// 	if ((date.getTime() - timestamp) < (24*60*60*1000)) {
+// 		return '<span class="timable" title="'+timestamp+'"> </span>';
+// 	} else {
+// 		date = new Date(timestamp);
+// 		var b = date.toISOString().split("T")[0].split("-");
+// 		var c = b[2] + "/" + b[1] + "/" + b[0];
+// 		return '<span class="datable">' + c + '</span>';
+// 	}
+// };
 
 /* Mostra os detalhes do filtro para ediÃ§Ã£o */
@@ -348,14 +348,4 @@
 }
 
-
-DataLayer.codec( 'message', 'jqGrid', {
-
-      encoder: function( data ){
-
-	  return( data );
-
-      }
-});
-
 /* Gerencia o grid das mensagens da caixa de entrada */
 function showGridMessages(thiss) {
@@ -407,27 +397,43 @@
 	var total = data.length ? Math.ceil( data.length / numRows ) : 0;
 
-	delete DataLayer.criterias['message:jqGrid'];	
-	DataLayer.register( 'criterias', 'message:jqGrid', function( crit ){
-
-		    if( crit.page > total )
-			crit.page = total;
-
-		    var start = crit.rows * ( crit.page - 1 );
-
-		    var msgNumber = [];
-
-		    for( var i = start; i < start + crit.rows && !!data[i]; i++ )
-			msgNumber.push( data[i] );
-
-		    if( !msgNumber.length )
-			return( false );
-
-		    return { filter: [ "msgNumber", "IN", msgNumber ], criteria: { properties: { context: { folder: 'INBOX' }, order: crit.sidx } } };
-	});
+	delete DataLayer.criterias['message:inboxSearch'];
+	delete DataLayer.encoders['message:inboxSearch'];
+
+	DataLayer.codec( 'message', 'inboxSearch', {
+
+		  encoder: function( dt, crit ){
+
+		      return({"rows": dt, 
+			      "records": data.length,
+			      "page": crit.criteria.properties.context.page, 
+			      "total": total});
+
+		  },
+		  criteria: function( crit ){
+
+		      if( crit.page > total )
+			  crit.page = total;
+
+		      var start = crit.rows * ( crit.page - 1 );
+		      
+		      start / crit.rows + 1
+
+		      var msgNumber = [];
+
+		      for( var i = start; i < start + crit.rows && !!data[i]; i++ )
+			  msgNumber.push( data[i] );
+
+		      if( !msgNumber.length )
+			  return( false );
+
+		      return { filter: [ "msgNumber", "IN", msgNumber ], criteria: { properties: { context: { folder: 'INBOX', page: crit.page }, order: crit.sidx } } };
+
+		  }
+	  });
 
 	allMessages = data;
 
 	if (typeof grid !== "undefined") {
-		grid.jqGrid( 'setGridParam', { url: 'message:jqGrid', postData: data } ).trigger( 'reloadGrid' );
+		grid/*.jqGrid( 'setGridParam', { url: 'message:inboxSearch', postData: data } )*/.trigger( 'reloadGrid' );
 		//return;
 	}
@@ -435,5 +441,5 @@
 	.html('<table class="hidden fields-search-messages-grid" id="fields-search-messages-grid"><tr><td/></tr></table><div class="hidden fields-search-messages-grid-pager" id="fields-search-messages-grid-pager"></div>')
 	.children(".fields-search-messages-grid, .fields-search-messages-grid-pager").removeClass('hidden').filter(".fields-search-messages-grid").trigger( 'reloadGrid' ).jqGrid({
-		url: 'message:jqGrid',
+		url: 'message:inboxSearch',
 		datatype: "json",
 		mtype: 'GET',
