Index: /trunk/expressoMail1_2/inc/class.imap_functions.inc.php
===================================================================
--- /trunk/expressoMail1_2/inc/class.imap_functions.inc.php	(revision 8015)
+++ /trunk/expressoMail1_2/inc/class.imap_functions.inc.php	(revision 8063)
@@ -2700,18 +2700,19 @@
 	}
 
+	/*Método utilizado para retornar dados da mensagem local (desarquivada na pasta lixeira)
+	para poder ser anexada à mensagem.*/
     function get_info_msg_archiver($params){
-         $folder = "INBOX/Trash";
-         $mbox_stream = $this->open_mbox($folder);
-
-        foreach($params['idMsgs'] as $i => $id){
-            $name = imap_headerinfo($mbox_stream, imap_msgno($mbox_stream ,$id));
-            $return[] =  array(
-                'uid' => $id,
-                'folder' => "archiver",
-                'type' => "imapMSG",
-                'name' => base64_encode($name->subject.".eml")
-            );
-        }
-        
+        $folder = "INBOX".$this->imap_delimiter.$this->folders['trash'];
+        $mbox_stream = $this->open_mbox($folder);
+        $id = $params['idMsgs'];
+
+        $name = imap_headerinfo($mbox_stream, imap_msgno($mbox_stream, $id));
+        $return[] =  array(
+            'uid' => $id,
+            'folder' => "archiver",
+            'type' => "imapMSG",
+            'name' => base64_encode($name->subject.".eml")
+        );
+
         return json_encode($return);
     }
Index: /trunk/expressoMail1_2/js/mail_archiver.js
===================================================================
--- /trunk/expressoMail1_2/js/mail_archiver.js	(revision 7948)
+++ /trunk/expressoMail1_2/js/mail_archiver.js	(revision 8063)
@@ -575,6 +575,8 @@
 }
 
-MailArchiver.prototype.unarchieveToAttach = function (folder, new_folder, msgs_number){
-    try{
+MailArchiver.prototype.unarchieveToAttach = function (folder, new_folder, msgs_number, callback){
+    try{
+
+        if(typeof callback !== 'function') callback = function(){};
 
         if(typeof(expresso_mail_archive.idMsgsToAttach) == "undefined"){
@@ -601,5 +603,5 @@
                 (new_folder != null)?expresso_mail_archive.unarchievenewfolder = new_folder:expresso_mail_archive.unarchievenewfolder='INBOX';
                 
-                expresso_mail_archive.unarchieveToAttachHandler();
+                expresso_mail_archive.unarchieveToAttachHandler(callback);
                 
                 if(currentTab.toString().indexOf("_r") != -1){
@@ -621,7 +623,7 @@
 }
 
-MailArchiver.prototype.unarchieveToAttachHandler = function(){
-    try{
-        var email = mail_archive_protocol+'://'+mail_archive_host+':'+mail_archive_port+'/mail/' + expresso_mail_archive.session.id +'/'+ expresso_mail_archive.folder.path + '/'+ expresso_mail_archive.messageToAttach + '.eml';    
+MailArchiver.prototype.unarchieveToAttachHandler = function(uCallback){
+    try{
+         var email = mail_archive_protocol+'://'+mail_archive_host+':'+mail_archive_port+'/mail/' + expresso_mail_archive.session.id +'/'+ expresso_mail_archive.folder.path + '/'+ expresso_mail_archive.messageToAttach + '.eml';    
     
         //Creates a new object to unarchive messages. It's a CXF Add-on CORS component
@@ -710,4 +712,5 @@
                     expresso_mail_archive.idMsgsToAttach.push(data.idsMsg);
                     handler_unarchive(data);
+                    uCallback(data);
                 },
                 async: false,
Index: /trunk/expressoMail1_2/js/abas.js
===================================================================
--- /trunk/expressoMail1_2/js/abas.js	(revision 7972)
+++ /trunk/expressoMail1_2/js/abas.js	(revision 8063)
@@ -708,34 +708,4 @@
 function listAttachment(ID)
 {
-    var imap     = new Array();
-    var archiver = new Array();
-    var files    = new Array();
-
-    if(typeof msgAttachments[ID] == "undefined"){
-        return "";
-    }
-
-    $.each(msgAttachments[ID], function(i, each){
-       
-       if(typeof(each) == "undefined")  return true;
-       
-       if(typeof $.parseJSON(each) == "number"){
-            
-           files.push(parseInt(each));
-       } else {
-           if($.parseJSON(each).folder.indexOf("local_messages_") != -1){
-                archiver.push($.parseJSON(each));
-           } else {
-                imap.push(each);
-           }
-       }
-    });
-
-    context = {
-        "imap" : imap,
-        "archiver" : archiver,
-        "files" : files
-    };
-
-   return (typeof(msgAttachments[ID]) == 'undefined') ? '' : context;
-}
+    return (typeof(msgAttachments[ID]) == 'undefined') ? '' : JSON.stringify(msgAttachments[ID]);
+}
Index: /trunk/expressoMail1_2/js/main.js
===================================================================
--- /trunk/expressoMail1_2/js/main.js	(revision 8055)
+++ /trunk/expressoMail1_2/js/main.js	(revision 8063)
@@ -1,3 +1,2 @@
-// Tempo do auto refresh (em milisegundos)
 var time_refresh = 150000;
 
@@ -3533,142 +3532,26 @@
         mailData.input_from = $(content).find('select[name="input_from"]').val();
 
-
-    var filesAux = [];
-    // VERIFY IF EXISTS MESSAGE TO ATTACH
-    if(typeof mailData.attachments == "object"){
-
-
-         if(mailData.attachments.files.length){
-            var files = mailData.attachments.files;
-            var filesAux = new Array();
-
-            $.each(files, function(i, each){
-               filesAux.push(JSON.stringify(each));
-            });
-        }
-
-        // VERIFY IF EXISTS MESSAGE OF ARCHIVE
-
-        if(mailData.attachments.archiver.length){
-
-            // CREATE ONE VARIABLE TO STORE ALL THE MESSAGES INFORMATION
-            var archiver = new Array();
-
-            // UNARCHIEVE ALL THE MESSAGES TO IMAP TRASH
-           $.each(mailData.attachments.archiver, function(i, each){
-             expresso_mail_archive.unarchieveToAttach(each.folder,"INBOX/Trash",each.uid);
-           });
-
-            // FIX THE PROBLEM WITH ASYNC
-            // noReady is calling always that the variable is not complete with all the messages ids
-            notReady = function(){
-                setTimeout(function(){
-                if(mailData.attachments.archiver.length == expresso_mail_archive.idMsgsToAttach.length){
-                    // THIS FUNCTION IS FOR TO GET THE INFORMATION OF THE MESSAGE NEWLY UNARCHIVED
-                    readyToFetch();
-                    // THIS FUNCTION IS FOR TO SEND THE MESSAGE WITH ATTACHMENT
-                    readyToSend();
-                } else {
-                    // IF THE ARRAY DON'T HAVE ALL THE MESSAGES IDS, OKAY, NO PROBLEM... CALL THIS FUNCTION AGAIN!
-                    noReady();
-                }
-              },30);
-            };
-            notReady();
-
-             // THIS FUNCTION IS FOR TO GET THE INFORMATION OF THE MESSAGE NEWLY UNARCHIVED
-             readyToFetch = function(){
-                 $.ajax({
-                        url: "controller.php?action=$this.imap_functions.get_info_msg_archiver",
-                        data:  {"idMsgs":expresso_mail_archive.idMsgsToAttach},
-                        type: 'POST',
-                        async: false,
-                        success: function(data){
-                            data = connector.unserialize(data);
-                            archiver.push(data);
-                        },
-                  });
-
-                // HERE, THE MESSAGES IMAP ARE READY FOR TO SEND...
-                mailData.attachments = mailData.attachments.imap;
-
-                // BUT, I NEED TO PREPARE THE MESSAGE ARCHIVE FOR TO SEND.
-                archiver = $.parseJSON(archiver[0]);
-                if(archiver.length){
-                    $.each(archiver, function(i, each){
-                        mailData.attachments.push(JSON.stringify(archiver[i]));
-                    });
-                }
-
-                if(filesAux.length){
-                    $.each(filesAux, function(i, each){
-                        mailData.attachments.push(each);
-                    });
-                }
-
-                // GOOD, NOW THE ATTACHMENTS ARE READY TO SEND!
-                mailData.attachments = JSON.stringify(mailData.attachments);
-            };
-        } else if(mailData.attachments.imap.length) {
-            // IF THIS MESSAGE JUST HAVE IMAP MESSAGES
-            mailData.attachments = mailData.attachments.imap;
-            if(filesAux.length){
-                $.each(filesAux, function(i, each){
-                    mailData.attachments.push(each);
-                });
-            }
-            mailData.attachments = JSON.stringify(mailData.attachments);
-             setTimeout(function(){ readyToSend() }, 30);
-        } else if(mailData.attachments.files.length){
-            if(filesAux.length){
-                mailData.attachments = [];
-                $.each(filesAux, function(i, each){
-                    mailData.attachments.push(each);
-                });
-                mailData.attachments = JSON.stringify(mailData.attachments);
-                setTimeout(function(){ readyToSend() }, 30);
-            }
-        }
-
-    } else {
-        // IF THIS MESSAGE DON'T HAVE ATTACHMENT, CALL READYTOSEND.
-        setTimeout(function(){ readyToSend() }, 30);
-        mailData.attachments = [];
-    }
-
-    // THIS FUNCTION IS FOR TO SEND THE MESSAGE WITH ATTACHMENT OR NOT.
-    readyToSend = function(){
-    
-        if(stringEmail != ""){
-            $.ajax({
-                url: "controller.php?action=$this.imap_functions.send_mail",
-                data:  mailData,
-                type: 'POST',
-                async: false,
-                beforeSend: function(jqXHR, settings){
-                    write_msg( get_lang( 'Sending the message...' ) );
-                    $(content).find('button.send').button('option', 'disabled', true);
-                },
-                success: function(data){
-                    send_message_return(connector.unserialize(data),ID);
-                    // HERE, I NEED TO DELETE THE MESSAGES THAT WERE UNARCHIVE FROM ARCHIVE.
-                    delete_msgs("INBOX/Trash",expresso_mail_archive.idMsgsToAttach, false, false);
-                },
-                error: function(){
-                    write_msg(get_lang( 'Error trying to send the message. Retry in a few seconds...' ) );
-                    $(content).find('button.send').button('option', 'disabled', false);
-                    var interval = setInterval(function(){
-                            send_valided_message(ID,folder,folder_name);
-                            clearInterval(interval);
-                    },15000);
-                    return;
-                }
-            });
-        }else{
-            write_msg(get_lang("message without receiver"));
+    $.ajax({
+        url: "controller.php?action=$this.imap_functions.send_mail",
+        data:  mailData,
+        type: 'POST',
+        async: false,
+        beforeSend: function(jqXHR, settings){
+            write_msg( get_lang( 'Sending the message...' ) );
+            $(content).find('button.send').button('option', 'disabled', true);
+        },
+        success: function(data){
+            send_message_return(connector.unserialize(data),ID);
+        },
+        error: function(){
+            write_msg(get_lang( 'Error trying to send the message. Retry in a few seconds...' ) );
+            $(content).find('button.send').button('option', 'disabled', false);
+            var interval = setInterval(function(){
+                send_valided_message(ID,folder,folder_name);
+                clearInterval(interval);
+            },15000);
             return;
         }
-        delete(expresso_mail_archive.idMsgsToAttach);
-    };
+    });
 
 }
Index: /trunk/expressoMail1_2/js/draw_api.js
===================================================================
--- /trunk/expressoMail1_2/js/draw_api.js	(revision 8062)
+++ /trunk/expressoMail1_2/js/draw_api.js	(revision 8063)
@@ -4766,10 +4766,7 @@
     fileUploadMSG.find(' .attachments-list').show(); 
     var att = new Object(); 
-    att.folder = folder_name; 
-    att.uid = message_number; 
-    att.type = 'imapMSG'; 
-    att.name = Base64.encode(onceOpenedHeadersMessages[folder_name][message_number].subject + '.eml'); 
-    var idATT = JSON.stringify(att); 
-    addAttachment(ID, idATT); 
+
+   
+
     var attach = {}; 
     attach.fileName = onceOpenedHeadersMessages[folder_name][message_number].subject + '.eml'; 
@@ -4806,46 +4803,82 @@
     }); 
  
-    fileUploadMSG.find('.attachments-list').append(upload); 
- 
-    upload.find('.att-box-loading').remove(); 
- 
-    fileUploadMSG.find('.attachments-list .att-box:last').qtip( 
-    { 
-        content: DataLayer.render("../prototype/modules/mail/templates/attachment_add_itemlist_tooltip.ejs", { 
-            attach: attach 
-        }), 
-        position: { 
-            corner: { 
-                tooltip: 'bottomMiddle', 
-                target: 'topMiddle' 
+    var addtip = function(attach){
+        fileUploadMSG.find('.attachments-list .att-box:last').qtip( 
+        { 
+            content: DataLayer.render("../prototype/modules/mail/templates/attachment_add_itemlist_tooltip.ejs", { 
+                attach: attach 
+            }), 
+            position: { 
+                corner: { 
+                    tooltip: 'bottomMiddle', 
+                    target: 'topMiddle' 
+                }, 
+                adjust: { 
+                    resize: true, 
+                    scroll: true 
+                } 
             }, 
-            adjust: { 
-                resize: true, 
-                scroll: true 
+            show: { 
+                when: 'mouseover', 
+                // Don't specify a show event 
+                ready: false // Show the tooltip when ready 
+            }, 
+            hide: 'mouseout', 
+            // Don't specify a hide event 
+            style: { 
+                border: { 
+                    width: 1, 
+                    radius: 5 
+                }, 
+                width: { 
+                    min: 75, 
+                    max: 1000 
+                }, 
+                padding: 5, 
+                textAlign: 'center', 
+                tip: true, 
+                // Give it a speech bubble tip with automatic corner detection 
+                name: 'blue' // Style it according to the preset 'cream' style 
             } 
-        }, 
-        show: { 
-            when: 'mouseover', 
-            // Don't specify a show event 
-            ready: false // Show the tooltip when ready 
-        }, 
-        hide: 'mouseout', 
-        // Don't specify a hide event 
-        style: { 
-            border: { 
-                width: 1, 
-                radius: 5 
-            }, 
-            width: { 
-                min: 75, 
-                max: 1000 
-            }, 
-            padding: 5, 
-            textAlign: 'center', 
-            tip: true, 
-            // Give it a speech bubble tip with automatic corner detection 
-            name: 'blue' // Style it according to the preset 'cream' style 
-        } 
-    }); 
+        }); 
+    } 
+
+    if(folder_name.indexOf("local_messages_") != 0)
+    {
+        att.folder = folder_name; 
+        att.uid = message_number; 
+        att.type = 'imapMSG'; 
+        att.name = Base64.encode(onceOpenedHeadersMessages[folder_name][message_number].subject + '.eml'); 
+        var idATT = JSON.stringify(att); 
+        addAttachment(ID, idATT); 
+
+        fileUploadMSG.find('.attachments-list').append(upload);
+        addtip(attach);
+    }
+    else
+    {
+        var folder_trash = "INBOX"+cyrus_delimiter+special_folders["Trash"];
+        expresso_mail_archive.unarchieveToAttach(folder_name, folder_trash, message_number, function(data){
+            $.ajax({
+                url: "controller.php?action=$this.imap_functions.get_info_msg_archiver",
+                data:  {"idMsgs":data.idsMsg},
+                type: 'POST',
+                async: false,
+                success: function(data){
+                    data = JSON.parse(connector.unserialize(data));
+                    data = data[0];
+                    att.folder = folder_trash;
+                    att.uid = data.uid; 
+                    att.type = 'imapMSG'; 
+                    att.name = Base64.encode(onceOpenedHeadersMessages[folder_name][message_number].subject + '.eml'); 
+                    var idATT = JSON.stringify(att); 
+                    addAttachment(ID, idATT);
+                    fileUploadMSG.find('.attachments-list').append(upload);
+                    addtip(attach);
+                },
+            });
+        }); 
+    }
+    upload.find('.att-box-loading').remove();     
 }
 		
@@ -5245,5 +5278,5 @@
 					if (message) {
 						/* Anexa a mensagem especificada (por folder e id_msg) 
-						   na mensagem sendo criada.*/ 
+						   na mensagem sendo criada.*/
 						attach_message(folder_name, message_number);
 					}
