Ignore:
Timestamp:
06/20/09 01:07:18 (15 years ago)
Author:
rafaelraymundo
Message:

Ticket #558 - Adicionada funcionalidade de assinatura e criptografia de e-mails.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/expressoMail1_2/js/main.js

    r1005 r1035  
    2323                        write_msg(get_lang("Attention, you are in out of office mode."), true); 
    2424                ConstructMenuTools(); 
     25 
     26        // Insere a applet de criptografia 
     27        if (preferences.use_signature_digital_cripto == '1'){ 
     28            loadApplet(); 
     29        } 
     30        // Fim da inserção da applet 
     31 
    2532                cExecute ("$this.imap_functions.get_folders_list", update_menu); 
    2633        } 
     
    3643        // Get cyrus delimiter 
    3744        cyrus_delimiter = Element('cyrus_delimiter').value; 
    38          
     45    var del_return = function(data){ 
     46                //alert(data); 
     47        } 
     48 
     49        cExecute ("$this.imap_functions.delete_mailbox&del_past=INBOX/decifradas", del_return); 
    3950        cExecute ("$this.db_functions.get_dropdown_contacts", save_contacts); 
    4051        cExecute ("$this.functions.get_preferences", save_preferences); 
    4152        setTimeout('auto_refresh()', time_refresh); 
    4253} 
     54 
     55/** 
     56 * Carrega a applet java no objeto search_div 
     57 * @author Mário César Kolling <mario.kolling@serpro.gov.br> 
     58 */ 
     59 
     60function loadApplet(){ 
     61 
     62    var search_div = Element('search_div'); 
     63    var applet = null; 
     64    if (navigator.userAgent.match('MSIE')){ 
     65        applet = document.createElement('<object style="display:yes;width:0;height:0;vertical-align:bottom;" id="cert_applet" ' + 
     66            'classid="clsid:8AD9C840-044E-11D1-B3E9-00805F499D93"></object>'); 
     67 
     68        //applet = document.createElement('object'); 
     69        //var attributes = { 
     70        //    style:'display:yes;width:0;height:0;vertical-align:bottom;', 
     71        //    id:'cert_applet', 
     72        //    classid:'clsid:8AD9C840-044E-11D1-B3E9-00805F499D93' 
     73        //} 
     74 
     75        var parameters = { 
     76            type:'application/x-java-applet;version=1.5', 
     77            code:'ExpressoSmimeApplet', 
     78            codebase:'../', 
     79            mayscript:'true', 
     80            token: token_param, 
     81            locale: locale, 
     82            archive:'ExpressoCertMail.jar,' + 
     83                'ExpressoCert.jar,' + 
     84                'bcmail-jdk15-142.jar,' + 
     85                'mail.jar,' + 
     86                'activation.jar,' + 
     87                'bcprov-jdk15-142.jar,' + 
     88                'commons-codec-1.3.jar,' + 
     89                'commons-httpclient-3.1.jar,' + 
     90                'commons-logging-1.1.1.jar' 
     91            //debug:'true' 
     92        } 
     93 
     94        //for (var attribute in attributes){ 
     95        //    applet.setAttribute(attribute, attributes[attribute]); 
     96        //} 
     97 
     98        if (parameters != 'undefined' && parameters != null){ 
     99            for (var parameter in parameters) { 
     100                var param = document.createElement("PARAM"); 
     101                param.setAttribute("name",parameter); 
     102                param.setAttribute("value",parameters[parameter]); 
     103                applet.appendChild(param); 
     104            } 
     105        } 
     106        search_div.appendChild(applet); 
     107        //alert(search_div.innerHTML); 
     108        //alert(window.); 
     109    } 
     110    else { 
     111        applet = document.createElement('embed'); 
     112        applet.innerHTML = '<embed style="display:yes;width:0;height:0;vertical-align:bottom;" id="cert_applet" code="ExpressoSmimeApplet.class" ' + 
     113            'codebase="../" locale="'+locale+'"'+ 
     114            'archive="ExpressoCertMail.jar,ExpressoCert.jar,bcmail-jdk15-142.jar,mail.jar,activation.jar,bcprov-jdk15-142.jar,commons-codec-1.3.jar,commons-httpclient-3.1.jar,commons-logging-1.1.1.jar" ' + 
     115            'token="' + token_param + '" ' + 
     116            'type="application/x-java-applet;version=1.5" mayscript > ' + 
     117            //'type="application/x-java-applet;version=1.5" debug="true" mayscript > ' + 
     118            '<noembed> ' + 
     119            'No Java Support. ' + 
     120            '</noembed> ' + 
     121            '</embed> '; 
     122        search_div.appendChild(applet); 
     123    } 
     124} 
     125 
    43126function disable_field(field,condition) { 
    44127        var comando = "if ("+condition+") { document.getElementById('"+field.id+"').disabled=true;} else { document.getElementById('"+field.id+"').disabled=false; }"; 
     
    137220                        write_msg(get_lang("Error in SMTP sending read confirmation.")); 
    138221        } 
     222     
     223        if(msg_info.source) 
     224        { 
     225        // Abrindo um e-mail criptografado 
     226        // Verifica se existe o objeto applet 
     227        if (!Element('cert_applet')){ 
     228            // se não existir, mostra mensagem de erro. 
     229            write_msg(get_lang('The preference "%1" isn\'t enabled.', get_lang('Enable digitally sign/cipher the message?'))); 
     230        } else { 
     231            // se existir prepara os dados para serem enviados e chama a 
     232            // operação na applet 
     233 
     234            connector.showProgressBar(); 
     235 
     236           // if ((msg_info.DispositionNotificationTo) && ((msg_info.Unseen == 'U') || (msg_info.Recent == 'N'))){ 
     237            /*  var confNotification = confirm(get_lang("The sender waits your notification of reading. Do you want to confirm this?"), ""); 
     238                if (confNotification)*/ 
     239            //        cExecute ("$this.imap_functions.send_notification&notificationto="+msg_info.DispositionNotificationTo+"&subject="+url_encode(msg_info.subject), handler_sendNotification); 
     240           // } 
     241 
     242            Element('cert_applet').doButtonClickAction('decript', 
     243                                                        msg_info.msg_number, 
     244                                                        msg_info.source, 
     245                                                        msg_info.msg_folder); // Passa os dados para a applet 
     246        } 
     247                return; 
     248 
     249        } 
     250 
     251 
     252        if (msg_info.status_get_msg_info == 'false') 
     253        { 
     254                write_msg(get_lang("Problems reading your message")+ "."); 
     255                return; 
     256        } 
    139257 
    140258        if (msg_info.status == 'false'){ 
     
    142260        } 
    143261        else{ 
     262        var ID = msg_info.original_ID ? msg_info.original_ID : msg_info.msg_number; 
     263        var id_msg_read = ID+"_r"; 
     264 
    144265                if (preferences.use_shortcuts == '1') 
    145                         select_msg(msg_info.msg_number, 'null'); 
     266                        select_msg(ID, 'null'); 
    146267                // Call function to draw message 
    147                 var id_msg_read = msg_info.msg_number +"_r"; 
    148268                // If needed, delete old border 
    149269                if (openTab.type[currentTab] == 2 || openTab.type[currentTab] == 3) 
     
    173293 
    174294                var domains = ""; 
    175                 if ((msg_info.DispositionNotificationTo) && (!msg_is_read(msg_info.msg_number) || (msg_info.Recent == 'N'))) 
     295                if ((msg_info.DispositionNotificationTo) && (!msg_is_read(ID) || (msg_info.Recent == 'N'))) 
    176296                {                        
    177297                        if (preferences.notification_domains != undefined && preferences.notification_domains != "") 
     298            { 
    178299                                domains = preferences.notification_domains.split(','); 
     300            } 
    179301                        else 
    180302                        {                                
     
    194316                } 
    195317                //Change msg class to read. 
    196                 if (!msg_is_read(msg_info.msg_number)) 
     318                if (!msg_is_read(ID)) 
    197319                { 
    198                         set_msg_as_read(msg_info['msg_number'], true); 
    199                         if (msg_info.cacheHit) 
    200                                 set_message_flag(msg_info.msg_number, "seen"); // avoid caducous (lazy) data 
    201                 } 
    202  
     320            set_msg_as_read(ID, true); 
     321                        if (msg_info.cacheHit || (!proxy_mensagens.is_local_folder(get_current_folder()) && msg_info.original_ID)) 
     322            { 
     323                                set_message_flag(ID, "seen"); // avoid caducous (lazy) data 
     324            } 
     325        } 
    203326        } 
    204327} 
     
    12141337 
    12151338function send_message_return(data, ID){ 
     1339 
     1340    var sign = false; 
     1341        var crypt = false; 
     1342 
     1343    if ((preferences.use_assinar_criptografar != '0') && (preferences.use_signature_digital_cripto != '0')){ 
     1344                var checkSign = document.getElementById('return_digital_'+ID) 
     1345                if (checkSign.checked){ 
     1346                        sign = true; 
     1347                } 
     1348 
     1349                var checkCript = document.getElementById('return_cripto_'+ID); 
     1350                if (checkCript.checked){ 
     1351                        crypt = true; 
     1352                } 
     1353        } 
     1354 
     1355    if (typeof(data) == 'object' && !data.success) 
     1356        { 
     1357        connector = new  cConnector(); 
     1358        connector.showProgressBar(); 
     1359 
     1360        if (sign || crypt){ 
     1361            var operation = ''; 
     1362                        if (sign){ 
     1363                                operation = 'sign'; 
     1364                        } 
     1365                        else { // crypt 
     1366                //TODO: Colocar mensagem de erro, e finalizar o método. 
     1367                                operation = 'nop'; 
     1368                        } 
     1369        } 
     1370 
     1371        if (data.body){ 
     1372            Element('cert_applet').doButtonClickAction(operation, ID, data.body); 
     1373        } 
     1374        else { 
     1375                        alert(data.error); 
     1376                } 
     1377 
     1378                return; 
     1379    } 
     1380 
    12161381        if(data && data.success == true ){ 
    12171382                // if send ok, set a flag as answered or forwarded 
     
    12521417                        write_msg(get_lang("Connection failed with %1 Server. Try later.", "Web")); 
    12531418        } 
     1419} 
     1420 
     1421function appletReturn(smime, ID, operation, folder){ 
     1422        //alert('os dados chegaram!'); 
     1423    //alert("ID: " + ID + "\n" + smime); 
     1424        if(operation=='decript') 
     1425        { 
     1426                var handler = function(data){ 
     1427 
     1428                        if(data.msg_day == '') 
     1429                        { 
     1430                header=expresso_local_messages.get_msg_date(data.original_ID, proxy_mensagens.is_local_folder(get_current_folder())); 
     1431 
     1432                                data.fulldate=header.fulldate; 
     1433                                data.smalldate=header.smalldate; 
     1434                                data.msg_day = header.msg_day; 
     1435                                data.msg_hour = header.msg_hour; 
     1436 
     1437                        } 
     1438                        this.show_msg(data); 
     1439                } 
     1440                para="&source="+smime+"&ID="+ID+"&folder="+folder; 
     1441                cExecute ("$this.imap_functions.show_decript&", handler, para); 
     1442        }else 
     1443        { 
     1444        ID_tmp = ID; 
     1445        // Lê a variável e chama a nova função cExecuteForm 
     1446        // Processa e envia para o servidor web 
     1447        // Faz o request do connector novamente. Talvez implementar no connector 
     1448        // para manter coerência. 
     1449 
     1450        var handler_send_smime = function(data){ 
     1451            send_message_return(data, this.ID_tmp); // this is a hack to escape quotation form connector bug 
     1452        }; 
     1453 
     1454        var textArea = document.createElement("TEXTAREA"); 
     1455        textArea.style.display='none'; 
     1456        textArea.name = "smime"; 
     1457        textArea.value += smime; 
     1458 
     1459        // Lê a variável e chama a nova função cExecuteForm 
     1460        // Processa e envia para o servidor web 
     1461        // Faz o request do connector novamente. Talvez implementar no connector 
     1462        // para manter coerência. 
     1463        if (is_ie){ 
     1464            var i = 0; 
     1465            while (document.forms(i).name != "form_message_"+ID){i++} 
     1466            form = document.forms(i); 
     1467        } 
     1468        else 
     1469            form = document.forms["form_message_"+ID]; 
     1470 
     1471        form.appendChild(textArea); 
     1472 
     1473        cExecuteForm ("$this.imap_functions.send_mail", form, handler_send_smime, ID); 
     1474    } 
    12541475} 
    12551476 
Note: See TracChangeset for help on using the changeset viewer.