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);
-    };
+    });
 
 }
