Changeset 1595


Ignore:
Timestamp:
11/05/09 16:22:24 (14 years ago)
Author:
eduardoalex
Message:

Ticket #709 - adição da melhoria descrita no ticket em questao

Location:
trunk/expressoMail1_2
Files:
8 edited

Legend:

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

    r1558 r1595  
    277277                $body           = $this-> getBody($id_msg); 
    278278                 
    279                 $file = "source_".$_SESSION[ 'phpgw_session' ][ 'session_id' ].".php"; 
     279                $tempSubDir = md5($_SESSION[ 'phpgw_session' ][ 'session_id' ].microtime()); 
     280                $file = "source_".$tempSubDir.".php"; 
     281                //$file = "source_".$_SESSION[ 'phpgw_session' ][ 'session_id' ].".php"; 
    280282                $f = fopen($tempDir.'/'.$file,"w"); 
    281283                fputs($f,$phpheader.$header ."\r\n\r\n". $body); 
  • trunk/expressoMail1_2/js/common_functions.js

    r1526 r1595  
    7373 
    7474function unloadMess(){ 
    75         if (expresso_mail_sync.folders.length != 0) { 
     75        if (expresso_mail_sync.working) { 
    7676                var mess = get_lang("You're about archiving your e-mails from server. Do you really want to stop this action?"); 
    7777                return mess; 
  • trunk/expressoMail1_2/js/draw_api.js

    r1564 r1595  
    12791279        var option_reply_without_history                = '<span onmouseover="this.className=\'message_options_active\'" onmouseout="this.className=\'message_options\'" class="message_options" onclick=new_message("reply_without_history","'+ID+'");>'+get_lang("Reply without history")+'</span> | '; 
    12801280        var option_reply_to_all_without_history = '<span onmouseover="this.className=\'message_options_active\'" onmouseout="this.className=\'message_options\'" class="message_options" onclick=new_message("reply_to_all_without_history","'+ID+'");>'+get_lang("Reply to all without history")+'</span> |'; 
    1281         var option_source_msg = '<span class="message_options" onclick=source_msg("'+ID+'","'+url_encode(info_msg.msg_folder)+'");>'+get_lang("Message Font")+'</span> </div>';          
     1281        var option_source_msg = '<span class="message_options" onclick=proxy_mensagens.proxy_source_msg("'+ID+'","'+url_encode(info_msg.msg_folder)+'");>'+get_lang("Message Font")+'</span> </div>';            
    12821282 
    12831283        div_other_options.innerHTML = option_reply_to_all + option_reply_without_history + option_reply_to_all_without_history + option_source_msg; 
  • trunk/expressoMail1_2/js/local_messages.js

    r1518 r1595  
    3333                 
    3434                var db_in_other_use = true; 
     35                var start_trying = new Date().getTime(); 
    3536                while (db_in_other_use) { 
    3637                        try { 
     
    3940                        }  
    4041                        catch (ex) { 
    41                                 db_in_other_use=true; 
     42                                if(new Date.getTime()-start_trying>10000) { //too much time trying, throw an exception 
     43                                        throw ex; 
     44                                } 
    4245                        } 
    4346                } 
     
    934937        } 
    935938         
    936         local_messages.prototype.get_folders_to_sync = function() { 
     939        local_messages.prototype.get_folders_to_sync = function() {//Precisa ter visibilidade ao array de linguagens. 
    937940                this.init_local_messages(); 
    938941                var rs = this.dbGears.execute("select id_folder,folder_name from folders_sync where uid_usuario="+account_id); 
     
    941944                        temp = new Array(); 
    942945                        temp[0] = rs.field(0); 
    943                         temp[1] = rs.field(1); 
     946                        if(temp[0]=='INBOX/Drafts' ||temp[0]=='INBOX/Trash' || temp[0]=='INBOX/Sent') { 
     947                                temp[1] = array_lang[rs.field(1).toLowerCase()]; 
     948                        } 
     949                        else { 
     950                                temp[1] = rs.field(1);   
     951                        } 
     952                         
    944953                        retorno.push(temp); 
    945954                        rs.next(); 
  • trunk/expressoMail1_2/js/mail_sync.js

    r1518 r1595  
    22 * @author diogenes 
    33 */ 
     4 
     5        /** 
     6         *  @param folders: 
     7         *              1 - rowid of folder in sqlite 
     8         *              2 - folder name in sqlite 
     9         *              3 - ids to not download(for auto archiving) or ids to download(for archiving) 
     10         *              4 - true for auto archiving and false for normal archiving. 
     11         */ 
    412        function mail_sync() { 
    5                 this.dbGears = null; 
    6                 this.localServer = null; 
    7                 this.store = null; 
     13//              this.dbGears = null; 
     14//              this.localServer = null; 
     15//              this.store = null; 
    816                this.folders = new Array(); 
    917                this.messages = null; 
    1018                this.attachs = null; 
    1119                this.url_attachs = null; 
     20                this.working = false; 
     21                this.is_auto = null; 
     22                this.errors = new Array(); 
     23//              this.main_title = null; 
     24                 
    1225                this.main_title = null; 
     26                this.dbGears = google.gears.factory.create('beta.database'); 
     27                this.localServer = google.gears.factory.create('beta.localserver'); 
     28                this.store = this.localServer.createStore('test-store'); 
    1329        } 
    1430         
    1531        mail_sync.prototype.open_conn = function(){ 
    1632                var db_in_other_use = true; 
     33                var start_trying = new Date().getTime(); 
    1734                while (db_in_other_use) { 
    1835                        try { 
     
    2138                        }  
    2239                        catch (ex) { 
    23                                 db_in_other_use=true; 
     40                                if(new Date.getTime()-start_trying>10000) { //too much time trying, throw an exception 
     41                                        throw ex; 
     42                                } 
    2443                        } 
    2544                } 
     
    2746         
    2847        mail_sync.prototype.start_sync = function() { 
    29                 if(this.folders.length!=0) { 
     48                if(this.working) { 
    3049                        //Já está sincronizando... 
    3150                        return; 
    3251                } 
    33                 this.main_title = document.getElementById('main_title').innerHTML; 
    34                 this.dbGears = google.gears.factory.create('beta.database'); 
     52                //this.main_title = document.getElementById('main_title').innerHTML; 
     53                /*this.dbGears = google.gears.factory.create('beta.database'); 
    3554                this.localServer = google.gears.factory.create('beta.localserver'); 
    36                 this.store = this.localServer.createStore('test-store');         
     55                this.store = this.localServer.createStore('test-store');        */ 
     56                this.working=true; 
    3757                this.messages = null; 
    3858                this.attachs = null; 
     
    4868                        temp[1] = rs.field(1); 
    4969                        temp[2] = null; 
     70                        temp[3] = false; 
    5071                        var rs2 = this.dbGears.execute("select mail.original_id from mail inner join folder on mail.id_folder=folder.rowid where folder.folder = ? and mail.uid_usuario=?",[temp[1]==get_lang('Inbox')?'Inbox':temp[1],account_id]); 
    5172                        while(rs2.isValidRow()) { 
     
    85106        } 
    86107         
     108        mail_sync.prototype.archive_msgs = function(folder,folder_dest,ids) { 
     109                //this.main_title = document.getElementById('main_title').innerHTML; 
     110                var temp = new Array(); 
     111                temp[0] = folder; 
     112                temp[1] = folder_dest.substr(6); 
     113                temp[2] = ids; 
     114                temp[3] = true; 
     115                this.folders.push(temp); 
     116                Element('chk_box_select_all_messages').checked = false; 
     117                 
     118                array_ids = ids.split(","); 
     119                for (var i in array_ids) { 
     120                        if (Element("check_box_message_" + array_ids[i]))  
     121                                Element("check_box_message_" + array_ids[i]).checked = false; 
     122                        remove_className(Element(array_ids[i]), 'selected_msg'); 
     123                } 
     124                if(!this.working) { 
     125                        this.working=true; 
     126                        this.syncronize_folders(); 
     127                } 
     128                else { 
     129                        write_msg(get_lang("An archiving is in process, but dont worry, expresso will process this messages after the actual archiving")); 
     130                } 
     131        } 
     132         
    87133        mail_sync.prototype.syncronize_folders = function() { 
    88134                if (this.folders.length == 0) { 
    89135                        document.getElementById('main_title').innerHTML = get_lang("Deleting downloadeds msgs..."); 
    90136                        expresso_mail_sync.remove_archived_mails(); 
     137                        this.working=false; 
     138                        update_menu(); 
    91139                        return; 
    92140                } 
    93141                var folder_to_sync = this.folders.pop(); 
    94                 folder_to_sync[1] = folder_to_sync[0].toUpperCase()=="INBOX"?"Inbox":folder_to_sync[1]; 
     142                folder_to_sync[1] = folder_to_sync[0].toUpperCase()=="INBOX" && !folder_to_sync[3]?"Inbox":folder_to_sync[1]; 
     143                 
     144                if(folder_to_sync[3]) { //Em caso de arquivamento normal, pode ser que a pasta inbox ainda não tenha sido criada. 
     145                        expresso_mail_sync.open_conn() 
     146                        if(!expresso_mail_sync.has_local_mails()) { 
     147                                expresso_mail_sync.dbGears.execute("insert into folder (folder,uid_usuario) values (?,?)",["Inbox",account_id]); 
     148                        } 
     149                        expresso_mail_sync.dbGears.close(); 
     150                        ttreeBox.update_folder(); 
     151                         
     152                } 
    95153                 
    96154                var start_sync_mails = function(data) { 
    97155                        expresso_mail_sync.messages=data; 
    98                         document.getElementById('main_title').innerHTML = get_lang("Auto archiving")+" "+lang_folder(folder_to_sync[1])+": 0 / "+data.length; 
     156                        if(expresso_mail_sync.is_auto) 
     157                                document.getElementById('main_title').innerHTML = get_lang("Auto archiving")+" "+lang_folder(folder_to_sync[1])+": 0 / "+data.length; 
     158                        else 
     159                                document.getElementById('main_title').innerHTML = get_lang("Archiving messages on folder")+" "+lang_folder(folder_to_sync[1])+": 0 / "+data.length; 
    99160 
    100161                        expresso_mail_sync.syncronize_mails(folder_to_sync[1]); 
    101162                } 
    102                 document.getElementById('main_title').innerHTML = get_lang("Starting to sync folder ")+lang_folder(folder_to_sync[1]); 
    103                 cExecute("$this.imap_functions.msgs_to_archive&folder=" + folder_to_sync[0]+"&mails="+folder_to_sync[2] , start_sync_mails); 
     163                 
     164 
     165                if (folder_to_sync[3]) { 
     166                        document.getElementById('main_title').innerHTML = get_lang("Starting to archive messages"); 
     167                        cExecute("$this.imap_functions.get_info_msgs&folder=" + folder_to_sync[0] + "&msgs_number=" + folder_to_sync[2], start_sync_mails); 
     168                        this.is_auto = false; 
     169                } 
     170                else { 
     171                        document.getElementById('main_title').innerHTML = get_lang("Starting to sync folder")+" "+lang_folder(folder_to_sync[1]); 
     172                        cExecute("$this.imap_functions.msgs_to_archive&folder=" + folder_to_sync[0] + "&mails=" + folder_to_sync[2], start_sync_mails); 
     173                        this.is_auto = true; 
     174                } 
     175                         
    104176        } 
    105177         
     
    118190                new_value = parseInt(new_value) + 1; 
    119191                document.getElementById('main_title').innerHTML = document.getElementById('main_title').innerHTML.replace(value_to_change,new_value+" /"); 
    120                  
    121192                msg_to_sync = connector.unserialize(msg_to_sync); 
     193                 
    122194                var source_msg = new Array(); 
    123195                source_msg['url'] = msg_to_sync.url_export_file; 
    124                  
     196 
    125197                if (typeof(msg_to_sync['array_attach'])=='object'&&(msg_to_sync['array_attach'] instanceof Array)) 
    126198                        expresso_mail_sync.attachs = msg_to_sync['array_attach'].slice(); 
     
    134206                if (expresso_mail_sync.attachs == null || expresso_mail_sync.attachs.length == 0) { 
    135207                        expresso_mail_sync.insert_mail(msg, folder_dest); 
     208                         
    136209                        return; 
    137210                } 
     
    140213                 
    141214                var call_back = function(url,success,captureId) { 
    142                         //TODO: Tratar se houver erro ao baixar anexo... 
    143                         expresso_mail_sync.download_attachs(msg,folder_dest); 
     215                         
     216                        if (!success) { 
     217                                /* 
     218                                 * 0 - original id 
     219                                 * 1 - message subject 
     220                                 * 2 - original folder 
     221                                 */ 
     222                                var mail_error = new Array(); 
     223                                mail_error[0] = msg.msg_number; 
     224                                mail_error[1] = msg.subject; 
     225                                mail_error[2] = msg.msg_folder; 
     226                                expresso_mail_sync.errors.push(mail_error); 
     227                                alert('erro ao baixar: '+url); 
     228                                 
     229                                /*if (typeof(msg['array_attach']) == 'object' && (msg['array_attach'] instanceof Array)) { 
     230                                        for (var i in msg['array_attach']) { //remove os anexos que já foram baixados para essa mensagem... 
     231                                                expresso_mail_sync.store.remove(msg['array_attach'][i]['url']); 
     232                                        } 
     233                                }*/ 
     234                                expresso_mail_sync.syncronize_mails(folder_dest); //Pula para o próximo e-mail. 
     235                        } 
     236                        else { 
     237                                expresso_mail_sync.download_attachs(msg, folder_dest);//continua baixando o próximo anexo 
     238                        } 
    144239                } 
    145240                expresso_mail_sync.store.capture(attach_to_capt['url'],call_back); 
     
    147242         
    148243        mail_sync.prototype.insert_mail = function(msg,folder) { 
    149                  
    150244                try { 
    151                 //      document.getElementById('div_menu_c3').innerHTML = document.getElementById('div_menu_c3').innerHTML.replace(/(\d+) de/,(((int)"$1")+1)+" de"); 
    152 //                      document.getElementById('div_menu_c3').innerHTML += expresso_mail_sync.messages.length + "restantes"; 
    153                          
     245 
    154246                        expresso_mail_sync.open_conn(); 
    155                          
     247                 
    156248                        var msg_info = msg; 
    157249                        var msg_header = msg['header']; 
     
    162254                        var login = msg_info.login; 
    163255                        var original_id = msg_info.msg_number; 
    164                         var original_folder = msg_info.msg_folder; 
    165                          
     256                        var original_folder = msg_info.msg_folder=='INBOX/Lixeira/tmpMoveToLocal'?msg_info.msg_folder+(Date.parse(new Date)):msg_info.msg_folder; 
     257 
    166258                        //Os campos abaixo precisam estar isolados para busca de mensagens em cima deles. 
    167259                        var from = connector.serialize(msg_info.from); 
     
    182274                        //A data no header pode vir como horário ao invés de data, caso o usuário tenha arquivado no mesmo 
    183275                        //dia que recebeu a msg. Para esses casos, usar a data aux que vem com o dia. 
    184                         if(msg_header.udate.indexOf(":")!=-1) { 
     276                        if(msg_header.udate.indexOf("/")==-1) { 
    185277                                msg_header.udate = msg_header.aux_date; 
    186278                        } 
     279                 
    187280                         
    188281                        /** 
     
    203296                        id_folder = rs.field(0); 
    204297         
    205                          
    206298                        if(msg_info.Unseen=="U") 
    207299                                unseen = 1; 
    208300                        this.dbGears.execute("insert into mail (mail,original_id,original_folder,header,timestamp,uid_usuario,unseen,id_folder,ffrom,subject,fto,cc,body,size) values (?,?,?,?,?,?,?,?,?,?,?,?,?,?)",[mail,original_id,original_folder,header,timestamp,login,unseen,id_folder,from,subject,to,cc,body,size]); 
    209301                         
     302                         
     303                         
    210304                        //Preenche os anexos. 
    211305                        var id_mail = this.dbGears.lastInsertRowId; 
     
    215309                        } 
    216310                         
    217                         if(preferences.keep_after_auto_archiving!=1) 
     311                        var check_remove; 
     312                        if(this.is_auto) 
     313                                check_remove = preferences.keep_after_auto_archiving; 
     314                        else 
     315                                check_remove = preferences.keep_archived_messages; 
     316                         
     317                         
     318                         
     319                        if(check_remove!=1) 
    218320                                this.dbGears.execute("insert into msgs_to_remove (id_msg,folder,uid_usuario) values (?,?,?)",[original_id,original_folder,account_id]); 
    219                          
    220                          
     321                                                 
    221322                } catch (error) { 
    222                         //TODO: O que fazer se der erro ao baixar um email? 
     323                        /* 
     324                         * 0 - original id 
     325                         * 1 - message subject 
     326                         * 2 - original folder 
     327                         */ 
     328                        var mail_error = new Array(); 
     329                        mail_error[0] = original_id; 
     330                        mail_error[1] = subject; 
     331                        mail_error[2] = original_folder; 
     332                        this.errors.push(mail_error); 
     333                         
     334                        if (typeof(msg_info['array_attach'])=='object'&&(msg_info['array_attach'] instanceof Array)) {  
     335                                for(var i in msg_info['array_attach']) { //remove os anexos que já foram baixados para essa mensagem... 
     336                                        this.store.remove(msg_info['array_attach'][i]['url']); 
     337                                } 
     338                        } 
     339 
    223340                } 
    224341                this.dbGears.close(); 
    225342                this.syncronize_mails(folder); 
     343        } 
     344         
     345        mail_sync.prototype.has_local_mails = function() {//This function considers that the connection with base is already opened. 
     346                var rs = this.dbGears.execute("select rowid from folder limit 0,1"); 
     347                if(rs.isValidRow()) 
     348                        return true; 
     349                else  
     350                        return false; 
    226351        } 
    227352         
     
    257382                                        Element('tot_m').innerHTML = parseInt(Element('tot_m').innerHTML) - data.msgs_number.length; 
    258383                                } 
     384                                ttreeBox.update_folder(); 
    259385                                refresh(); 
    260386                                expresso_mail_sync.remove_archived_mails(); 
     
    268394                else { 
    269395                        this.dbGears.close(); 
    270                         document.getElementById('main_title').innerHTML = get_lang("End of auto download messages"); 
    271                         window.setTimeout("eval('document.getElementById(\"main_title\").innerHTML =expresso_mail_sync.main_title')",3000); 
     396                        document.getElementById('main_title').innerHTML = get_lang("End of archive messages"); 
     397                        if(this.errors.length>0) { 
     398                                //TODO: Tratar melhor quando existirem erros... 
     399                                write_msg(get_lang("at least, one of selected mails is already archived, expresso tried to archive the others, check them later")); 
     400                                this.errors=new Array(); 
     401                        } 
     402                        window.setTimeout("eval('document.getElementById(\"main_title\").innerHTML =\"Expresso Mail\"')",3000); 
    272403                } 
    273404                 
  • trunk/expressoMail1_2/js/main.js

    r1531 r1595  
    767767                return; 
    768768        } 
    769         var has_local_messages_before = expresso_local_messages.has_local_mails(); //vejo se já tinha mensagens locais 
     769 
     770        if(!id_msgs) 
     771                id_msgs = get_selected_messages(); 
     772         
     773        if(folder_dest=='local_root' || folder_dest==null) //Caso seja o primeiro arquivamento... 
     774                folder_dest = 'local_Inbox'; 
     775         
     776        if (parseInt(id_msgs) > 0 || id_msgs.length > 0) 
     777                expresso_mail_sync.archive_msgs(folder,folder_dest,id_msgs);  
     778                //cExecute("$this.imap_functions.get_info_msgs&folder=" + folder + "&msgs_number=" + id_msgs , handler_arquivar_mensagens); 
     779        else  
     780                write_msg(get_lang('No selected message.')); 
     781        /*var has_local_messages_before = expresso_local_messages.has_local_mails(); //vejo se já tinha mensagens locais 
    770782        var handler_arquivar_mensagens = function(data) { 
    771783                var sucess = true; 
     
    819831                cExecute("$this.imap_functions.get_info_msgs&folder=" + folder + "&msgs_number=" + id_msgs , handler_arquivar_mensagens); 
    820832        else  
    821                 write_msg(get_lang('No selected message.')); 
     833                write_msg(get_lang('No selected message.'));*/ 
    822834         
    823835} 
  • trunk/expressoMail1_2/programed_archiving.php

    r1518 r1595  
    99        ); 
    1010 
    11          
     11 
    1212        require_once('../header.inc.php'); 
    1313 
     
    8989                } 
    9090                $GLOBALS['phpgw']->template->set_var('all_folders',$options); 
    91          
    92          
     91                echo '<script language="javascript">var array_lang = new Array();</script>'; 
     92                include("inc/load_lang.php");    
    9393         
    9494                $GLOBALS['phpgw']->template->set_var('lang_Would_you_like_to_keep_messages_on_server_?',lang("Would you like to keep archived messages?")); 
Note: See TracChangeset for help on using the changeset viewer.