Changeset 4942


Ignore:
Timestamp:
08/17/11 14:57:21 (10 years ago)
Author:
fernando-alberto
Message:

Ticket #1269 - Desenvolvimento da nova solucao de arquivamento local MailArchiver?, evolucao dos trabalhos

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sandbox/expressoMail1_2/MailArchiver/2.2/expressoMail1_2/js/mail_archiver.js

    r4909 r4942  
    142142    this.counter = 0; 
    143143    this.message_list = new Array(); 
     144    this.messageslisted = new Array(); 
    144145    this.total_messages = 0; 
    145146    this.messages_processed = 0; 
     
    149150    this.folders = null; 
    150151    this.currentfolder = 'local_root'; 
     152    this.currentmessage = null; 
    151153    this.drawdata = null; 
    152154    this.onprocess = false; 
    153155    this.queryconfig = new MAQueryConfig(); 
     156    this.messagesourcehandler = new Cxf_Transport_Handler(); 
    154157    this.specialfolders = { 
    155158                            "inbox":"local_inbox",  
     
    370373            cExecute("$this.exporteml.js_source_var",arch_handler,"folder="+url_decode(source_folder)+"&msgs_to_export="+expresso_mail_archive.message_list[0]); 
    371374        } 
    372         else throw('Ops. Message list stack is empty!'); 
     375        else throw('Ops. Message list stack is empty!\nMessage list count = ' + expresso_mail_archive.message_list.length + '\nFirst child = ' + expresso_mail_archive.message_list[0]); 
    373376    } 
    374377    catch(e){ 
     
    741744        var testing_data_xml = '<?xml version="1.0" encoding="UTF-8"?><query lowerIndex="0" upperIndex="50"><folder id="'+folderid+'"/><order asc="date"/><order desc="subject"/></query>'; 
    742745        var testing_data_json_mapped = '{"query":{"@lowerIndex":"0", "@upperIndex":"50", "folder":[{"@id":"'+folderid+'"}], "order":[{"@asc":"date", "@desc":"subject"}]}}'; 
    743  
     746        //window.alert('Query config lower = ' + expresso_mail_archive.queryconfig.lowerIndex + ' - upper = ' + expresso_mail_archive.queryconfig.upperIndex + ' folder = ' + expresso_mail_archive.queryconfig.folder); 
    744747        if (expresso_mail_archive.queryconfig.folder != null) 
    745748            var testing_data = expresso_mail_archive.queryconfig.query(); 
     
    775778    msglist["num_msgs"] = returnService.getReturn().length; 
    776779    //window.alert('print_r\n\n' + print_r(msglist)); 
     780    expresso_mail_archive.messageslisted = msglist; 
     781    //window.alert('expresso_mail_archive.message_list.length = ' + expresso_mail_archive.message_list.length); 
     782    //window.alert(print_r(expresso_mail_archive.message_list)); 
    777783    expresso_mail_archive.drawdata = {messagesList:msglist}; 
    778784    expresso_mail_archive.drawMessagesList(); 
     785     
     786    window.alert('get ajax...'); 
     787    expresso_mail_archive.getMessageSource(); 
    779788} 
    780789 
     
    799808    alternate_border(0); 
    800809    Element("border_id_0").innerHTML = "&nbsp;" + lang_folder(fcaption) + '&nbsp;<font face="Verdana" size="1" color="#505050">[<span id="new_m">&nbsp;</span> / <span id="tot_m"></span>]</font>'; 
    801     draw_box(data_to_draw, expresso_mail_archive.currentfolder, true); 
     810    draw_box(data_to_draw, 'local_' + expresso_mail_archive.currentfolder, true); 
    802811    draw_paging(expresso_mail_archive.drawdata.messagesList.length); 
    803812    Element("tot_m").innerHTML = expresso_mail_archive.drawdata.messagesList.length; 
    804813    //update_menu(); 
    805814     
     815} 
     816 
     817MailArchiver.prototype.getMessageHeaders = function(msgId){ 
     818    var msgfound = false; 
     819    var headerMsg; 
     820     
     821    //Get message header info, from message list operation previously invoked 
     822    for (var w=0; w < expresso_mail_archive.messageslisted.length; w++){ 
     823        //window.alert('comparando messageslisted "' +expresso_mail_archive.messageslisted[w]["msg_number"]+ '" com o id parametrizado "' +msgId+ '"'); 
     824        if(expresso_mail_archive.messageslisted[w]["msg_number"] == msgId){ 
     825            headerMsg = expresso_mail_archive.messageslisted[w]; 
     826            msgfound = true; 
     827            break; 
     828        } 
     829    } 
     830    //Message does not exists at message list. it will not be loaded. 
     831    if(!msgfound){ 
     832        alert('ops... the message"'+msgId+'" was not found at messages list, so it cannot be readed!') 
     833        headerMsg = null; 
     834        return; 
     835    } 
     836    return(headerMsg); 
     837} 
     838 
     839MailArchiver.prototype.getMessage = function(msgdata){ 
     840    try{ 
     841        if((msgdata.length <= 0) || (msgdata == null)){ 
     842            window.alert('no msgdata received. aborting local message load') 
     843            return; 
     844        } 
     845 
     846        expresso_mail_archive.currentmessage = expresso_mail_archive.getMessageHeaders(msgdata)["msg_number"]; 
     847        //window.alert('current message guid = ' + expresso_mail_archive.currentmessage); 
     848 
     849        //window.alert('vai invocar getMessageBody com msgid=' + expresso_mail_archive.currentmessage); 
     850        ArchiveServices.getMessageBody(expresso_mail_archive.getMessageOperationOK, expresso_mail_archive.getMessageOperationFailure, sessid, expresso_mail_archive.currentmessage); 
     851    } 
     852    catch(e){ 
     853        window.alert('Ops...getMessage fails at:\n' + e); 
     854    } 
     855} 
     856 
     857MailArchiver.prototype.getMessageOperationOK = function(returnService){ 
     858    if(returnService.getReturn().length <= 0){ 
     859        window.alert('Oh no: service return data is zero length...'); 
     860        return; 
     861    } 
     862     
     863    //window.alert('Get header info from message "' + expresso_mail_archive.currentmessage + '"'); 
     864     
     865     
     866    var msgBody = returnService.getReturn(); 
     867    var msgHeaders = expresso_mail_archive.getMessageHeaders(expresso_mail_archive.currentmessage); 
     868    var expSerializedMessage = expresso_mail_archive.toExpressoMessage(msgHeaders, msgBody); 
     869    //window.alert('Serialized data\n\n' + print_r(expSerializedMessage)); 
     870    show_msg(expSerializedMessage); 
     871} 
     872 
     873MailArchiver.prototype.getMessageOperationFailure = function(ServiceFault){ 
     874    window.alert('Message fails do be loaded.'); 
     875} 
     876 
     877//Under develpment this one 
     878MailArchiver.prototype.getMessageSource = function(){ 
     879    expresso_mail_archive.messagesourcehandler.onreadystatechange = AlerteO(); 
     880    //expresso_mail_archive.messagesourcehandler.setRequestHeader("SOAPAction", ""); 
     881    //expresso_mail_archive.messagesourcehandler.setRequestHeader("Access-Control-Allow-Origin", "*"); 
     882    //expresso_mail_archive.messagesourcehandler.setRequestHeader("Access-Control-Allow-Credentials", "true"); 
     883    window.alert('vai chamar via ajax o texto'); 
     884    expresso_mail_archive.messagesourcehandler.open("GET", "http://10.200.242.186:4333/mail/Sent/teste.txt", true); 
     885    //expresso_mail_archive.messagesourcehandler.setRequestHeader("MessageType", "CALL"); 
     886    //expresso_mail_archive.messagesourcehandler.setRequestHeader("Access-Control-Allow-Origin", "*"); 
     887    //expresso_mail_archive.messagesourcehandler.setRequestHeader("Access-Control-Allow-Credentials", "true");     
     888    expresso_mail_archive.messagesourcehandler.send(); 
     889} 
     890 
     891function AlerteO(){ 
     892    window.alert('Ajax lido:\n\nState = ' + expresso_mail_archive.messagesourcehandler.readyState + '\nStatus = ' + expresso_mail_archive.messagesourcehandler.status); 
    806893} 
    807894 
     
    839926+           's:'+dataEmail.length+':"'+dataEmail+'";' 
    840927+           's:4:"full";' 
    841 +           's:'+(dataName.length + dataEmail.length + 3)+':"'+dataName+'" <'+dataEmail+'>;' 
     928+           's:'+(dataName.length + dataEmail.length + 3)+':"'+dataName+' <'+dataEmail+'>";' 
    842929+       '}'; 
     930    //window.alert('from = ' + tplFrom); 
    843931    } 
    844932    //Data adrress from mailbox is empty, null, or canot be correctly returned by service invocation (will return 'unknow mailbox' string) 
     
    9931081} 
    9941082 
    995 MailArchiver.prototype.toExpressoMail = function(data){ 
    996      
     1083MailArchiver.prototype.toExpressoBody = function(mheader){ 
     1084    var tplBody = 'a:33:{' 
     1085+                   's:4:"body";N;' 
     1086+                   's:11:"attachments";N;' 
     1087+                   's:6:"thumbs";N;' 
     1088+                   's:9:"signature";N;' 
     1089+                   's:10:"Importance";s:6:"Normal";' 
     1090+                   's:6:"Recent";s:1:" ";' 
     1091+                   's:6:"Unseen";s:1:"N";' 
     1092+                   's:7:"Deleted";s:1:" ";' 
     1093+                   's:7:"Flagged";b:0;' 
     1094+                   's:8:"Answered";s:1:" ";' 
     1095+                   's:5:"Draft";s:1:" ";' 
     1096+                   's:10:"msg_number";s:4:"2241";' 
     1097+                   's:10:"msg_folder";s:5:"INBOX";' 
     1098+                   's:5:"udate";s:5:"10:01";' 
     1099+                   's:7:"msg_day";s:10:"10/05/2011";' 
     1100+                   's:8:"msg_hour";s:5:"10:02";' 
     1101+                   's:8:"fulldate";s:36:"10/05/2011 10:01 (05:35 horas atras)";' 
     1102+                   's:9:"smalldate";s:5:"10:04";' 
     1103+                   's:4:"from";N;' 
     1104+                   's:6:"sender";a:3:{' 
     1105+                       's:4:"name";N;' 
     1106+                       's:5:"email";s:46:"listaregional-pae-bounces@grupos.serpro.gov.br";' 
     1107+                       's:4:"full";s:46:"listaregional-pae-bounces@grupos.serpro.gov.br";' 
     1108+                   '}' 
     1109+                   's:10:"toaddress2";s:32:"comunicacao.social@serpro.gov.br";' 
     1110+                   's:2:"cc";N;' 
     1111+                   's:3:"bcc";N;' 
     1112+                   's:8:"reply_to";N;' 
     1113+                   's:7:"subject";N;' 
     1114+                   's:4:"Size";s:4:"1234";' 
     1115+                   's:15:"reply_toaddress";s:45:"com.social <comunicacao.social@serpro.gov.br>";' 
     1116+                   's:9:"timestamp";i:1305032476;' 
     1117+                   's:5:"login";i:944889240;' 
     1118+                   's:6:"header";a:16:{' 
     1119+                      's:11:"ContentType";s:6:"normal";' 
     1120+                      's:10:"Importance";s:6:"Normal";' 
     1121+                      's:6:"Recent";s:1:" ";' 
     1122+                      's:6:"Unseen";s:1:"N";' 
     1123+                      's:8:"Answered";s:1:" ";' 
     1124+                      's:5:"Draft";s:1:" ";' 
     1125+                      's:7:"Deleted";s:1:" ";' 
     1126+                      's:7:"Flagged";b:0;' 
     1127+                      's:10:"msg_number";s:4:"2251";' 
     1128+                      's:5:"udate";s:10:"10/05/2011";' 
     1129+                      's:11:"offsetToGMT";i:-10800;' 
     1130+                      's:8:"aux_date";N;' 
     1131+                      's:4:"from";a:2:{' 
     1132+                         's:4:"name";s:10:"com.social";' 
     1133+                         's:5:"email";s:32:"comunicacao.social@serpro.gov.br";' 
     1134+                      '}' 
     1135+                      's:2:"to";a:2:{' 
     1136+                         's:4:"name";s:32:"comunicacao.social@serpro.gov.br";' 
     1137+                         's:5:"email";s:32:"comunicacao.social@serpro.gov.br";' 
     1138+                      '}' 
     1139+                      's:7:"subject";s:28:"Primeira leitura - 10/5/2011";' 
     1140+                      's:4:"Size";N;' 
     1141+                      's:10:"attachment";a:2:{' 
     1142+                         's:5:"names";b:0;' 
     1143+                         's:18:"number_attachments";i:0;' 
     1144+                      '}' 
     1145+                  '}' 
     1146+                  's:12:"array_attach";N;' 
     1147+                  's:15:"url_export_file";s:160:"inc/gotodownload.php?idx_file=/var/www/expressov2/expressoMail1_2/inc/../tmpLclAtt/source_38a3e960115351578aa182ae1d6c2b7b.txt&newfilename=fonte_da_mensagem.txt";' 
     1148+                  's:2:"to";N;' 
     1149+              '}'; 
     1150    return(tplBody); 
     1151} 
     1152 
     1153MailArchiver.prototype.toExpressoMessage = function(mheader, mbody){ 
     1154    var strMessage = null; 
     1155    var strMessage1 = expresso_mail_archive.toExpressoBody(mheader); 
     1156    //var str3 = connector.unserialize(strMessage1); 
     1157    //strMessage =  eval("(" + strMessage1 + ")"); 
     1158    strMessage = connector.unserialize(strMessage1); 
     1159     
     1160    window.alert('dump strMessage:\n\n' + print_r(strMessage,0)); 
     1161     
     1162    strMessage['from'] = mheader["from"]; 
     1163    //strMessage['from'] = expresso_mail_archive.toExpressoBody(mheader, mbody); 
     1164    strMessage['subject'] = mheader["subject"]; 
     1165    strMessage['body'] = mbody; 
     1166    strMessage['to'] = mheader["to"]; 
     1167    strMessage['cc'] = mheader["cc"]; 
     1168    strMessage['local_message'] = true; 
     1169    strMessage['folder'] = 'local_' + expresso_mail_archive.currentfolder; 
     1170    strMessage['msg_number'] = mheader["msg_number"]; 
     1171    //window.alert('strMessage dump\n\n' + print_r(strMessage)); 
     1172    return(strMessage); 
     1173 
     1174 
     1175/* 
     1176 *      retorno['from'] = connector.unserialize(rs.field(2)); 
     1177        retorno['subject'] = rs.field(3); 
     1178        retorno['body'] = rs.field(4); 
     1179        //Codigo que as imagens embutidas em emails (com multipart/related ou multipart/mixed) sejam corretamente mostradas em emails arquivados. Os links do 
     1180        //tipo "./inc/show_embedded_attach.php?msg_folder=[folder]&msg_num=[msg_num]&msg_part=[part]" 
     1181        //são substituidos pelos links dos anexos capturados pelo gears. 
     1182 
     1183        var thumbs= retorno.thumbs; 
     1184        var anexos= retorno.array_attach; 
     1185        for (i in anexos) 
     1186        { 
     1187            if(anexos[i]['url'] && anexos[i]['url'].match(/((jpg)|(jpeg)|(png)|(gif)|(bmp))/gi)) 
     1188            { 
     1189                var er_imagens = new RegExp("\\.\\/inc\\/show_embedded_attach.php\\?msg_folder=[\\w/]+\\&msg_num=[0-9]+\\&msg_part="+anexos[i]['pid']); 
     1190                var Result_imagens = er_imagens.exec(retorno['body']); 
     1191                retorno['body'] = retorno['body'].replace(Result_imagens,anexos[i]['url']); 
     1192                if(thumbs && thumbs[i]){ 
     1193                    er_imagens = new RegExp("\\.\\/inc\\/show_thumbs.php\\?file_type=image\\/[\\w]+\\&msg_num=[0-9]+\\&msg_folder=[\\w/%]+\\&msg_part="+anexos[i]['pid']); 
     1194                    Result_imagens = er_imagens.exec(thumbs[i]); 
     1195                    thumbs[i] = thumbs[i].replace(Result_imagens,"'"+anexos[i]['url']+"'"); 
     1196                    er_imagens = new RegExp("\\.\\/inc\\/show_img.php\\?msg_num=[0-9]+\\&msg_folder=[\\w/%]+\\&msg_part="+anexos[i]['pid']); 
     1197                    Result_imagens = er_imagens.exec(thumbs[i]); 
     1198                    thumbs[i] = thumbs[i].replace(Result_imagens,anexos[i]['url']); 
     1199                    thumbs[i] = thumbs[i].replace(/<IMG/i,'<img width="120"'); 
     1200                } 
     1201            } 
     1202        } 
     1203 
     1204        retorno['to'] = connector.unserialize(rs.field(5)); 
     1205        retorno['cc'] = connector.unserialize(rs.field(6)); 
     1206 
     1207        retorno['local_message'] = true; 
     1208        retorno['msg_folder'] = "local_"+rs.field(7); //Now it's a local folder 
     1209        retorno['msg_number'] = rs.field(0)+plus_id; //the message number is the rowid 
     1210 **/     
    9971211} 
    9981212 
Note: See TracChangeset for help on using the changeset viewer.