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 4871)
+++ sandbox/expressoMail1_2/MailArchiver/2.2/expressoMail1_2/js/mail_archiver.js	(revision 4878)
@@ -151,4 +151,5 @@
     this.drawdata = null;
     this.onprocess = false;
+    this.queryconfig = new MAQueryConfig();
     this.specialfolders = {
                             "inbox":"local_inbox", 
@@ -158,5 +159,4 @@
                             "trash":"local_trash"
                           };
-    //this.queryconfig = new MAQueryConfig();
 }
 
@@ -724,4 +724,5 @@
 //OLD local_messages.prototype.get_local_range_msgs = function(folder,msg_range_begin,emails_per_page,sort,sort_reverse,search,preview_msg_subject,preview_msg_tip) {
 //ONLINE messages_proxy.prototype.messages_list = function(folder,msg_range_begin,emails_per_page,sort_box_type,search_box_type,sort_box_reverse,preview_msg_subject,preview_msg_tip,call_back,tree_name) {
+//sys call = proxy_mensagens.messages_list(current_folder,1,preferences.max_email_per_page,sort,search,sort_box_reverse,preferences.preview_msg_subject,preferences.preview_msg_tip,handler_draw_box);
 MailArchiver.prototype.listMessages = function(){
     try{
@@ -783,15 +784,25 @@
 MailArchiver.prototype.toExpressoAddress = function(data){
     if((typeof(data) != 'undefined') && (data.length > 0)){
-    /*var dataFormat = expresso_mail_archive.toExpressoFormatNameMail(data);
-    var dataName = dataFormat[0];
-    var dataEmail = dataFormat[1];
-    */
-    //window.alert('em toExpressoFrom com data = \n' + data + '[' + typeof(data) + ']('+data.length+')');
-    var Fromdata = eval("(" + data + ")");
-    var dataName = Fromdata.mailbox["@name"];
-    var dataEmail = Fromdata.mailbox["@localPart"] + '@' + Fromdata.mailbox["@domain"];
-    //window.alert('name = ' + Fromdata.mailbox.name.$ + '\nlocal part = ' + Fromdata.mailbox.localPart.$ + '\ndomain = ' + Fromdata.mailbox.domain.$);
-       
-    var tplFrom = 'a:2:{'
+        /*var dataFormat = expresso_mail_archive.toExpressoFormatNameMail(data);
+        var dataName = dataFormat[0];
+        var dataEmail = dataFormat[1];
+        */
+        //window.alert('em toExpressoFrom com data = \n' + data + '[' + typeof(data) + ']('+data.length+')');
+        var Fromdata = eval("(" + data + ")");
+        //window.alert('temos ' + Fromdata.mailbox.length + ' destinatarios/remetentes a lidar...');
+        //window.alert('name = ' + Fromdata.mailbox["@name"] + '\nlocal part = ' + Fromdata.mailbox["@localPart"] + '\ndomain = ' + Fromdata.mailbox["@domain"]);
+     
+        //one address
+        if(typeof(Fromdata.mailbox.length) == 'undefined'){
+            var dataName = Fromdata.mailbox["@name"];
+            var dataEmail = Fromdata.mailbox["@localPart"] + '@' + Fromdata.mailbox["@domain"];
+        }
+        //address list: to header(msgs list), only first metters
+        else{
+            var dataName = Fromdata.mailbox[0]["@name"];
+            var dataEmail = Fromdata.mailbox[0]["@localPart"] + '@' + Fromdata.mailbox[0]["@domain"];
+        }
+
+        var tplFrom = 'a:3:{'
 +           's:4:"name";'
 +           's:'+dataName.length+':"'+dataName+'";'
@@ -820,61 +831,105 @@
 }
 
-MailArchiver.prototype.toExpressoDate = function(data){
-    var ndate = new Date(data);   
-    var odate = zeroFill(ndate.getDay()) + '/' + zeroFill(ndate.getMonth()) + '/' + zeroFill(ndate.getFullYear());
-    return(odate);
-}
-
-MailArchiver.prototype.toExpressoHour = function(data){
-    var ndate = new Date(data);   
-    var ohour = zeroFill(ndate.getHours()) + ':' + zeroFill(ndate.getMinutes()) + ':' + zeroFill(ndate.getSeconds());
-    return(ohour);    
-}
-
-MailArchiver.prototype.toExpressoCC = function(data){
-    var tplCC =  "s:"+data.getCC().length+":\""+data.getCC()+"\";";
-    return(tplCC);
-}
-
-MailArchiver.prototype.toExpressoTo = function(data){
-    var tplTo =  "s:"+data.getTo().length+":\""+data.getTo()+"\";";
-    return(tplTo);
-}
-
-/**
- *+           's:'+expresso_mail_archive.toExpressoDate(data.getDate()).length+':"'+expresso_mail_archive.toExpressoDate(data.getDate())+'";'
-+           's:7:"msg_day";'
-+           's:'+expresso_mail_archive.toExpressoDate(data.getDate()).length+':"'+expresso_mail_archive.toExpressoDate(data.getDate())+'";'
-+           's:8:"msg_hour";'
-+           's:'+expresso_mail_archive.toExpressoHour(data.getDate()).length+':"'+expresso_mail_archive.toExpressoHour(data.getDate())+'";'
-+           's:8:"fulldate";'
-+           's:'+(expresso_mail_archive.toExpressoDate(data.getDate()).length+expresso_mail_archive.toExpressoHour(data.getDate()).length+1)+':"'+expresso_mail_archive.toExpressoDate(data.getDate())+' '+expresso_mail_archive.toExpressoHour(data.getDate())+'";'
-+           's:9:"smalldate";'
-+           's:'+expresso_mail_archive.toExpressoDate(data.getDate()).length+':"'+expresso_mail_archive.toExpressoDate(data.getDate())+'";'
-+           's:8:"aux_date";'
-+           's:1:"N";'
- */
-
+MailArchiver.prototype.toExpressoAttachmentsHeader = function(data){
+    if((typeof(data) != 'undefined') && (data.length > 0)){
+        var Attdata = eval("(" + data + ")");
+        if(typeof(Attdata.attachment) != 'undefined'){                    
+            var tplAttatch = 'a:2:{'
++               's:5:"names";';
+            //More than 1 attachment - because length will be 'undefined' if just one exists
+            if(Attdata.attachment.length > 0){
+                var strnamesatt = "";
+                for(var x=0; x<Attdata.attachment.length; x++){
+                  var attId = Attdata.attachment[x]["@id"];
+                  var attName = Attdata.attachment[x]["@name"];
+                  var attSize = Attdata.attachment[x]["@size"];
+                  var attMediaType = Attdata.attachment[x]["@mediaType"];
+                  var attSubType = Attdata.attachment[x]["@subType"];
+                  var attEncoding = Attdata.attachment[x]["@encoding"];
+                  
+                  strnamesatt += attName + ', ';
+                }
+                strnamesatt = strnamesatt.substr(0, strnamesatt.length-2);
+                var intnumberatt = Attdata.attachment.length;
+            }
+            //Just one attachment
+            else{
+                var attId = Attdata.attachment["@id"];
+                var attName = Attdata.attachment["@name"];
+                var attSize = Attdata.attachment["@size"];
+                var attMediaType = Attdata.attachment["@mediaType"];
+                var attSubType = Attdata.attachment["@subType"];
+                var attEncoding = Attdata.attachment["@encoding"];
+                strnamesatt = attName;
+                var intnumberatt = 1;
+            }
+            
+            tplAttatch += 's:'+strnamesatt.length+':"'+strnamesatt+'";'
++               's:18:"number_attachments";i:' +intnumberatt+';'
++           '}';
+        }
+        else {
+            tplAttatch = 'a:2:{s:5:"names";b:0;s:18:"number_attachments";i:0;}';    
+        }
+    }
+    //No attatch data
+    else {
+        tplAttatch = 'a:2:{s:5:"names";b:0;s:18:"number_attachments";i:0;}';
+    }
+    return(tplAttatch);
+}
+
+MailArchiver.prototype.toExpressoFlags = function(data){
+    if((data.length > 0) && (typeof(data) != 'undefined')){
+        var Tagdata = eval("(" + data + ")");
+        //More than 1 attachment - because length will be 'undefined' if just one exists
+        if(Tagdata.tag.length >= 0){
+            var strnamestag = "";
+            for(var x=0; x<Tagdata.tag.length; x++){
+                var tagvalue = Tagdata.tag[x]["@value"];
+                if(tagvalue.toLowerCase().indexOf('recent')!= -1)
+                    strnamestag += 's:6:"Recent";s:1:"N";';
+                if(tagvalue.toLowerCase().indexOf('unseen')!= -1)
+                    strnamestag += 's:6:"Unseen";s:1:"U";';
+                if(tagvalue.toLowerCase().indexOf('answered')!= -1)
+                    strnamestag += 's:8:"Answered";s:1:"A";';
+                if(tagvalue.toLowerCase().indexOf('forwarded')!= -1)
+                    strnamestag += 's:9:"Forwarded";s:1:"F"';
+                if(tagvalue.toLowerCase().indexOf('draft')!= -1)
+                    strnamestag += 's:5:"Draft";s:1:"X";';
+                if(tagvalue.toLowerCase().indexOf('importance')!= -1)
+                    strnamestag += 's:10:"Importance";s:6:"High";';
+                if(tagvalue.toLowerCase().indexOf('flagged')!= -1)
+                    strnamestag += 's:7:"Flagged";s:1:"F";';                       
+            } 
+            var tplTags = strnamestag;
+        }
+        else{
+            tplTags = 's:6:"Recent";s:1:" ";s:6:"Unseen";s:1:" ";s:8:"Answered";s:1:" ";s:9:"Forwarded";s:1:" ";s:5:"Draft";s:1:" ";s:10:"Importance";s:6:"Normal";s:7:"Flagged";b:0;';    
+        }
+    }
+    else{
+        tplTags = 's:6:"Recent";s:1:" ";s:6:"Unseen";s:1:" ";s:8:"Answered";s:1:" ";s:9:"Forwarded";s:1:" ";s:5:"Draft";s:1:" ";s:10:"Importance";s:6:"Normal";s:7:"Flagged";b:0;';
+    }
+    return(tplTags);
+}
 
 MailArchiver.prototype.toExpressoHeader = function(data){   
-    var tplHeader = 'a:16:{'
+    var tplHeader = 'a:19:{'
 +           's:11:"ContentType";'
-+           's:6:"normal";'
-+           's:10:"Importance";'
-+           's:6:"Normal";'
-+           's:6:"Recent";'
-+           's:1:" ";'
-+           's:6:"Unseen";'
-+           's:1:"N";'
-+           's:8:"Answered";'
-+           's:1:" ";'
-+           's:5:"Draft";'
-+           's:1:" ";'
-+           's:7:"Deleted";'
-+           's:1:" ";'
-+           's:7:"Flagged";'
-+           'b:0;'
++           's:' + data.getContentType().length + ':"' + data.getContentType() + '";'
++           expresso_mail_archive.toExpressoFlags(data.getTags())
 +           's:10:"msg_number";'
 +           's:'+data.getId().length+':"'+data.getId()+'";'
++           's:5:"udate";'
++           'i:' + parseInt(data.getDate()/1000) + ';'
++           's:11:"offsetToGMT";'
++           'i:-10800;'
++           's:9:"timestamp";'
++           'i:' + parseInt(data.getDate()/1000) + ';'
++           's:9:"smalldate";'
++           's:10:"01/04/2011";'
++           's:8:"aux_date";'
++           's:1:" ";'
 +           's:4:"from";'
 +           expresso_mail_archive.toExpressoAddress(data.getFrom())
@@ -885,25 +940,8 @@
 +           's:4:"Size";'
 +           'i:'+data.getSize()+';'
-+           's:5:"udate";'
-+           's:10:"01/04/2011";'
-+           's:7:"msg_day";'
-+           's:10:"01/04/2011";'
-+           's:8:"msg_hour";'
-+           's:8:"01:01:59";'
-+           's:8:"fulldate";'
-+           's:19:"01/04/2011 01:01:59";'
-+           's:9:"smalldate";'
-+           's:10:"01/04/2011";'
 +           's:10:"attachment";'
-+           'a:2:{'
-+                   's:5:"names";'
-+                   'b:0;'
-+                   's:18:"number_attachments";'
-+                  'i:0;'
-+               '}'
-+           's:8:"aux_date";'
-+           's:10:"01/04/2011";'
++           expresso_mail_archive.toExpressoAttachmentsHeader(data.getAttachments())
 +           '}';
-    //window.alert('Expresso Header draw data = ' + tplHeader);
+    //window.alert('Serialized data\n\n' + tplHeader);
     return(tplHeader);
 }
@@ -915,5 +953,5 @@
 
 MailArchiver.prototype.Query = function(offlow, offup, qdata){
-    var querystring = this.queryconfig.query(offlow, offup, qdata);
+    var querystring = this.queryconfig.query(offlow, preferences.max_email_per_page, qdata);
     this.listMessages();
 }
