Changeset 8063 for trunk/expressoMail1_2


Ignore:
Timestamp:
03/28/13 16:24:07 (11 years ago)
Author:
marcosw
Message:

Ticket #3331 - Correção para inconsistência ao salvar mensagem e remover anexos

Location:
trunk/expressoMail1_2
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/expressoMail1_2/inc/class.imap_functions.inc.php

    r8015 r8063  
    27002700        } 
    27012701 
     2702        /*Método utilizado para retornar dados da mensagem local (desarquivada na pasta lixeira) 
     2703        para poder ser anexada à mensagem.*/ 
    27022704    function get_info_msg_archiver($params){ 
    2703          $folder = "INBOX/Trash"; 
    2704          $mbox_stream = $this->open_mbox($folder); 
    2705  
    2706         foreach($params['idMsgs'] as $i => $id){ 
    2707             $name = imap_headerinfo($mbox_stream, imap_msgno($mbox_stream ,$id)); 
    2708             $return[] =  array( 
    2709                 'uid' => $id, 
    2710                 'folder' => "archiver", 
    2711                 'type' => "imapMSG", 
    2712                 'name' => base64_encode($name->subject.".eml") 
    2713             ); 
    2714         } 
    2715          
     2705        $folder = "INBOX".$this->imap_delimiter.$this->folders['trash']; 
     2706        $mbox_stream = $this->open_mbox($folder); 
     2707        $id = $params['idMsgs']; 
     2708 
     2709        $name = imap_headerinfo($mbox_stream, imap_msgno($mbox_stream, $id)); 
     2710        $return[] =  array( 
     2711            'uid' => $id, 
     2712            'folder' => "archiver", 
     2713            'type' => "imapMSG", 
     2714            'name' => base64_encode($name->subject.".eml") 
     2715        ); 
     2716 
    27162717        return json_encode($return); 
    27172718    } 
  • trunk/expressoMail1_2/js/abas.js

    r7972 r8063  
    708708function listAttachment(ID) 
    709709{ 
    710     var imap     = new Array(); 
    711     var archiver = new Array(); 
    712     var files    = new Array(); 
    713  
    714     if(typeof msgAttachments[ID] == "undefined"){ 
    715         return ""; 
    716     } 
    717  
    718     $.each(msgAttachments[ID], function(i, each){ 
    719         
    720        if(typeof(each) == "undefined")  return true; 
    721         
    722        if(typeof $.parseJSON(each) == "number"){ 
    723              
    724            files.push(parseInt(each)); 
    725        } else { 
    726            if($.parseJSON(each).folder.indexOf("local_messages_") != -1){ 
    727                 archiver.push($.parseJSON(each)); 
    728            } else { 
    729                 imap.push(each); 
    730            } 
    731        } 
    732     }); 
    733  
    734     context = { 
    735         "imap" : imap, 
    736         "archiver" : archiver, 
    737         "files" : files 
    738     }; 
    739  
    740    return (typeof(msgAttachments[ID]) == 'undefined') ? '' : context; 
    741 } 
     710    return (typeof(msgAttachments[ID]) == 'undefined') ? '' : JSON.stringify(msgAttachments[ID]); 
     711} 
  • trunk/expressoMail1_2/js/draw_api.js

    r8062 r8063  
    47664766    fileUploadMSG.find(' .attachments-list').show();  
    47674767    var att = new Object();  
    4768     att.folder = folder_name;  
    4769     att.uid = message_number;  
    4770     att.type = 'imapMSG';  
    4771     att.name = Base64.encode(onceOpenedHeadersMessages[folder_name][message_number].subject + '.eml');  
    4772     var idATT = JSON.stringify(att);  
    4773     addAttachment(ID, idATT);  
     4768 
     4769    
     4770 
    47744771    var attach = {};  
    47754772    attach.fileName = onceOpenedHeadersMessages[folder_name][message_number].subject + '.eml';  
     
    48064803    });  
    48074804  
    4808     fileUploadMSG.find('.attachments-list').append(upload);  
    4809   
    4810     upload.find('.att-box-loading').remove();  
    4811   
    4812     fileUploadMSG.find('.attachments-list .att-box:last').qtip(  
    4813     {  
    4814         content: DataLayer.render("../prototype/modules/mail/templates/attachment_add_itemlist_tooltip.ejs", {  
    4815             attach: attach  
    4816         }),  
    4817         position: {  
    4818             corner: {  
    4819                 tooltip: 'bottomMiddle',  
    4820                 target: 'topMiddle'  
     4805    var addtip = function(attach){ 
     4806        fileUploadMSG.find('.attachments-list .att-box:last').qtip(  
     4807        {  
     4808            content: DataLayer.render("../prototype/modules/mail/templates/attachment_add_itemlist_tooltip.ejs", {  
     4809                attach: attach  
     4810            }),  
     4811            position: {  
     4812                corner: {  
     4813                    tooltip: 'bottomMiddle',  
     4814                    target: 'topMiddle'  
     4815                },  
     4816                adjust: {  
     4817                    resize: true,  
     4818                    scroll: true  
     4819                }  
    48214820            },  
    4822             adjust: {  
    4823                 resize: true,  
    4824                 scroll: true  
     4821            show: {  
     4822                when: 'mouseover',  
     4823                // Don't specify a show event  
     4824                ready: false // Show the tooltip when ready  
     4825            },  
     4826            hide: 'mouseout',  
     4827            // Don't specify a hide event  
     4828            style: {  
     4829                border: {  
     4830                    width: 1,  
     4831                    radius: 5  
     4832                },  
     4833                width: {  
     4834                    min: 75,  
     4835                    max: 1000  
     4836                },  
     4837                padding: 5,  
     4838                textAlign: 'center',  
     4839                tip: true,  
     4840                // Give it a speech bubble tip with automatic corner detection  
     4841                name: 'blue' // Style it according to the preset 'cream' style  
    48254842            }  
    4826         },  
    4827         show: {  
    4828             when: 'mouseover',  
    4829             // Don't specify a show event  
    4830             ready: false // Show the tooltip when ready  
    4831         },  
    4832         hide: 'mouseout',  
    4833         // Don't specify a hide event  
    4834         style: {  
    4835             border: {  
    4836                 width: 1,  
    4837                 radius: 5  
    4838             },  
    4839             width: {  
    4840                 min: 75,  
    4841                 max: 1000  
    4842             },  
    4843             padding: 5,  
    4844             textAlign: 'center',  
    4845             tip: true,  
    4846             // Give it a speech bubble tip with automatic corner detection  
    4847             name: 'blue' // Style it according to the preset 'cream' style  
    4848         }  
    4849     });  
     4843        });  
     4844    }  
     4845 
     4846    if(folder_name.indexOf("local_messages_") != 0) 
     4847    { 
     4848        att.folder = folder_name;  
     4849        att.uid = message_number;  
     4850        att.type = 'imapMSG';  
     4851        att.name = Base64.encode(onceOpenedHeadersMessages[folder_name][message_number].subject + '.eml');  
     4852        var idATT = JSON.stringify(att);  
     4853        addAttachment(ID, idATT);  
     4854 
     4855        fileUploadMSG.find('.attachments-list').append(upload); 
     4856        addtip(attach); 
     4857    } 
     4858    else 
     4859    { 
     4860        var folder_trash = "INBOX"+cyrus_delimiter+special_folders["Trash"]; 
     4861        expresso_mail_archive.unarchieveToAttach(folder_name, folder_trash, message_number, function(data){ 
     4862            $.ajax({ 
     4863                url: "controller.php?action=$this.imap_functions.get_info_msg_archiver", 
     4864                data:  {"idMsgs":data.idsMsg}, 
     4865                type: 'POST', 
     4866                async: false, 
     4867                success: function(data){ 
     4868                    data = JSON.parse(connector.unserialize(data)); 
     4869                    data = data[0]; 
     4870                    att.folder = folder_trash; 
     4871                    att.uid = data.uid;  
     4872                    att.type = 'imapMSG';  
     4873                    att.name = Base64.encode(onceOpenedHeadersMessages[folder_name][message_number].subject + '.eml');  
     4874                    var idATT = JSON.stringify(att);  
     4875                    addAttachment(ID, idATT); 
     4876                    fileUploadMSG.find('.attachments-list').append(upload); 
     4877                    addtip(attach); 
     4878                }, 
     4879            }); 
     4880        });  
     4881    } 
     4882    upload.find('.att-box-loading').remove();      
    48504883} 
    48514884                 
     
    52455278                                        if (message) { 
    52465279                                                /* Anexa a mensagem especificada (por folder e id_msg)  
    5247                                                    na mensagem sendo criada.*/  
     5280                                                   na mensagem sendo criada.*/ 
    52485281                                                attach_message(folder_name, message_number); 
    52495282                                        } 
  • trunk/expressoMail1_2/js/mail_archiver.js

    r7948 r8063  
    575575} 
    576576 
    577 MailArchiver.prototype.unarchieveToAttach = function (folder, new_folder, msgs_number){ 
    578     try{ 
     577MailArchiver.prototype.unarchieveToAttach = function (folder, new_folder, msgs_number, callback){ 
     578    try{ 
     579 
     580        if(typeof callback !== 'function') callback = function(){}; 
    579581 
    580582        if(typeof(expresso_mail_archive.idMsgsToAttach) == "undefined"){ 
     
    601603                (new_folder != null)?expresso_mail_archive.unarchievenewfolder = new_folder:expresso_mail_archive.unarchievenewfolder='INBOX'; 
    602604                 
    603                 expresso_mail_archive.unarchieveToAttachHandler(); 
     605                expresso_mail_archive.unarchieveToAttachHandler(callback); 
    604606                 
    605607                if(currentTab.toString().indexOf("_r") != -1){ 
     
    621623} 
    622624 
    623 MailArchiver.prototype.unarchieveToAttachHandler = function(){ 
    624     try{ 
    625         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';     
     625MailArchiver.prototype.unarchieveToAttachHandler = function(uCallback){ 
     626    try{ 
     627         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';     
    626628     
    627629        //Creates a new object to unarchive messages. It's a CXF Add-on CORS component 
     
    710712                    expresso_mail_archive.idMsgsToAttach.push(data.idsMsg); 
    711713                    handler_unarchive(data); 
     714                    uCallback(data); 
    712715                }, 
    713716                async: false, 
  • trunk/expressoMail1_2/js/main.js

    r8055 r8063  
    1 // Tempo do auto refresh (em milisegundos) 
    21var time_refresh = 150000; 
    32 
     
    35333532        mailData.input_from = $(content).find('select[name="input_from"]').val(); 
    35343533 
    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); 
    36693553            return; 
    36703554        } 
    3671         delete(expresso_mail_archive.idMsgsToAttach); 
    3672     }; 
     3555    }); 
    36733556 
    36743557} 
Note: See TracChangeset for help on using the changeset viewer.