Index: sandbox/expressoServiceImap/prototype/services/ImapServiceAdapter.php
===================================================================
--- sandbox/expressoServiceImap/prototype/services/ImapServiceAdapter.php	(revision 6529)
+++ sandbox/expressoServiceImap/prototype/services/ImapServiceAdapter.php	(revision 6545)
@@ -144,5 +144,5 @@
 				if( $filter )
 				{
-					if( $filter[0] !== 'msgNumber' )
+					if( $filter[1] !== 'msgNumber' )
 					{
 					    for( $i = 0; $i < count($filter); $i++ )
@@ -158,5 +158,5 @@
 
 					$result = $this->get_info_msgs( array( 'folder' => $folder_name, 
-									   'msgs_number' => implode( ',', $filter[2] ) ) );
+									       'msgs_number' => implode( ',', $filter[2] ) ) );
 
 					foreach( $result as $i => $val )
@@ -170,5 +170,5 @@
 							'folder' => $folder_name, //INBOX
 							'msg_range_begin' => $criteria['offset'] + 1, //??
-							'msg_range_end' => $criteria['limit'], //$limit = $_GET['rows']; // get how many rows we want to have into the grid
+							'msg_range_end' => $criteria['offset'] + $criteria['limit'], //$limit = $_GET['rows']; // get how many rows we want to have into the grid
 							'sort_box_type' => 'SORTARRIVAL', 
 							'search_box_type' => 'ALL',
@@ -198,6 +198,7 @@
 						$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[$i]['size'] = $response[$i]['Size'];
+						$response[$i]['folder'] = $folder_name;
+						$response[$i]['msgNumber'] = $response[$i]['msg_number'];
 						//$response["rows"][$i]['udate'] = ( $result[$i]['udate'] + $this->functions->CalculateDateOffset()  * 1000 );
 						unset($response[$i]['Size']);
Index: sandbox/expressoServiceImap/prototype/modules/attach_message/attach_message.js
===================================================================
--- sandbox/expressoServiceImap/prototype/modules/attach_message/attach_message.js	(revision 6529)
+++ sandbox/expressoServiceImap/prototype/modules/attach_message/attach_message.js	(revision 6545)
@@ -43,5 +43,5 @@
     
     current_folder = targetId.replace(dashes, '.');
-    current_count = DataLayer.get( 'message', { criteria: { count: true } }, true );
+    current_count = DataLayer.get( 'message', { criteria: { count: true, properties: {context:{folder:current_folder}} } }, true );
 
      $("#message_attacher_grid").trigger("reloadGrid")
Index: sandbox/expressoServiceImap/prototype/modules/attach_message/common.js
===================================================================
--- sandbox/expressoServiceImap/prototype/modules/attach_message/common.js	(revision 6510)
+++ sandbox/expressoServiceImap/prototype/modules/attach_message/common.js	(revision 6545)
@@ -4,4 +4,5 @@
 months = ['Jan','Feb','Mar','Apr','May','June','July','Aug','Sept','Oct','Nov','Dec'];
 current_folder = 'INBOX';
+current_count = DataLayer.get( 'message', { criteria: { count: true, properties: {context:{folder:current_folder}} } }, true );
 
 DataLayer.codec( 'folder', 'tree', {
@@ -56,8 +57,10 @@
 
       encoder: function( data, crit ){
-
-	    if( !crit.criteria.properties.context.folder.indexOf( 'local_messages/' ) )
+	
+	    crit = crit.criteria;
+
+	    if( !crit.properties.context.folder.indexOf( 'local_messages/' ) )
 	    {
-		var msgs = expresso_local_messages.get_local_range_msgs( crit.criteria.properties.context.folder.replace(dots, "/").replace("local_messages/", ""),
+		var msgs = expresso_local_messages.get_local_range_msgs( crit.properties.context.folder.replace(dots, "/").replace("local_messages/", ""),
 									  crit.offset + 1, crit.limit, "SORTARRIVAL", crit.orderDesc, "ALL", 1, 1 );
 
@@ -75,15 +78,15 @@
 		}
 
-		return( {"rows": msgs, 
-			  "records": msgs.length,
-			  "page": crit.page, 
-			  "total": Math.ceil( msgs.num_msgs / crit.limit )} );
+		data = msgs;
 	    }
 
-	    return( data );
+	    return( {"rows": data, 
+		      "records": data.num_msgs || current_count,
+		      "page": crit.offset / crit.limit + 1, 
+		      "total": Math.ceil( data.num_msgs || current_count / crit.limit )} );
       },
       criteria: function( crit ){
 
-	    return { criteria: { properties: {context:{folder: current_folder || 'INBOX'}}, offset: crit.rows * ( crit.page - 1 ), limit: crit.rows, orderDesc: crit.sord == "desc" } };
+	    return { criteria: { properties: {context:{folder: current_folder || 'INBOX'}}, offset: crit.rows * ( crit.page - 1 ), limit: crit.rows, orderDesc: crit.sord == "desc", currentCount: current_count } };
 
       }
Index: sandbox/expressoServiceImap/prototype/modules/filters/filters.js
===================================================================
--- sandbox/expressoServiceImap/prototype/modules/filters/filters.js	(revision 6529)
+++ sandbox/expressoServiceImap/prototype/modules/filters/filters.js	(revision 6545)
@@ -397,6 +397,6 @@
 	var total = data.length ? Math.ceil( data.length / numRows ) : 0;
 
-	delete DataLayer.criterias['message:inboxSearch'];
-	delete DataLayer.encoders['message:inboxSearch'];
+// 	delete DataLayer.criterias['message:inboxSearch'];
+// 	delete DataLayer.encoders['message:inboxSearch'];
 
 	DataLayer.codec( 'message', 'inboxSearch', {
@@ -427,8 +427,8 @@
 			  return( false );
 
-		      return { filter: [ "msgNumber", "IN", msgNumber ], criteria: { properties: { context: { folder: 'INBOX', page: crit.page }, order: crit.sidx } } };
+		      return { filter: [ "IN", "msgNumber", msgNumber ], criteria: { properties: { context: { folder: 'INBOX', page: crit.page }, order: crit.sidx } } };
 
 		  }
-	  });
+	  }, true );
 
 	allMessages = data;
Index: sandbox/expressoServiceImap/prototype/api/datalayer.js
===================================================================
--- sandbox/expressoServiceImap/prototype/api/datalayer.js	(revision 6444)
+++ sandbox/expressoServiceImap/prototype/api/datalayer.js	(revision 6545)
@@ -1182,5 +1182,5 @@
 	if( !result && (bothSides || oneSide) )
 	{
-	    result = this.request( concept, id || filter.filter, filter.criteria );
+	    result = this.request( concept, id || filter.filter || false, filter.criteria );
 
 	    if( result && bothSides && (!filter || 
@@ -1957,18 +1957,18 @@
     },
 
-    codec: function( concept, namespace, codec ){
+    codec: function( concept, namespace, codec, set ){
 
 	if( codec.encoder )
-	    this.encoder( concept, namespace, codec.encoder );
+	    this.encoder( concept, namespace, codec.encoder, set );
 	if( codec.decoder )
-	    this.decoder( concept, namespace, codec.decoder );
+	    this.decoder( concept, namespace, codec.decoder, set );
 	if( codec.criteria )
-	    this.register( "criterias", concept + ":" + namespace, codec.criteria );
-
-    },
-
-    encoder: function( concept, namespace, encoder ){
-
-	this.register( "encoders", concept + ":" + namespace, encoder );
+	    this.register( "criterias", concept + ":" + namespace, codec.criteria, set );
+
+    },
+
+    encoder: function( concept, namespace, encoder, set ){
+
+	this.register( "encoders", concept + ":" + namespace, encoder, set );
 
     },
@@ -1984,7 +1984,7 @@
     },
 
-    decoder: function( concept, namespace, decoder ){
-
-	this.register( "decoders", concept + ":" + namespace, decoder );
+    decoder: function( concept, namespace, decoder, set ){
+
+	this.register( "decoders", concept + ":" + namespace, decoder, set );
 
     },
@@ -2011,5 +2011,5 @@
     },
 
-    register: function( kind, concept, deployable ){
+    register: function( kind, concept, deployable, set ){
 
       if( arguments.length < 3 )
@@ -2020,5 +2020,5 @@
       }
 
-      if( !this[ kind ][ concept ] )
+      if( !this[ kind ][ concept ] || set )
 	    this[ kind ][ concept ] = [];
 
