Index: sandbox/expressoMail1_2/MailArchiver/2.2/expressoMail1_2/js/mail_archiver.js
===================================================================
--- sandbox/expressoMail1_2/MailArchiver/2.2/expressoMail1_2/js/mail_archiver.js	(revision 4894)
+++ sandbox/expressoMail1_2/MailArchiver/2.2/expressoMail1_2/js/mail_archiver.js	(revision 4899)
@@ -730,5 +730,10 @@
         var testing_data_xml = '<?xml version="1.0" encoding="UTF-8"?><query lowerIndex="0" upperIndex="50"><folder id="'+folderid+'"/><order asc="date"/><order desc="subject"/></query>';
         var testing_data_json_mapped = '{"query":{"@lowerIndex":"0", "@upperIndex":"50", "folder":[{"@id":"'+folderid+'"}], "order":[{"@asc":"date", "@desc":"subject"}]}}';
-        var testing_data = testing_data_json_mapped;
+
+        if (expresso_mail_archive.queryconfig.folder != null)
+            var testing_data = expresso_mail_archive.queryconfig.query();
+        else
+            var testing_data = testing_data_json_mapped;
+        
         //window.alert('vai chamar o listMessages com testing_data = ' + testing_data);
         ArchiveServices.listMessages(expresso_mail_archive.listMessagesOperationOK, expresso_mail_archive.listMessagesOperationFailure, sessid, testing_data);
Index: sandbox/expressoMail1_2/MailArchiver/2.2/expressoMail1_2/js/MAQueryConfig.js
===================================================================
--- sandbox/expressoMail1_2/MailArchiver/2.2/expressoMail1_2/js/MAQueryConfig.js	(revision 4873)
+++ sandbox/expressoMail1_2/MailArchiver/2.2/expressoMail1_2/js/MAQueryConfig.js	(revision 4899)
@@ -20,7 +20,9 @@
   this.body = null;
   this.date = null;
-  this.flag = null;
+  this.tag = null;
   this.folder = null;
   this.order = null;
+  this.preview_message = null;
+  this.preview_tooltip = null;
   this.defaults = null;
 }
@@ -42,5 +44,5 @@
       this.setDate(cl[p]);
     if(p.toLowerCase() == 'flags')
-      this.setFlags(cl[p]);
+      this.setTag(cl[p]);
     if(p.toLowerCase() == 'folder')
       this.setFolder(cl[p]);
@@ -52,4 +54,38 @@
 MAQueryConfig.prototype.setDefaults = function(defaults){
     this.defaults = defaults;
+}
+
+MAQueryConfig.prototype.setExpressoDefaults = function(data_default){
+    //Expresso defaults came from "messages_controller.js": here, we maps
+    //each array entry from messages_list intended to run by our own behavior
+    if(data_default.length != 7)
+        return;
+   //expresso default argument list => new Array(baseFolder,msg_range_begin,emails_per_page,sort_box_type,sort_box_reverse,preview_msg_subject,preview_msg_tip);
+   this.setFolder(data_default[0]);
+   this.setBounds(data_default[1], data_default[2]);
+   
+   if (parseInt(data_default[4]) == 0)
+       var oexpor = 'asc';
+   else
+       var oexpor = 'desc';
+   
+   switch(data_default[3].toLowerCase()){
+       case 'sortfrom':
+           var oexpcrt = 'from';
+           break;
+       case 'sortsubject':
+           var oexpcrt = 'subject';
+           break;
+       case 'sortsize':
+           var oexpcrt = 'size';
+           break;
+       default:
+           var oexpcrt = 'date';
+           break;
+   }
+
+   var oexporder = eval('({"' + oexpcrt + '":"' + oexpor + '"})');
+      
+   this.setOrder(oexporder);
 }
 
@@ -181,27 +217,27 @@
 
 //flags data
-MAQueryConfig.prototype.setFlags = function(flaglist){
+MAQueryConfig.prototype.setTag = function(flaglist){
   if(flaglist.flags.length <= 0){
-    this.flag = null;
-    return;
-  }
-
-  this.flag = '"flag":[';
+    this.tag = null;
+    return;
+  }
+
+  this.tag = '"flag":[';
   var flag_data = flaglist.flags.split(',');
   if(flag_data.length > 0){
     for(var k=0; k<flag_data.length; k++){
-      this.flag += '{"@value":"'+flag_data[k]+'"},'
+      this.tag += '{"@value":"'+flag_data[k]+'"},'
     }
-    this.flag = this.flag.substr(0,this.flag.length-1);
+    this.tag = this.tag.substr(0,this.tag.length-1);
   }
   else{
-    this.flag += '{"@value":"'+flaglist.flags+'"},';
-  }
-  this.flag += '],';
+    this.tag += '{"@value":"'+flaglist.flags+'"},';
+  }
+  this.tag += '],';
 }
 
 //Folder data
 MAQueryConfig.prototype.setFolder = function(folderslist){
-  if(folderslist.folderlength <= 0){
+  if(folderslist.length <= 0){
     this.folder = null;
     return;
@@ -209,13 +245,18 @@
 
   this.folder = '"folder":[';
-  var folder_data = folderslist.folder.split(',');
-  if(folder_data.length > 0){
-    for(var k=0; k<folder_data.length; k++){
-      this.folder += '{"@id":"'+folder_data[k]+'"},'
+  if (folderslist.indexOf(',') != -1){
+    var folder_data = folderslist.folder.split(',');
+    if(folder_data.length > 0){
+        for(var k=0; k<folder_data.length; k++){
+            this.folder += '{"@id":"'+folder_data[k]+'"},'
+        }
+        this.folder = this.folder.substr(0,this.folder.length-1);
     }
-    this.folder = this.folder.substr(0,this.folder.length-1);
+    else{
+        this.folder += '{"@id":"'+folderslist+'"}';
+    }
   }
   else{
-    this.folder += '{"@id":"'+folderslist.folder+'"},';
+      this.folder += '{"@id":"' + folderslist + '"}';
   }
   this.folder += '],';
@@ -224,5 +265,5 @@
 //Order criteria
 MAQueryConfig.prototype.setOrder = function(order){
-  if(order.length <= 0){
+  if(typeof(order) != 'object'){
     this.order = null;
     return;
@@ -259,18 +300,68 @@
 }
 
+MAQueryConfig.prototype.getFrom = function(){
+    (this.from != null) ? retdata = this.from : retdata = "";
+    return(retdata);
+}
+
+MAQueryConfig.prototype.getTo = function(){
+    (this.to != null) ? retdata = this.to : retdata = "";
+    return(retdata);    
+}
+
+MAQueryConfig.prototype.getCc = function(){
+    (this.cc != null) ? retdata = this.cc : retdata = "";
+    return(retdata);    
+}
+
+MAQueryConfig.prototype.getSubject = function(){
+    (this.subject != null) ? retdata = this.subject : retdata = "";
+    return(retdata);    
+}
+
+MAQueryConfig.prototype.getBody = function(){
+    (this.body != null) ? retdata = this.body : retdata = "";
+    return(retdata);    
+}
+
+MAQueryConfig.prototype.getDate = function(){
+    (this.date != null) ? retdata = this.date : retdata = "";
+    return(retdata);    
+}
+
+MAQueryConfig.prototype.getTag = function(){
+    (this.tag != null) ? retdata = this.tag : retdata = "";
+    return(retdata);    
+}
+
+MAQueryConfig.prototype.getFolder = function(){
+    (this.folder != null) ? retdata = this.folder : retdata = "";
+    return(retdata);    
+}
+
+MAQueryConfig.prototype.getOrder = function(){
+    (this.order != null) ? retdata = this.order : retdata = "";
+    return(retdata);    
+}
+
 //Query criteria (core api)
 MAQueryConfig.prototype.query = function(offsetlow,offsethight, criterialist){
-  this.setBounds(offsetlow, offsethight);
-  this.setCriteriaList(criterialist);
+  if ((offsetlow) && (offsethight))
+    this.setBounds(offsetlow, offsethight);
+
+  if (criterialist)
+    if(criterialist.length > 0)
+        this.setCriteriaList(criterialist);
+
   var querystring = '{"query":{' + this.lowerIndex + this.upperIndex;
-  querystring += this.from;
-  querystring += this.to;
-  querystring += this.cc;
-  querystring += this.subject;
-  querystring += this.body;
-  querystring += this.date;
-  querystring += this.flag;
-  querystring += this.folder;
-  querystring += this.order;
+  querystring += this.getFrom();
+  querystring += this.getTo();
+  querystring += this.getCc();
+  querystring += this.getSubject();
+  querystring += this.getBody();
+  querystring += this.getDate();
+  querystring += this.getTag();
+  querystring += this.getFolder();
+  querystring += this.getOrder();
   querystring += '}}';
   return(querystring);
Index: sandbox/expressoMail1_2/MailArchiver/2.2/expressoMail1_2/js/messages_controller.js
===================================================================
--- sandbox/expressoMail1_2/MailArchiver/2.2/expressoMail1_2/js/messages_controller.js	(revision 4875)
+++ sandbox/expressoMail1_2/MailArchiver/2.2/expressoMail1_2/js/messages_controller.js	(revision 4899)
@@ -18,4 +18,5 @@
                         //window.alert('dumping data:\n\n' + 'folder = ' + baseFolder + '\nmsg_range_begin = ' + msg_range_begin + '\nemails_per_page = ' + emails_per_page + '\nsort_box_type = ' + sort_box_type + '\nsearch_box_type = ' + search_box_type + '\nsort_box_reverse = ' + sort_box_reverse + '\npreview_msg_subject = ' + preview_msg_subject + '\npreview_msg_tip = ' + preview_msg_tip + '\ntree = ' + tree_name);
                         if(tree_name == 'tree_folders'){ //only the 'tree_folders' must show messages. 'folders_tree' are just for managment operation
+                            //alert('com tree_folders e sort_box_type = ' + sort_box_type + '\nsort_box_reverse = ' + sort_box_reverse + '\ncall_back = ' + call_back);
                             /*var dfs = new Array();
                             dfs["folder"] = baseFolder;
@@ -30,7 +31,14 @@
                             */
                             var dfs = new Array(baseFolder,msg_range_begin,emails_per_page,sort_box_type,sort_box_reverse,preview_msg_subject,preview_msg_tip,call_back,tree_name);
-                            expresso_mail_archive.queryconfig.setDefaults(dfs);
+                            expresso_mail_archive.queryconfig.folder = null;
                             expresso_mail_archive.listMessages();
                             
+                        }
+                        else{
+                            if (!tree_name){
+                                var exp_dfs = new Array(baseFolder,msg_range_begin,emails_per_page,sort_box_type,sort_box_reverse,preview_msg_subject,preview_msg_tip);
+                                expresso_mail_archive.queryconfig.setExpressoDefaults(exp_dfs);
+                                expresso_mail_archive.listMessages();
+                            }
                         }
 		}else {
