/** * @author diogenes */ function local_messages() { this.dbGears = null; this.localServer = null; this.store = null; } function charOrdA (a, b){ a = a[0].toLowerCase(); b = b[0].toLowerCase(); if (a>b) return 1; if (a b) return -1; return 0; } function HeaderFlags() { this.Answered = 0; //this.Draft = 0; this.Flagged = 0; this.Recent = 0; } HeaderFlags.prototype.getAnswered = function() { return this.Answered; } HeaderFlags.prototype.setAnswered = function(answered) { this.Answered = answered; } //HeaderFlags.prototype.getDraft = function() //{ // return this.Draft; //} HeaderFlags.prototype.setDraft = function(draft) { this.Draft = draft; } HeaderFlags.prototype.getFlagged = function() { return this.Flagged; } HeaderFlags.prototype.setFlagged = function(flagged) { this.Flagged = flagged; } HeaderFlags.prototype.getRecent = function() { return this.Recent; } HeaderFlags.prototype.setRecent = function(recent) { this.Recent = recent; } function FlagsParser(headerObj) { this.Header = headerObj; } FlagsParser.prototype.parse = function() { var tmp = null; if (typeof this.Header == 'string') { tmp = connector.unserialize(this.Header); } else { tmp = this.Header; } flags = new HeaderFlags(); if (tmp.Answered && tmp.Answered.match(/^A$/)) { flags.setAnswered(1); //if (tmp.Draft && tmp.Draft.match(/^X$/)) //{ // flags.setDraft(1); //} } if (tmp.Flagged && tmp.Flagged.match(/^F$/)){ flags.setFlagged(1); } if (tmp.Forwarded && tmp.Forwarded.match(/^F$/)){ flags.setAnswered(1); //flags.setDraft(1); } if (tmp.Recent && tmp.Recent.match(/^R$/)){ flags.setRecent(1); } return flags; } local_messages.prototype.installGears = function (){ temp = confirm(get_lang("To use local messages you have to install google gears. Would you like to install it now?")); if (temp && typeof(preferences.googlegears_url) != 'undefined'){ if (is_ie) location.href = preferences.googlegears_url + "/gears.exe"; else location.href = preferences.googlegears_url + "/gears.xpi"; return false; } if (temp) { location.href = "http://gears.google.com/?action=install&message="+ get_lang("To use local messages, install Google Gears")+"&return=" + document.location.href; } else return false; } local_messages.prototype.create_objects = function() { if(window.google){ if (this.dbGears == null) this.dbGears = google.gears.factory.create('beta.database'); if(this.localServer == null) this.localServer = google.gears.factory.create('beta.localserver'); if(this.store == null) this.store = this.localServer.createStore('test-store'); } } local_messages.prototype.init_local_messages = function(){ //starts only database operations if(this.dbGears==null || this.localServer==null || this.store == null) this.create_objects(); var db_in_other_use = true; var start_trying = new Date().getTime(); while (db_in_other_use) { try { this.dbGears.open('database-test'); db_in_other_use = false; } catch (ex) { if(new Date().getTime()-start_trying>10000) { //too much time trying, throw an exception throw ex; } } } // this.dbGears.open('database-test'); this.dbGears.execute('create table if not exists folder (folder text,uid_usuario int,unique(folder,uid_usuario))'); this.dbGears.execute('create table if not exists mail' + ' (mail blob,original_id int,original_folder text,header blob,timestamp int,uid_usuario int,unseen int,id_folder int,' + ' ffrom text, subject text, fto text, cc text, body text, size int,unique (original_id,original_folder,uid_usuario,id_folder))'); this.dbGears.execute('create table if not exists anexo' + ' (id_mail int,nome_anexo text,url text,pid int)'); this.dbGears.execute('create table if not exists folders_sync' + ' (id_folder text,folder_name text,uid_usuario int)'); this.dbGears.execute('create table if not exists msgs_to_remove (id_msg int,folder text,uid_usuario int)'); this.dbGears.execute('create index if not exists idx_user3 on mail (id_folder,uid_usuario,timestamp)'); this.dbGears.execute('create INDEX if not exists idx_folder ON folder(uid_usuario,folder)'); //some people that used old version of local messages could not have the size column. If it's the first version //with local messages you're using in expresso, this part of code can be removed try { this.dbGears.execute('alter table mail add column size int'); }catch(Exception) { } var rs = this.dbGears.execute('select rowid,header from mail where size is null'); while(rs.isValidRow()) { var temp = connector.unserialize(rs.field(1)); this.dbGears.execute('update mail set size='+temp.Size+' where rowid='+rs.field(0)); rs.next(); } //end of temporary code try { this.dbGears.execute('begin transaction'); this.dbGears.execute('alter table mail add column answered int'); //this.dbGears.execute('alter table mail add column draft int'); this.dbGears.execute('alter table mail add column flagged int'); this.dbGears.execute('alter table mail add column recent int'); //this.dbGears.execute('commit transaction'); //transaction_ended = true; //if (transaction_ended){ rs = null; rs = this.dbGears.execute('select rowid,header from mail'); // Popular os valores das novas colunas. var tmp = null; //this.dbGears.execute('begin transaction'); while(rs.isValidRow()) { //tmp = connector.unserialize(rs.field(1)); parser = new FlagsParser(rs.field(1)); flags = parser.parse(); this.dbGears.execute('update mail set answered='+flags.getAnswered()+ ',flagged='+flags.getFlagged()+',recent='+flags.getRecent()+ //',draft='+flags.getDraft()+' where rowid='+rs.field(0)); ' where rowid='+rs.field(0)); rs.next(); } this.dbGears.execute('commit transaction'); //tmp = null; }catch(Exception) { this.dbGears.execute('rollback transaction'); } } local_messages.prototype.drop_tables = function() { this.init_local_messages(); var rs = this.dbGears.execute('select url from anexo'); while(rs.isValidRow()) { this.store.remove(rs.field(0)); rs.next(); } this.dbGears.execute('drop table folder'); this.dbGears.execute('drop table mail'); this.dbGears.execute('drop table anexo'); this.finalize(); } local_messages.prototype.insert_mail = function(msg_info,msg_header,anexos,folder) { try { this.init_local_messages(); var unseen = 0; var login = msg_info.login; var original_id = msg_info.msg_number; var original_folder = msg_info.msg_folder; //This fields needs to be separeted to search. var from = connector.serialize(msg_info.from); var subject = msg_info.subject; var body = msg_info.body; var to = connector.serialize(msg_info.toaddress2); var cc = connector.serialize(msg_info.cc); var size = msg_header.Size; //do not duplicate this information msg_info.from = null; msg_info.subject = null; msg_info.body = null; msg_info.to = null; msg_info.cc = null; msg_header.Size=null; //If the mail was archieved in the same date the user received it, the date cames with the time. //here I solved it if(msg_header.udate.indexOf(":")!=-1) { msg_header.udate = msg_header.aux_date; } /** * The importance attribute can be empty, and javascript consider as null causing nullpointer. */ if((msg_header.Importance == null) || (msg_header.Importance == "")) msg_header.Importance = "Normal"; msg_header.aux_date = null; var mail = connector.serialize(msg_info); var header = connector.serialize(msg_header); var timestamp = msg_info.timestamp; var id_folder; if((folder==null) || (folder=="local_root")) folder = "Inbox"; else folder = folder.substr(6);//take off the word "local_" var rs = this.dbGears.execute("select rowid from folder where folder=? and uid_usuario=?",[folder,account_id]); if(rs.isValidRow()) id_folder=rs.field(0); else { this.dbGears.execute("insert into folder (folder,uid_usuario) values (?,?)",["Inbox",account_id]); id_folder = this.dbGears.lastInsertRowId; } if(msg_info.Unseen=="U") unseen = 1; //parse header parser = new FlagsParser(msg_header); flags = parser.parse(); //insere o e-mail //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]); this.dbGears.execute("insert into mail (mail,original_id,original_folder,header,timestamp,uid_usuario,unseen,id_folder,ffrom,subject,fto,cc,body,size,answered,flagged,recent) values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)",[mail,original_id,original_folder,header,timestamp,login,unseen,id_folder,from,subject,to,cc,body,size,flags.getAnswered(),flags.getFlagged(),flags.getRecent()]); var call_back = function() { } this.store.capture(msg_info.url_export_file,call_back); var id_mail = this.dbGears.lastInsertRowId; this.insert_attachments(id_mail,anexos); this.finalize(); return true; } catch (error) { this.finalize(); return false; } } /** * check if ID is no from main tab, if it's from main returns false, else * returns an array with all string in position 0, the mail id in position 1 * and the part of string relative to tab in position 2 * @param {Object} id_mail */ local_messages.prototype.parse_id_mail = function(id_mail) { if (this.isInt(id_mail)) return false; var matches = id_mail.match(/(.+)(_[a-zA-Z0-9]+)/); return matches; } local_messages.prototype.isInt = function(x) { var y=parseInt(x); if (isNaN(y)) return false; return x==y && x.toString()==y.toString(); } local_messages.prototype.get_local_mail = function(id_mail) { this.init_local_messages(); var plus_id = ''; var matches = ''; if(matches = this.parse_id_mail(id_mail)) { //Mails coming from other tab. id_mail = matches[1]; plus_id = matches[2]; } var rs = this.dbGears.execute("select mail.rowid,mail.mail,mail.ffrom,mail.subject,mail.body,mail.fto,mail.cc,folder.folder,mail.original_id from mail inner join folder on mail.id_folder=folder.rowid where mail.rowid="+id_mail); var retorno = null; if(rs.isValidRow()) { retorno = rs.field(1); } retorno = connector.unserialize(retorno); //alert('tipo retorno.source: ' + typeof(retorno.source)); if (typeof(retorno.source) == 'string') { retorno.msg_number=rs.field(0)+plus_id; retorno.original_ID=rs.field(8); retorno.msg_folder=rs.field(7); //alert('tipo retorno: '+typeof(retorno)) //show_msg(retorno); } else { retorno['from'] = connector.unserialize(rs.field(2)); retorno['subject'] = rs.field(3); retorno['body'] = rs.field(4); //Codigo que as imagens embutidas em emails (com multipart/related ou multipart/mixed) sejam corretamente mostradas em emails arquivados. Os links do //tipo "./inc/show_embedded_attach.php?msg_folder=[folder]&msg_num=[msg_num]&msg_part=[part]" //são substituidos pelos links dos anexos capturados pelo gears. var thumbs= retorno.thumbs; var anexos= retorno.array_attach; for (i in anexos) { if(anexos[i]['url'] && anexos[i]['url'].match(/((jpg)|(jpeg)|(png)|(gif)|(bmp))/gi)) { var er_imagens = new RegExp("\\.\\/inc\\/show_embedded_attach.php\\?msg_folder=[\\w/]+\\&msg_num=[0-9]+\\&msg_part="+anexos[i]['pid']); var Result_imagens = er_imagens.exec(retorno['body']); retorno['body'] = retorno['body'].replace(Result_imagens,anexos[i]['url']); if(thumbs && thumbs[i]){ er_imagens = new RegExp("\\.\\/inc\\/show_thumbs.php\\?file_type=image\\/[\\w]+\\&msg_num=[0-9]+\\&msg_folder=[\\w/%]+\\&msg_part="+anexos[i]['pid']); Result_imagens = er_imagens.exec(thumbs[i]); thumbs[i] = thumbs[i].replace(Result_imagens,"'"+anexos[i]['url']+"'"); er_imagens = new RegExp("\\.\\/inc\\/show_img.php\\?msg_num=[0-9]+\\&msg_folder=[\\w/%]+\\&msg_part="+anexos[i]['pid']); Result_imagens = er_imagens.exec(thumbs[i]); thumbs[i] = thumbs[i].replace(Result_imagens,anexos[i]['url']); thumbs[i] = thumbs[i].replace(/]+>/gi, ''); } local_messages.prototype.get_local_range_msgs = function(folder,msg_range_begin,emails_per_page,sort,sort_reverse,search,preview_msg_subject,preview_msg_tip) { this.init_local_messages(); var retorno = new Array(); msg_range_begin--; mail_filter = " "; if(search=="FLAGGED") { mail_filter = "and (header like '%\"Flagged\";s:1:\"F%' or header like '%\"Importance\";s:5:\"High%') "; } if(search=="UNSEEN") { mail_filter = "and unseen = 1 "; } if(search=="SEEN") { mail_filter = "and unseen = 0 "; } if (search=="ANSWERED") { mail_filter = "and header like '%\"Answered\";s:1:\"A%' "; } sql = 'select mail.rowid as rowid,mail.header as header,mail.size as size,' + 'mail.timestamp as timestamp,mail.unseen as unseen,mail.body as body, mail.mail as mail, ' + 'case when lower(mail.ffrom) like ? then ' + 'case when ltrim(ltrim(substr(UPPER(fto),7,length(fto)),\':\'),\'"\') like \'5:%\' then ' + 'substr(ltrim(ltrim(substr(UPPER(fto),7,length(fto)),\':\'),\'"\'),17) ' + 'else ' + 'ltrim(ltrim(substr(UPPER(fto),7,length(fto)),\':\'),\'"\') ' + 'end ' + 'else ' + 'case when ltrim(ltrim(substr(UPPER(ffrom),21,length(ffrom)),\':\'),\'"\') like \'5:%\' then ' + 'substr(ltrim(ltrim(substr(UPPER(ffrom),21,length(ffrom)),\':\'),\'"\'),17) ' + 'else ' + 'ltrim(ltrim(substr(UPPER(ffrom),21,length(ffrom)),\':\'),\'"\') ' + 'end ' + 'end as order_from,mail.subject from mail inner join folder on mail.id_folder=folder.rowid where mail.uid_usuario=? and folder.folder=? ' + mail_filter + ' order by '; if(sort == 'SORTFROM') { sql += 'order_from '; } if(sort == 'SORTARRIVAL') { sql += 'timestamp '; } if(sort == 'SORTSIZE') { sql += 'size '; } if(sort == 'SORTSUBJECT') { sql += 'UPPER(subject) '; } sql+= sort_reverse==0?"ASC ":"DESC "; sql +='limit ?,? '; var rs = this.dbGears.execute(sql,['%'+Element("user_email").value+'%',account_id,folder,msg_range_begin,emails_per_page]); var cont = 0; var rs3 = this.dbGears.execute('select count(*) from mail inner join folder on mail.id_folder=folder.rowid where mail.uid_usuario=? and folder.folder=?'+mail_filter,[account_id,folder]); while (rs.isValidRow()) { //var email = rs.field(1); var head = rs.field(1); var codigoMail = rs.field(0); var mail = rs.field(6); var msg_body = rs.field(5);//recebe o conteudo da coluna "body" do banco de dados; var rs2 = this.dbGears.execute('select count(*) from anexo where id_mail = '+codigoMail); var head_unserialized = connector.unserialize(head); var mail_unserialized = connector.unserialize(mail); head_unserialized.Size = rs.field(2); if(rs.field(4)==1) head_unserialized.Unseen = 'U'; head_unserialized.subject=(head_unserialized.subject==null)?"":head_unserialized.subject; //var email_unserialized = connector.unserialize(email); retorno[cont] = head_unserialized; retorno[cont]['msg_number'] = codigoMail; retorno[cont]['msg_day'] = mail_unserialized.msg_day; retorno[cont]['msg_hour'] = mail_unserialized.msg_hour; //declaracao do array() para receber o body de cada mensagem encontrada na busca sql realizada; retorno[cont]['msg_sample'] = new Array(); if( (preview_msg_subject == 0) && (preview_msg_tip == 0) ) { retorno[cont]['msg_sample']['body'] = ""; } else { msg_body += ">"; msg_body=this.strip_tags(msg_body); msg_body=msg_body.replace(/\ /ig," "); retorno[cont]['msg_sample']['body'] = " - " + msg_body.substr(2,msg_body.length-1); } cont++; rs.next(); } retorno['num_msgs'] = rs3.field(0); rs3.close(); rs.close(); if(cont>0) rs2.close(); this.finalize(); return retorno; } local_messages.prototype.get_url_anexo = function(msg_number,pid) { this.init_local_messages(); var matches = ''; if(matches = this.parse_id_mail(msg_number)) { msg_number = matches[1]; } var retorno; var rs = this.dbGears.execute("select url from anexo where id_mail="+msg_number+" and pid = '"+pid+"'"); retorno = rs.field(0) this.finalize(); return retorno; } local_messages.prototype.getInputFileFromAnexo = function (element,url) { this.init_local_messages(); fileSubmitter = this.store.createFileSubmitter(); fileSubmitter.setFileInputElement(element,url); this.finalize(); } local_messages.prototype.finalize = function() { this.dbGears.close(); this.dbGears = null; } local_messages.prototype.delete_msgs = function(msgs_number,border_ID) { this.init_local_messages(); var rs = this.dbGears.execute("select url from anexo where id_mail in ("+msgs_number+")"); while(rs.isValidRow()) { this.store.remove(rs.field(0)); rs.next(); } this.dbGears.execute("delete from anexo where id_mail in ("+msgs_number+")"); this.dbGears.execute("delete from mail where rowid in ("+msgs_number+")"); this.finalize(); if (msgs_number.length == 1) write_msg(get_lang("The message was deleted.")); else write_msg(get_lang("The messages were deleted.")); mail_msg = Element("tbody_box"); try { msgs_exploded = msgs_number.split(","); }catch(error) { msgs_exploded = new Array(); msgs_exploded[0] = msgs_number; } var msg_to_delete; for (var i=0; i"); searchKey = new Array(); searchKey.push("SUBJECT"); searchKey.push(tmp[1]); friendly_filters.push(searchKey); searchKey = new Array(); searchKey.push("BODY"); searchKey.push(tmp[1]); friendly_filters.push(searchKey); searchKey = new Array(); searchKey.push("FROM"); searchKey.push(tmp[1]); friendly_filters.push(searchKey); searchKey = new Array(); searchKey.push("TO"); searchKey.push(tmp[1]); friendly_filters.push(searchKey); searchKey = new Array(); searchKey.push("CC"); searchKey.push(tmp[1]); friendly_filters.push(searchKey); } else { for (var i=0; i")); } } } var sql = "select mail.header,folder.folder,mail.rowid,size from mail inner join folder on mail.id_folder=folder.rowid where mail.uid_usuario="+account_id + " and folder.folder in ("; for(var fnum in folders) { sql+="'"+folders[fnum]+"'"; if(fnum= 1){ return tmp + " kb"; }else{ return size + " b"; } } local_messages.prototype.aux_convert_filter_field = function(filter,date) { var dateObj; if (typeof date != 'undefined'){ dateObj=new Date(date[2],date[1]-1,date[0]); } if((filter=="SUBJECT ") || (filter=="SUBJECT")) return "subject"; else if((filter=="BODY ") || (filter=="BODY")) return "body"; else if((filter=="FROM ") || (filter=="FROM")) return "ffrom"; else if((filter=="TO ") || (filter=="TO")) return "fto"; else if((filter=="CC ") || (filter=="CC")) return "cc"; else if (filter.replace(/^\s+|\s+$/g,"") == "SINCE"){ dateObj.setHours(0, 0, 0, 0); return ">= " + dateObj.getTime().toString(10).substr(0, 10); } else if (filter.replace(/^\s+|\s+$/g,"") == "BEFORE"){ dateObj.setHours(23, 59, 59, 999); return "<= " + dateObj.getTime().toString(10).substr(0, 10); } else if (filter.replace(/^\s+|\s+$/g,"") == "ON"){ dateObj.setHours(0, 0, 0, 0); var ts1 = dateObj.getTime().toString(10).substr(0, 10); dateObj.setHours(23, 59, 59, 999); var ts2 = dateObj.getTime().toString(10).substr(0, 10); return ">= " + ts1 + ") and (timestamp <= " + ts2; } else if (filter.replace(/^\s+|\s+$/g,"") == "FLAGGED") return "flagged = 1"; else if (filter.replace(/^\s+|\s+$/g,"") == "UNFLAGGED") return "flagged = 0"; else if (filter.replace(/^\s+|\s+$/g,"") == "UNSEEN") return "unseen = 1"; else if (filter.replace(/^\s+|\s+$/g,"") == "SEEN") return "unseen = 0"; else if (filter.replace(/^\s+|\s+$/g,"") == "ANSWERED") return "answered = 1"; else if (filter.replace(/^\s+|\s+$/g,"") == "UNANSWERED") return "answered = 0"; else if (filter.replace(/^\s+|\s+$/g,"") == "RECENT") return "recent = 1"; else if (filter.replace(/^\s+|\s+$/g,"") == "OLD") return "recent = 0"; } local_messages.prototype.has_local_mails = function() { this.init_local_messages(); var rs = this.dbGears.execute("select rowid from folder limit 0,1"); var retorno; if(rs.isValidRow()) retorno = true; else retorno = false; this.finalize(); return retorno; } //Por Bruno Costa(bruno.vieira-costa@serpro.gov.br - Simple AJAX function used to get the RFC822 email source. local_messages.prototype.get_src = function(url){ AJAX = false; if (window.XMLHttpRequest) { // Mozilla, Safari,... AJAX = new XMLHttpRequest(); if (AJAX.overrideMimeType) { AJAX.overrideMimeType('text/xml'); } } else if (window.ActiveXObject) { // IE try { AJAX = new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { try { AJAX = new ActiveXObject("Microsoft.XMLHTTP"); } catch (e) {} } } if (!AJAX) { alert('ERRO :(Seu navegador não suporta a aplicação usada neste site'); return false; } AJAX.onreadystatechange = function() { if (AJAX.readyState == 4) { AJAX.src=AJAX.responseText; if (AJAX.status == 200) { return AJAX.responseText; } else { return false; } } } AJAX.open('get', url, false); AJAX.send(null); return AJAX.responseText; }; //Por Bruno Costa(bruno.vieira-costa@serpro.gov.br - Dessarquiva msgs locais pegando o codigo fonte das mesmas e mandando via POST para o servidor //para que elas sejam inseridas no imap pela fun��o imap_functions.unarchive_mail. local_messages.prototype.unarchive_msgs = function (folder,new_folder,msgs_number){ if(!new_folder) new_folder='INBOX'; this.init_local_messages(); // alert(folder+new_folder+msgs_number); var handler_unarchive = function(data) { if(data.error == '') write_msg(get_lang('All messages are successfully unarchived')); else alert(data.error); } if(currentTab.toString().indexOf("_r") != -1){ msgs_number = currentTab.toString().substr(0,currentTab.toString().indexOf("_r")); } if(msgs_number =='selected' || !msgs_number) { msgs_number = get_selected_messages() if (!msgs_number){ write_msg(get_lang('No selected message.')); return; } var rs = this.dbGears.execute("select mail,timestamp from mail where rowid in ("+msgs_number+")"); var source=""; var timestamp=""; while(rs.isValidRow()) { mail=connector.unserialize(rs.field(0)); mail.msg_source?source_tmp = escape(mail.msg_source):source_tmp = escape(this.get_src(mail.url_export_file)); // source_tmp=escape(this.get_src(mail.url_export_file)); source+="#@#@#@"+source_tmp; timestamp+="#@#@#@"+rs.field(1); rs.next(); } rs.close(); this.finalize(); } else { var rs = this.dbGears.execute("select mail,timestamp from mail where rowid="+msgs_number); mail=connector.unserialize(rs.field(0)); var source =""; // source = this.get_src(mail.url_export_file); mail.msg_source?source = mail.msg_source:source = this.get_src(mail.url_export_file); timestamp=rs.field(1); rs.close(); this.finalize(); } params="&folder="+new_folder+"&source="+source+"×tamp="+timestamp; cExecute ("$this.imap_functions.unarchive_mail&", handler_unarchive, params); } local_messages.prototype.get_msg_date = function (original_id, is_local){ this.init_local_messages(); if (typeof(is_local) == 'undefined') { is_local = false; } var rs; if (is_local) { rs = this.dbGears.execute("select mail from mail where rowid="+original_id); } else { rs = this.dbGears.execute("select mail from mail where original_id="+original_id); } var tmp = connector.unserialize(rs.field(0)); var ret = new Array(); ret.fulldate = tmp.fulldate.substr(0,16); ret.smalldate = tmp.msg_day; ret.msg_day = tmp.msg_day; ret.msg_hour = tmp.msg_day; rs.close(); this.finalize(); return ret; } local_messages.prototype.download_all_local_attachments = function(folder,id){ this.init_local_messages(); var rs = this.dbGears.execute("select mail from mail where rowid="+id); var tmp = connector.unserialize(rs.field(0)); rs.close(); this.finalize(); tmp.msg_source?source = tmp.msg_source:source = this.get_src(tmp.url_export_file); //source = this.get_src(tmp.url_export_file); source = escape(source); var handler_source = function(data){ download_attachments(null, null, data, null,null,'anexos.zip'); } cExecute("$this.imap_functions.download_all_local_attachments",handler_source,"source="+source); } /*************************************************************************/ /* Funcao usada para exportar mensagens arquivadas localmente. * Rommel de Brito Cysne (rommel.cysne@serpro.gov.br) * em 22/12/2008. */ local_messages.prototype.local_messages_to_export = function(){ if (openTab.type[currentTab] > 1){ var msgs_to_export_id = currentTab.substring(0,currentTab.length-2,currentTab); }else{ var msgs_to_export_id = get_selected_messages(); } var handler_local_mesgs_to_export = function(data){ download_attachments(null, null, data, null,null,'mensagens.zip'); } if(msgs_to_export_id){ this.init_local_messages(); var l_msg = "t"; var mesgs =""; var subjects =""; var rs = this.dbGears.execute("select mail,subject from mail where rowid in ("+msgs_to_export_id+")"); while(rs.isValidRow()){ mail = connector.unserialize(rs.field(0)); mail.msg_source?src = mail.msg_source:src = this.get_src(mail.url_export_file); subject = rs.field(1); mesgs += src; mesgs += "@@"; subjects += subject; subjects += "@@"; rs.next(); } rs.close(); this.finalize(); mesgs = escape(mesgs); subjects = escape(subjects); params = "subjects="+subjects+"&mesgs="+mesgs+"&l_msg="+l_msg+"&msgs_to_export="+msgs_to_export_id; cExecute ("$this.exporteml.makeAll&", handler_local_mesgs_to_export, params); } return true; } local_messages.prototype.get_all_local_folder_messages= function(folder_name){ var mesgs = new Array(); var subjects = new Array(); var hoje = new Date(); var msgs_to_export = new Array(); var l_msg="t"; this.init_local_messages(); var query = "select mail,subject,mail.rowid from mail inner join folder on (mail.id_folder=folder.rowid) where folder.folder='" + folder_name + "'"; var rs = this.dbGears.execute(" "+query) var handler_local_mesgs_to_export = function(data){ //alert("data - " + data + " - tipo - " + typeof(data)); download_attachments(null, null, data, null,null,'mensagens.zip'); } var j=0; while (rs.isValidRow()){ msgs_to_export[j]=rs.field(2) mail = connector.unserialize(rs.field(0)); mail.msg_source?src = mail.msg_source:src = this.get_src(mail.url_export_file); subject = rs.field(1); mesgs += src; mesgs += "@@"; subjects += subject; subjects += "@@"; rs.next(); j++; } rs.close(); this.finalize(); source = escape(mesgs); subjects = escape(subjects); params = "folder="+folder_name+"&subjects="+subjects+"&mesgs="+source+"&l_msg="+l_msg+"&msgs_to_export="+msgs_to_export; cExecute ("$this.exporteml.makeAll&", handler_local_mesgs_to_export, params); } /*************************************************************************/ /****************************************************************** Offline Part ******************************************************************/ local_messages.prototype.is_offline_installed = function() { this.init_local_messages(); var check = this.localServer.openManagedStore('expresso-offline'); this.finalize(); if(check==null) return false; else return true; } local_messages.prototype.update_offline = function(redirect) { this.init_local_messages(); var managedStore = this.localServer.openManagedStore('expresso-offline'); if(managedStore!=null){ managedStore.oncomplete = function(details){ if(redirect!=null) location.href=redirect; } managedStore.checkForUpdate(); } else if(redirect!=null) { location.href=redirect; } this.finalize(); } local_messages.prototype.uninstall_offline = function() { if (!window.google || !google.gears) { temp = confirm(document.getElementById('lang_gears_redirect').value); if (temp) { expresso_local_messages.installGears(); } return; } this.init_local_messages(); this.localServer.removeManagedStore('expresso-offline'); alert(document.getElementById('lang_offline_uninstalled').value); //this.dbGears.execute('drop table user'); //this.dbGears.execute('drop table queue'); //this.dbGears.execute('drop table attachments_queue'); this.finalize(); } local_messages.prototype.get_folders_to_sync = function() {//Precisa ter visibilidade ao array de linguagens. this.init_local_messages(); var rs = this.dbGears.execute("select id_folder,folder_name from folders_sync where uid_usuario="+account_id); var retorno = new Array(); while(rs.isValidRow()) { temp = new Array(); temp[0] = rs.field(0); if(temp[0]=='INBOX/Drafts' ||temp[0]=='INBOX/Trash' || temp[0]=='INBOX/Sent') { temp[1] = array_lang[rs.field(1).toLowerCase()]; } else { temp[1] = rs.field(1); } retorno.push(temp); rs.next(); } this.finalize(); return retorno; } local_messages.prototype.install_offline = function(urlOffline,urlIcone,uid_usuario,login,pass,redirect) { if (!window.google || !google.gears) { temp = confirm(document.getElementById('lang_gears_redirect').value); if (temp) { expresso_local_messages.installGears(); } return; } if(pass.length>0) { only_spaces = true; for(cont=0;cont