Changeset 8063 for trunk/expressoMail1_2/js/main.js
- Timestamp:
- 03/28/13 16:24:07 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/expressoMail1_2/js/main.js
r8055 r8063 1 // Tempo do auto refresh (em milisegundos)2 1 var time_refresh = 150000; 3 2 … … 3533 3532 mailData.input_from = $(content).find('select[name="input_from"]').val(); 3534 3533 3535 3536 var filesAux = []; 3537 // VERIFY IF EXISTS MESSAGE TO ATTACH 3538 if(typeof mailData.attachments == "object"){ 3539 3540 3541 if(mailData.attachments.files.length){ 3542 var files = mailData.attachments.files; 3543 var filesAux = new Array(); 3544 3545 $.each(files, function(i, each){ 3546 filesAux.push(JSON.stringify(each)); 3547 }); 3548 } 3549 3550 // VERIFY IF EXISTS MESSAGE OF ARCHIVE 3551 3552 if(mailData.attachments.archiver.length){ 3553 3554 // CREATE ONE VARIABLE TO STORE ALL THE MESSAGES INFORMATION 3555 var archiver = new Array(); 3556 3557 // UNARCHIEVE ALL THE MESSAGES TO IMAP TRASH 3558 $.each(mailData.attachments.archiver, function(i, each){ 3559 expresso_mail_archive.unarchieveToAttach(each.folder,"INBOX/Trash",each.uid); 3560 }); 3561 3562 // FIX THE PROBLEM WITH ASYNC 3563 // noReady is calling always that the variable is not complete with all the messages ids 3564 notReady = function(){ 3565 setTimeout(function(){ 3566 if(mailData.attachments.archiver.length == expresso_mail_archive.idMsgsToAttach.length){ 3567 // THIS FUNCTION IS FOR TO GET THE INFORMATION OF THE MESSAGE NEWLY UNARCHIVED 3568 readyToFetch(); 3569 // THIS FUNCTION IS FOR TO SEND THE MESSAGE WITH ATTACHMENT 3570 readyToSend(); 3571 } else { 3572 // IF THE ARRAY DON'T HAVE ALL THE MESSAGES IDS, OKAY, NO PROBLEM... CALL THIS FUNCTION AGAIN! 3573 noReady(); 3574 } 3575 },30); 3576 }; 3577 notReady(); 3578 3579 // THIS FUNCTION IS FOR TO GET THE INFORMATION OF THE MESSAGE NEWLY UNARCHIVED 3580 readyToFetch = function(){ 3581 $.ajax({ 3582 url: "controller.php?action=$this.imap_functions.get_info_msg_archiver", 3583 data: {"idMsgs":expresso_mail_archive.idMsgsToAttach}, 3584 type: 'POST', 3585 async: false, 3586 success: function(data){ 3587 data = connector.unserialize(data); 3588 archiver.push(data); 3589 }, 3590 }); 3591 3592 // HERE, THE MESSAGES IMAP ARE READY FOR TO SEND... 3593 mailData.attachments = mailData.attachments.imap; 3594 3595 // BUT, I NEED TO PREPARE THE MESSAGE ARCHIVE FOR TO SEND. 3596 archiver = $.parseJSON(archiver[0]); 3597 if(archiver.length){ 3598 $.each(archiver, function(i, each){ 3599 mailData.attachments.push(JSON.stringify(archiver[i])); 3600 }); 3601 } 3602 3603 if(filesAux.length){ 3604 $.each(filesAux, function(i, each){ 3605 mailData.attachments.push(each); 3606 }); 3607 } 3608 3609 // GOOD, NOW THE ATTACHMENTS ARE READY TO SEND! 3610 mailData.attachments = JSON.stringify(mailData.attachments); 3611 }; 3612 } else if(mailData.attachments.imap.length) { 3613 // IF THIS MESSAGE JUST HAVE IMAP MESSAGES 3614 mailData.attachments = mailData.attachments.imap; 3615 if(filesAux.length){ 3616 $.each(filesAux, function(i, each){ 3617 mailData.attachments.push(each); 3618 }); 3619 } 3620 mailData.attachments = JSON.stringify(mailData.attachments); 3621 setTimeout(function(){ readyToSend() }, 30); 3622 } else if(mailData.attachments.files.length){ 3623 if(filesAux.length){ 3624 mailData.attachments = []; 3625 $.each(filesAux, function(i, each){ 3626 mailData.attachments.push(each); 3627 }); 3628 mailData.attachments = JSON.stringify(mailData.attachments); 3629 setTimeout(function(){ readyToSend() }, 30); 3630 } 3631 } 3632 3633 } else { 3634 // IF THIS MESSAGE DON'T HAVE ATTACHMENT, CALL READYTOSEND. 3635 setTimeout(function(){ readyToSend() }, 30); 3636 mailData.attachments = []; 3637 } 3638 3639 // THIS FUNCTION IS FOR TO SEND THE MESSAGE WITH ATTACHMENT OR NOT. 3640 readyToSend = function(){ 3641 3642 if(stringEmail != ""){ 3643 $.ajax({ 3644 url: "controller.php?action=$this.imap_functions.send_mail", 3645 data: mailData, 3646 type: 'POST', 3647 async: false, 3648 beforeSend: function(jqXHR, settings){ 3649 write_msg( get_lang( 'Sending the message...' ) ); 3650 $(content).find('button.send').button('option', 'disabled', true); 3651 }, 3652 success: function(data){ 3653 send_message_return(connector.unserialize(data),ID); 3654 // HERE, I NEED TO DELETE THE MESSAGES THAT WERE UNARCHIVE FROM ARCHIVE. 3655 delete_msgs("INBOX/Trash",expresso_mail_archive.idMsgsToAttach, false, false); 3656 }, 3657 error: function(){ 3658 write_msg(get_lang( 'Error trying to send the message. Retry in a few seconds...' ) ); 3659 $(content).find('button.send').button('option', 'disabled', false); 3660 var interval = setInterval(function(){ 3661 send_valided_message(ID,folder,folder_name); 3662 clearInterval(interval); 3663 },15000); 3664 return; 3665 } 3666 }); 3667 }else{ 3668 write_msg(get_lang("message without receiver")); 3534 $.ajax({ 3535 url: "controller.php?action=$this.imap_functions.send_mail", 3536 data: mailData, 3537 type: 'POST', 3538 async: false, 3539 beforeSend: function(jqXHR, settings){ 3540 write_msg( get_lang( 'Sending the message...' ) ); 3541 $(content).find('button.send').button('option', 'disabled', true); 3542 }, 3543 success: function(data){ 3544 send_message_return(connector.unserialize(data),ID); 3545 }, 3546 error: function(){ 3547 write_msg(get_lang( 'Error trying to send the message. Retry in a few seconds...' ) ); 3548 $(content).find('button.send').button('option', 'disabled', false); 3549 var interval = setInterval(function(){ 3550 send_valided_message(ID,folder,folder_name); 3551 clearInterval(interval); 3552 },15000); 3669 3553 return; 3670 3554 } 3671 delete(expresso_mail_archive.idMsgsToAttach); 3672 }; 3555 }); 3673 3556 3674 3557 }
Note: See TracChangeset
for help on using the changeset viewer.