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 4942)
+++ sandbox/expressoMail1_2/MailArchiver/2.2/expressoMail1_2/js/mail_archiver.js	(revision 4955)
@@ -161,5 +161,9 @@
                             "outbox":"local_outbox", 
                             "trash":"local_trash"
-                          };
+                          };                          
+    this.unarchivecounter = 0;
+    this.unarchievefolder = null;
+    this.unarchievenewfolder = null;
+                          
 }
 
@@ -401,9 +405,99 @@
 
 /**
+ *Unarchieve Message
+ *
+ *@author Cassiano Dal Pizzol [cassiano.dalpizzol@serpro.gov.br]
+ *
+ *@param folder Original Folder of the message
+ *@param new_folder The new folder of the message
+ *@param msgs_number id of the messages
+ */
+MailArchiver.prototype.unarchieve = function (folder, new_folder, msgs_number){
+    try{ 
+        expresso_mail_archive.message_list = new Array();
+        expresso_mail_archive.CreateMessageList(msgs_number);
+        if((expresso_mail_archive.message_list.length > 0) && (expresso_mail_archive.message_list[0] != '')) {
+            expresso_mail_archive.unarchivecounter = 0;
+            expresso_mail_archive.unarchievefolder = folder;
+            expresso_mail_archive.unarchievenewfolder = new_folder;
+            expresso_mail_archive.unarchieveHandler();
+        }
+        else{
+            write_msg(get_lang('No selected message.'));
+        }
+    }
+    catch (e){
+        write_msg(get_lang('Unarchive error: ' + e));
+    }
+}
+
+/**
+ *
+ *Unarchieve Message Handler
+ *
+ *@author Cassiano Dal Pizzol [cassiano.dalpizzol@serpro.gov.br]
+ *
+ **/
+MailArchiver.prototype.unarchieveHandler = function(){
+    var email = 'http://127.0.0.1:4333/mail/' + expresso_mail_archive.unarchievefolder.substr(6).charAt(0).toUpperCase() + expresso_mail_archive.unarchievefolder.substr(7) + '/'+ expresso_mail_archive.message_list[expresso_mail_archive.unarchivecounter] + '.eml';
+    expresso_mail_archive.messagesourcehandler.onreadystatechange = function(){
+        if (expresso_mail_archive.messagesourcehandler.readyState==4 && expresso_mail_archive.messagesourcehandler.status==200){
+            for (var w=0; w < expresso_mail_archive.messageslisted.length; w++){
+                if(expresso_mail_archive.messageslisted[w]["msg_number"] == expresso_mail_archive.message_list[expresso_mail_archive.unarchivecounter]){
+                    var timestamp = expresso_mail_archive.messageslisted[w]["timestamp"];
+                    var flags  = "#@#@#@" + (expresso_mail_archive.messageslisted[w]["Answered"]!=undefined)?'A':'';
+                        flags +=            (expresso_mail_archive.messageslisted[w]["Draft"]   !=undefined)?'D':'';
+                        flags +=            (expresso_mail_archive.messageslisted[w]["Flagged"] !=undefined)?'F':'';
+                        flags +=            (expresso_mail_archive.messageslisted[w]["Unseen"]  !=undefined)?'U':'';
+                    break;
+                }
+            }
+            var source = "#@#@#@" + escape(expresso_mail_archive.messagesourcehandler.responseText);
+            //var flags+="#@#@#@"+ mail["Answered"] +":"+mail["Draft"]+":"+mail["Flagged"]+":"+mail["Unseen"];
+            var params = 
+            "&folder="      + expresso_mail_archive.unarchievenewfolder + 
+            "&source="      + source + 
+            "&timestamp="   + timestamp + 
+            "&flags="       + flags;
+            var handler_unarchive = function(){
+                expresso_mail_archive.unarchieveController();
+            }
+            write_msg(get_lang('Unarchieving ' + (expresso_mail_archive.unarchivecounter + 1) + ' of ' +  expresso_mail_archive.message_list.length));
+            cExecute ("$this.imap_functions.unarchive_mail&", handler_unarchive, params);
+        }
+    }
+    write_msg(get_lang('Opening message ' + (expresso_mail_archive.unarchivecounter + 1) + ' for Unarchieve'));
+    expresso_mail_archive.messagesourcehandler.open("GET", email, true);
+    expresso_mail_archive.messagesourcehandler.send();
+}
+
+/**
+ *
+ *Unarchieve Message Controller
+ *
+ *@author Cassiano Dal Pizzol [cassiano.dalpizzol@serpro.gov.br]
+ *
+ **/
+MailArchiver.prototype.unarchieveController = function(){
+    expresso_mail_archive.unarchivecounter++;
+    if (expresso_mail_archive.unarchivecounter < expresso_mail_archive.message_list.length){
+        expresso_mail_archive.unarchieveHandler();
+    }
+    else{
+        if (expresso_mail_archive.message_list.length==1){
+            write_msg(get_lang('Message successfully unarchived'));
+        }
+        else{
+            write_msg(get_lang('Messages successfully unarchived'));
+        }
+    }
+}
+
+/**
  *Archieve Delete Message
  *
  *@author Cassiano Dal Pizzol [cassiano.dalpizzol@serpro.gov.br]
  *
- *@param msg_number Unique identification of the message
+ *@param msgs_number Unique identification of the message
  */
 MailArchiver.prototype.deleteMessages = function(msgs_number){
@@ -416,7 +510,10 @@
                                            expresso_mail_archive.message_list);
         }
+        else{
+            write_msg(get_lang('No selected message.'));
+        }
     }
     catch (e){
-        return (e);
+        window.alert('Delete error: ' + e);
     }
 }
@@ -474,10 +571,10 @@
                                        );
         }
-        else {
-            throw "Error moving the messages!";
+        else{
+            write_msg(get_lang('No selected message.'));
         }
     }
     catch (e){
-        return (e);
+        window.alert('Move error: ' + e);
     }
 }
@@ -509,7 +606,7 @@
 MailArchiver.prototype.moveMessagesOperationFailure = function(error_message){
     if(expresso_mail_archive.message_list.length > 1){
-        write_msg(get_lang("Error deleting messages.") + ' ' + error_message.getReturn());
+        write_msg(get_lang("Error moving messages.") + ' ' + error_message.getReturn());
     }else{
-        write_msg(get_lang("Error deleting message.") + ' ' + error_message.getReturn());
+        write_msg(get_lang("Error moving message.") + ' ' + error_message.getReturn());
     } 
 }
@@ -784,6 +881,6 @@
     expresso_mail_archive.drawMessagesList();
     
-    window.alert('get ajax...');
-    expresso_mail_archive.getMessageSource();
+    //window.alert('get ajax...');
+   // expresso_mail_archive.getMessageSource();
 }
 
@@ -877,18 +974,18 @@
 //Under develpment this one
 MailArchiver.prototype.getMessageSource = function(){
-    expresso_mail_archive.messagesourcehandler.onreadystatechange = AlerteO();
+    //expresso_mail_archive.messagesourcehandler.onreadystatechange = AlerteO();
     //expresso_mail_archive.messagesourcehandler.setRequestHeader("SOAPAction", "");
     //expresso_mail_archive.messagesourcehandler.setRequestHeader("Access-Control-Allow-Origin", "*");
     //expresso_mail_archive.messagesourcehandler.setRequestHeader("Access-Control-Allow-Credentials", "true");
-    window.alert('vai chamar via ajax o texto');
-    expresso_mail_archive.messagesourcehandler.open("GET", "http://10.200.242.186:4333/mail/Sent/teste.txt", true);
+    //window.alert('vai chamar via ajax o texto');
+   // expresso_mail_archive.messagesourcehandler.open("GET", "http://10.200.242.186:4333/mail/Sent/teste.txt", true);
     //expresso_mail_archive.messagesourcehandler.setRequestHeader("MessageType", "CALL");
     //expresso_mail_archive.messagesourcehandler.setRequestHeader("Access-Control-Allow-Origin", "*");
     //expresso_mail_archive.messagesourcehandler.setRequestHeader("Access-Control-Allow-Credentials", "true");    
-    expresso_mail_archive.messagesourcehandler.send();
+    //expresso_mail_archive.messagesourcehandler.send();
 }
 
 function AlerteO(){
-    window.alert('Ajax lido:\n\nState = ' + expresso_mail_archive.messagesourcehandler.readyState + '\nStatus = ' + expresso_mail_archive.messagesourcehandler.status);
+    //window.alert('Ajax lido:\n\nState = ' + expresso_mail_archive.messagesourcehandler.readyState + '\nStatus = ' + expresso_mail_archive.messagesourcehandler.status);
 }
 
