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 4658)
+++ sandbox/expressoMail1_2/MailArchiver/2.2/expressoMail1_2/js/mail_archiver.js	(revision 4715)
@@ -60,4 +60,78 @@
 }
 
+function zeroFill(d){
+    if(parseInt(d) < 10)
+        return('0' + d);
+    else
+        return(d);
+}
+
+/**
+ * Concatenates the values of a variable into an easily readable string
+ * by Matt Hackett [scriptnode.com]
+ * @param {Object} x The variable to debug
+ * @param {Number} max The maximum number of recursions allowed (keep low, around 5 for HTML elements to prevent errors) [default: 10]
+ * @param {String} sep The separator to use between [default: a single space ' ']
+ * @param {Number} l The current level deep (amount of recursion). Do not use this parameter: it's for the function's own use
+ */
+function print_r(x, max, sep, l) {
+
+	l = l || 0;
+	max = max || 100;
+	sep = sep || ' ';
+
+	if (l > max) {
+		return "[WARNING: Too much recursion]\n";
+	}
+
+	var
+		i,
+		r = '',
+		t = typeof x,
+		tab = '';
+
+	if (x === null) {
+		r += "(null)\n";
+	} else if (t == 'object') {
+
+		l++;
+
+		for (i = 0; i < l; i++) {
+			tab += sep;
+		}
+
+		if (x && x.length) {
+			t = 'array';
+		}
+
+		r += '(' + t + ") :\n";
+
+		for (i in x) {
+			try {
+				r += tab + '[' + i + '] : ' + print_r(x[i], max, sep, (l + 1));
+			} catch(e) {
+				return "[ERROR: " + e + "]\n";
+			}
+		}
+
+	} else {
+
+		if (t == 'string') {
+			if (x == '') {
+				x = '(empty)';
+			}
+		}
+
+		r += '(' + t + ') ' + x + "\n";
+
+	}
+
+	return r;
+
+};
+var_dump = print_r;
+
+
+
 //Main object structure: object property data definition
 function MailArchiver() { 
@@ -103,5 +177,4 @@
     else
         tem_tag = false;
-    
     try{
         if (obj.enabled){
@@ -148,4 +221,8 @@
                 expresso_mail_archive.interval = 5000;
                 expresso_mail_archive.timer = window.setInterval(expresso_mail_archive.getServicesStatus, expresso_mail_archive.interval);
+                var drawinginfo = {treeObject: tree_folders, treeName: 'tree_folders', folderName: 'local_root'};
+                expresso_mail_archive.currentfolder = 'local_root';
+                expresso_mail_archive.drawdata = drawinginfo;
+                expresso_mail_archive.getFoldersList();
            }
         }
@@ -198,9 +275,6 @@
  **/
 MailArchiver.prototype.Restart = function(obj){
-    window.alert('Trying reboot...');
-
     obj.SystemCheck();
     obj.ActivateStatusListener(obj);
-    //tree_folders.getNodeById('local_root')._refresh();
     auto_refresh();
 }
@@ -212,4 +286,13 @@
     this.SystemCheck();
 }
+
+MailArchiver.prototype.serializeToExpresso = function(data){
+    return(connector.serialize(data));
+}
+
+MailArchiver.prototype.unserializeFromExpresso = function(data){
+    return(connector.unserialize(data));
+}
+
 
 MailArchiver.prototype.CreateMessageList = function(msg_list){
@@ -233,5 +316,5 @@
 //Archive Operation
 MailArchiver.prototype.Archive = function(source_folder,destination_folder,msgs_id){
-    window.alert('tentando arquivar a mensagem [' + msgs_id + '], do folder ['+source_folder+'] para a pasta destino ['+destination_folder+']');
+    //window.alert('tentando arquivar a mensagem [' + msgs_id + '], do folder ['+source_folder+'] para a pasta destino ['+destination_folder+']');
     try{
         document.getElementById('main_title').innerHTML = get_lang("Starting to archive messages");
@@ -245,5 +328,5 @@
             //Sets the folders properties: destination and origin
             expresso_mail_archive.folder_origin = source_folder;
-            window.alert('substr(0,5) = ' + destination_folder.substr(0,5));
+            //window.alert('substr(0,5) = ' + destination_folder.substr(0,5));
             if(destination_folder.substr(0,5) == 'local')
                 expresso_mail_archive.folder_destination = destination_folder.substr(6,destination_folder.length);
@@ -251,5 +334,5 @@
                 expresso_mail_archive.folder_destination = destination_folder;
             
-            window.alert('destination_folder = ' + expresso_mail_archive.folder_destination);
+            //window.alert('destination_folder = ' + expresso_mail_archive.folder_destination);
 
             var arch_handler = function(data){
@@ -302,5 +385,5 @@
     }
     catch (e){
-        window.alert('Ops...List folders fails at:\n' + e.description);
+        window.alert('AQUI MESMO\nOps...List folders fails at:\n' + e.description);
     } 
 }
@@ -346,4 +429,5 @@
         //If something UI related have been flagged, handle it
         if (expresso_mail_archive.drawdata){
+            //window.alert('com drawdata');
             expresso_mail_archive.drawFolderTree();
         }
@@ -358,4 +442,5 @@
 //drawFolderTree operation, if requested to
 MailArchiver.prototype.drawFolderTree = function(){
+    //window.alert('na api de foldertree');
     var localBaseName  = 'local_';
     var objectTree = expresso_mail_archive.drawdata.treeObject;
@@ -378,8 +463,14 @@
             
             //Adjust the id node names
-            if(expresso_mail_archive.currentfolder.substr(0,5) != 'local'){
-                evalobjectTree.add(n_demo, localBaseName + expresso_mail_archive.currentfolder);
+            if(expresso_mail_archive.currentfolder){
+                if(expresso_mail_archive.currentfolder.substr(0,5) != 'local'){
+                    evalobjectTree.add(n_demo, localBaseName + expresso_mail_archive.currentfolder);
+                }
+                else{
+                    evalobjectTree.add(n_demo,expresso_mail_archive.currentfolder);
+                }
             }
-            else{
+            else {
+                expresso_mail_archive.currentfolder = 'local_root';
                 evalobjectTree.add(n_demo,expresso_mail_archive.currentfolder);
             }
@@ -507,7 +598,12 @@
 
 //listMessages operation
-MailArchiver.prototype.listMessages = function(listQuery){
-    try{
-        ///ArchiveServices.listMessages()
+MailArchiver.prototype.listMessages = function(){
+    try{
+        var folderid = expresso_mail_archive.currentfolder;
+        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;
+        //window.alert('vai chamar o listMessages com testing_data = ' + testing_data);
+        ArchiveServices.listMessages(expresso_mail_archive.listMessagesOperationOK, expresso_mail_archive.listMessagesOperationFailure, sessid, testing_data);
     }
     catch (e){
@@ -518,12 +614,160 @@
 //listMessages callback OK
 MailArchiver.prototype.listMessagesOperationOK = function(returnService){
+    var msglist = new Array();
+    /*window.alert('Dados da mensagem:\n->From ' + returnService.getReturn()[0].getFrom()
+                                      +'\n->To ' + returnService.getReturn()[0].getTo()
+                                      +'\n->Subject ' + returnService.getReturn()[0].getSubject()
+                                      +'\n->Date ' + returnService.getReturn()[0].getDate()
+                                      +'\n->Date ' + returnService.getReturn()[0].getSize()
+                                      +'\n->ID ' + returnService.getReturn()[0].getId());
+    */
+    for(var i=0; i< returnService.getReturn().length; i++){
+        //window.alert('quer deserializar:\n\n' + print_r(returnService.getReturn()[i]));
+        var ExpSerialized = expresso_mail_archive.toExpressoHeader(returnService.getReturn()[i]);
+        //window.alert('expSerialized ' + i + '\n\n --\n\n' + print_r(ExpSerialized));
+        //var test = connector.unserialize(ExpSerialized);
+        //window.alert('unserialized = \n\n' + test);
+        msglist.push(connector.unserialize(ExpSerialized));//usando connector.unserialize sobre o header mapeado no layout abaixo
+    }
+    msglist["num_msgs"] = returnService.getReturn().length;
+    //window.alert('print_r\n\n' + print_r(msglist));
+    expresso_mail_archive.drawdata = {messagesList:msglist};
+    expresso_mail_archive.drawMessagesList();
+}
+
+//listMessages callback Fail
+MailArchiver.prototype.listMessagesOperationFailure = function(ServiceFault){
+    window.alert('listmessages FALHOU!\n' + ServiceFault.getReturn());
+}
+
+MailArchiver.prototype.drawMessagesList = function(){
+    var data_to_draw = expresso_mail_archive.drawdata.messagesList;  
+    //window.alert('data to draw =  ' + data_to_draw.length + '\ndata_to_draw[0].from.full = ' + print_r(data_to_draw));
     
-}
-
-//listMessages callback Fail
-MailArchiver.prototype.listMessagesOperationFailure = function(serviceFault){
+    alternate_border(0);
+    Element("border_id_0").innerHTML = "&nbsp;" + lang_folder(expresso_mail_archive.currentfolder) + '&nbsp;<font face="Verdana" size="1" color="#505050">[<span id="new_m">&nbsp;</span> / <span id="tot_m"></span>]</font>';
+    draw_box(data_to_draw, expresso_mail_archive.currentfolder, true);
+    draw_paging(expresso_mail_archive.drawdata.messagesList.length);
+    Element("tot_m").innerHTML = expresso_mail_archive.drawdata.messagesList.length;
+    //update_menu();
     
 }
 
+// -----------------------------------SERIALIZED DATA TEMPLATES ----------------
+MailArchiver.prototype.toExpressoAddress = function(data){
+    /*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:{'
++           's:4:"name";'
++           's:'+dataName.length+':"'+dataName+'";'
++           's:5:"email";'
++           's:'+dataEmail.length+':"'+dataEmail+'";'
++           's:4:"full";'
++           's:'+(dataName.length + dataEmail.length + 3)+':"'+dataName+'" <'+dataEmail+'>;'
++       '}';
+    //window.alert('retorno do email: ' + tplFrom);
+    return(tplFrom);
+}
+
+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.toExpressoHeader = function(data){   
+    var tplHeader = 'a:16:{'
++           '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:10:"msg_number";'
++           's:'+data.getId().length+':"'+data.getId()+'";'
++           's:4:"from";'
++           expresso_mail_archive.toExpressoAddress(data.getFrom())
++           's:2:"to";'
++           expresso_mail_archive.toExpressoAddress(data.getTo())
++           's:7:"subject";'
++           's:'+data.getSubject().length+':"'+data.getSubject()+'";'
++           '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";'
++           '}';
+    //window.alert('Expresso Header draw data = ' + tplHeader);
+    return(tplHeader);
+}
+
+MailArchiver.prototype.toExpressoMail = function(data){
+    
+}
 /*
  *The all pourpose JavaScript variable, used by all related functionalityes at
