Changeset 3286
- Timestamp:
- 09/24/10 14:55:10 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2.2/expressoMail1_2/js/local_messages.js
r3269 r3286 3 3 */ 4 4 5 function local_messages() { 6 this.dbGears = null; 7 this.localServer = null; 8 this.store = null; 9 } 10 11 function HeaderFlags() 12 { 13 this.Answered = 0; 14 //this.Draft = 0; 15 this.Flagged = 0; 16 this.Recent = 0; 17 } 18 19 HeaderFlags.prototype.getAnswered = function() 20 { 21 return this.Answered; 22 } 23 24 HeaderFlags.prototype.setAnswered = function(answered) 25 { 26 this.Answered = answered; 27 } 28 29 //HeaderFlags.prototype.getDraft = function() 30 //{ 31 // return this.Draft; 32 //} 33 34 HeaderFlags.prototype.setDraft = function(draft) 35 { 36 this.Draft = draft; 37 } 38 39 HeaderFlags.prototype.getFlagged = function() 40 { 41 return this.Flagged; 42 } 43 44 HeaderFlags.prototype.setFlagged = function(flagged) 45 { 46 this.Flagged = flagged; 47 } 48 49 HeaderFlags.prototype.getRecent = function() 50 { 51 return this.Recent; 52 } 53 54 HeaderFlags.prototype.setRecent = function(recent) 55 { 56 this.Recent = recent; 57 } 58 59 function FlagsParser(headerObj) 60 { 61 this.Header = headerObj; 62 } 63 64 FlagsParser.prototype.parse = function() 65 { 66 var tmp = null; 67 if (typeof this.Header == 'string') 68 { 69 tmp = connector.unserialize(this.Header); 70 } 71 else 72 { 73 tmp = this.Header; 74 } 75 76 flags = new HeaderFlags(); 77 78 if (tmp.Answered && tmp.Answered.match(/^A$/)) 79 { 80 flags.setAnswered(1); 81 //if (tmp.Draft && tmp.Draft.match(/^X$/)) 82 //{ 83 // flags.setDraft(1); 84 //} 85 } 86 87 if (tmp.Flagged && tmp.Flagged.match(/^F$/)){ 88 flags.setFlagged(1); 89 } 90 91 if (tmp.Forwarded && tmp.Forwarded.match(/^F$/)){ 92 flags.setAnswered(1); 93 //flags.setDraft(1); 94 } 95 96 if (tmp.Recent && tmp.Recent.match(/^R$/)){ 97 flags.setRecent(1); 98 } 99 100 return flags; 101 102 } 5 function local_messages() { 6 this.dbGears = null; 7 this.localServer = null; 8 this.store = null; 9 } 10 11 function charOrdA (a, b){ 12 a = a[0].toLowerCase(); 13 b = b[0].toLowerCase(); 14 if (a>b) return 1; 15 if (a <b) return -1; 16 return 0; 17 } 18 function charOrdD(a, b){ 19 a = a[0].toLowerCase(); 20 b = b[0].toLowerCase(); 21 if (a<b) return 1; 22 if (a>b) return -1; 23 return 0; 24 } 25 26 27 function HeaderFlags() 28 { 29 this.Answered = 0; 30 //this.Draft = 0; 31 this.Flagged = 0; 32 this.Recent = 0; 33 } 34 35 HeaderFlags.prototype.getAnswered = function() 36 { 37 return this.Answered; 38 } 39 40 HeaderFlags.prototype.setAnswered = function(answered) 41 { 42 this.Answered = answered; 43 } 44 45 //HeaderFlags.prototype.getDraft = function() 46 //{ 47 // return this.Draft; 48 //} 49 50 HeaderFlags.prototype.setDraft = function(draft) 51 { 52 this.Draft = draft; 53 } 54 55 HeaderFlags.prototype.getFlagged = function() 56 { 57 return this.Flagged; 58 } 59 60 HeaderFlags.prototype.setFlagged = function(flagged) 61 { 62 this.Flagged = flagged; 63 } 64 65 HeaderFlags.prototype.getRecent = function() 66 { 67 return this.Recent; 68 } 69 70 HeaderFlags.prototype.setRecent = function(recent) 71 { 72 this.Recent = recent; 73 } 74 75 function FlagsParser(headerObj) 76 { 77 this.Header = headerObj; 78 } 79 80 FlagsParser.prototype.parse = function() 81 { 82 var tmp = null; 83 if (typeof this.Header == 'string') 84 { 85 tmp = connector.unserialize(this.Header); 86 } 87 else 88 { 89 tmp = this.Header; 90 } 91 92 flags = new HeaderFlags(); 93 94 if (tmp.Answered && tmp.Answered.match(/^A$/)) 95 { 96 flags.setAnswered(1); 97 //if (tmp.Draft && tmp.Draft.match(/^X$/)) 98 //{ 99 // flags.setDraft(1); 100 //} 101 } 102 103 if (tmp.Flagged && tmp.Flagged.match(/^F$/)){ 104 flags.setFlagged(1); 105 } 106 107 if (tmp.Forwarded && tmp.Forwarded.match(/^F$/)){ 108 flags.setAnswered(1); 109 //flags.setDraft(1); 110 } 111 112 if (tmp.Recent && tmp.Recent.match(/^R$/)){ 113 flags.setRecent(1); 114 } 115 116 return flags; 117 118 } 103 119 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 }143 120 local_messages.prototype.installGears = function (){ 121 temp = confirm(get_lang("To use local messages you have to install google gears. Would you like to install it now?")); 122 if (temp && typeof(preferences.googlegears_url) != 'undefined'){ 123 if (is_ie) 124 location.href = preferences.googlegears_url + "/gears.exe"; 125 else 126 location.href = preferences.googlegears_url + "/gears.xpi"; 127 return false; 128 } 129 if (temp) { 130 location.href = "http://gears.google.com/?action=install&message="+ 131 get_lang("To use local messages, install Google Gears")+"&return=" + document.location.href; 132 } 133 else return false; 134 } 135 136 local_messages.prototype.create_objects = function() { 137 if(window.google){ 138 if (this.dbGears == null) 139 this.dbGears = google.gears.factory.create('beta.database'); 140 if(this.localServer == null) 141 this.localServer = google.gears.factory.create('beta.localserver'); 142 if(this.store == null) 143 this.store = this.localServer.createStore('test-store'); 144 } 145 } 146 147 local_messages.prototype.init_local_messages = function(){ //starts only database operations 148 149 if(this.dbGears==null || this.localServer==null || this.store == null) 150 this.create_objects(); 151 152 var db_in_other_use = true; 153 var start_trying = new Date().getTime(); 154 while (db_in_other_use) { 155 try { 156 this.dbGears.open('database-test'); 157 db_in_other_use = false; 158 } 159 catch (ex) { 144 160 if(new Date.getTime()-start_trying>10000) { //too much time trying, throw an exception 145 161 throw ex; 146 147 162 } 163 } 148 164 } 149 165 150 // this.dbGears.open('database-test');151 152 153 ' (mail blob,original_id int,original_folder text,header blob,timestamp int,uid_usuario int,unseen int,id_folder int,' +154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 166 // this.dbGears.open('database-test'); 167 this.dbGears.execute('create table if not exists folder (folder text,uid_usuario int,unique(folder,uid_usuario))'); 168 this.dbGears.execute('create table if not exists mail' + 169 ' (mail blob,original_id int,original_folder text,header blob,timestamp int,uid_usuario int,unseen int,id_folder int,' + 170 ' ffrom text, subject text, fto text, cc text, body text, size int,unique (original_id,original_folder,uid_usuario))'); 171 this.dbGears.execute('create table if not exists anexo' + 172 ' (id_mail int,nome_anexo text,url text,pid int)'); 173 this.dbGears.execute('create table if not exists folders_sync' + 174 ' (id_folder text,folder_name text,uid_usuario int)'); 175 this.dbGears.execute('create table if not exists msgs_to_remove (id_msg int,folder text,uid_usuario int)'); 176 this.dbGears.execute('create index if not exists idx_user3 on mail (id_folder,uid_usuario,timestamp)'); 177 178 //some people that used old version of local messages could not have the size column. If it's the first version 179 //with local messages you're using in expresso, this part of code can be removed 180 try { 181 this.dbGears.execute('alter table mail add column size int'); 182 }catch(Exception) { 183 184 } 185 var rs = this.dbGears.execute('select rowid,header from mail where size is null'); 186 while(rs.isValidRow()) { 187 var temp = connector.unserialize(rs.field(1)); 188 189 this.dbGears.execute('update mail set size='+temp.Size+' where rowid='+rs.field(0)); 190 rs.next(); 191 } 192 //end of temporary code 193 194 try { 195 this.dbGears.execute('begin transaction'); 196 this.dbGears.execute('alter table mail add column answered int'); 197 //this.dbGears.execute('alter table mail add column draft int'); 198 this.dbGears.execute('alter table mail add column flagged int'); 199 this.dbGears.execute('alter table mail add column recent int'); 200 //this.dbGears.execute('commit transaction'); 201 //transaction_ended = true; 202 //if (transaction_ended){ 203 rs = null; 204 rs = this.dbGears.execute('select rowid,header from mail'); 205 206 // Popular os valores das novas colunas. 207 var tmp = null; 208 //this.dbGears.execute('begin transaction'); 209 while(rs.isValidRow()) { 210 //tmp = connector.unserialize(rs.field(1)); 211 parser = new FlagsParser(rs.field(1)); 212 flags = parser.parse(); 213 214 this.dbGears.execute('update mail set answered='+flags.getAnswered()+ 215 ',flagged='+flags.getFlagged()+',recent='+flags.getRecent()+ 216 //',draft='+flags.getDraft()+' where rowid='+rs.field(0)); 217 ' where rowid='+rs.field(0)); 218 219 rs.next(); 220 } 221 this.dbGears.execute('commit transaction'); 222 223 //tmp = null; 224 225 }catch(Exception) { 226 this.dbGears.execute('rollback transaction'); 227 } 228 229 } 230 231 local_messages.prototype.drop_tables = function() { 232 this.init_local_messages(); 233 var rs = this.dbGears.execute('select url from anexo'); 234 while(rs.isValidRow()) { 235 this.store.remove(rs.field(0)); 236 rs.next(); 237 } 238 this.dbGears.execute('drop table folder'); 239 this.dbGears.execute('drop table mail'); 240 this.dbGears.execute('drop table anexo'); 241 this.finalize(); 242 } 243 244 local_messages.prototype.insert_mail = function(msg_info,msg_header,anexos,folder) { 245 try { 246 this.init_local_messages(); 247 var unseen = 0; 248 var login = msg_info.login; 249 var original_id = msg_info.msg_number; 250 var original_folder = msg_info.msg_folder; 251 252 //This fields needs to be separeted to search. 253 var from = connector.serialize(msg_info.from); 254 var subject = msg_info.subject; 255 var body = msg_info.body; 256 var to = connector.serialize(msg_info.toaddress2); 257 var cc = connector.serialize(msg_info.cc); 258 var size = msg_header.Size; 259 260 //do not duplicate this information 261 msg_info.from = null; 262 msg_info.subject = null; 263 msg_info.body = null; 264 msg_info.to = null; 265 msg_info.cc = null; 266 msg_header.Size=null; 267 //If the mail was archieved in the same date the user received it, the date cames with the time. 268 //here I solved it 269 if(msg_header.udate.indexOf(":")!=-1) { 270 msg_header.udate = msg_header.aux_date; 271 } 272 273 /** 258 274 * The importance attribute can be empty, and javascript consider as null causing nullpointer. 259 275 */ 260 261 262 263 msg_header.aux_date = null;264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 276 if((msg_header.Importance == null) || (msg_header.Importance == "")) 277 msg_header.Importance = "Normal"; 278 279 msg_header.aux_date = null; 280 281 var mail = connector.serialize(msg_info); 282 var header = connector.serialize(msg_header); 283 284 var timestamp = msg_info.timestamp; 285 var id_folder; 286 287 if((folder==null) || (folder=="local_root")) 288 folder = "Inbox"; 289 else 290 folder = folder.substr(6);//take off the word "local_" 291 292 var rs = this.dbGears.execute("select rowid from folder where folder=? and uid_usuario=?",[folder,account_id]); 293 if(rs.isValidRow()) 294 id_folder=rs.field(0); 295 else { 296 this.dbGears.execute("insert into folder (folder,uid_usuario) values (?,?)",["Inbox",account_id]); 297 id_folder = this.dbGears.lastInsertRowId; 298 } 299 300 if(msg_info.Unseen=="U") 301 unseen = 1; 302 303 //parse header 304 parser = new FlagsParser(msg_header); 305 flags = parser.parse(); 306 307 //insere o e-mail 308 //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]); 309 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()]); 310 var call_back = function() { 311 } 312 this.store.capture(msg_info.url_export_file,call_back); 313 var id_mail = this.dbGears.lastInsertRowId; 314 315 this.insert_attachments(id_mail,anexos); 316 this.finalize(); 317 return true; 318 } catch (error) { 319 this.finalize(); 320 return false; 321 } 322 323 324 } 325 326 /** 311 327 * check if ID is no from main tab, if it's from main returns false, else 312 328 * returns an array with all string in position 0, the mail id in position 1 … … 314 330 * @param {Object} id_mail 315 331 */ 316 local_messages.prototype.parse_id_mail = function(id_mail) { 317 if (this.isInt(id_mail)) 318 return false; 319 320 var matches = id_mail.match(/(.+)(_[a-zA-Z0-9]+)/); 321 return matches; 322 } 323 324 local_messages.prototype.isInt = function(x) { 325 var y=parseInt(x); 326 if (isNaN(y)) return false; 327 return x==y && x.toString()==y.toString(); 328 } 329 330 local_messages.prototype.get_local_mail = function(id_mail) { 331 this.init_local_messages(); 332 333 var plus_id = ''; 334 var matches = ''; 335 if(matches = this.parse_id_mail(id_mail)) { //Mails coming from other tab. 336 id_mail = matches[1]; 337 plus_id = matches[2]; 332 local_messages.prototype.parse_id_mail = function(id_mail) { 333 if (this.isInt(id_mail)) 334 return false; 335 336 var matches = id_mail.match(/(.+)(_[a-zA-Z0-9]+)/); 337 return matches; 338 } 339 340 local_messages.prototype.isInt = function(x) { 341 var y=parseInt(x); 342 if (isNaN(y)) return false; 343 return x==y && x.toString()==y.toString(); 344 } 345 346 local_messages.prototype.get_local_mail = function(id_mail) { 347 this.init_local_messages(); 348 349 var plus_id = ''; 350 var matches = ''; 351 if(matches = this.parse_id_mail(id_mail)) { //Mails coming from other tab. 352 id_mail = matches[1]; 353 plus_id = matches[2]; 354 } 355 356 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); 357 var retorno = null; 358 if(rs.isValidRow()) { 359 retorno = rs.field(1); 360 } 361 retorno = connector.unserialize(retorno); 362 363 //alert('tipo retorno.source: ' + typeof(retorno.source)); 364 365 if (typeof(retorno.source) == 'string') 366 { 367 retorno.msg_number=rs.field(0)+plus_id; 368 retorno.original_ID=rs.field(8); 369 retorno.msg_folder=rs.field(7); 370 371 //alert('tipo retorno: '+typeof(retorno)) 372 //show_msg(retorno); 373 } 374 else 375 { 376 retorno['from'] = connector.unserialize(rs.field(2)); 377 retorno['subject'] = rs.field(3); 378 retorno['body'] = rs.field(4); 379 //Codigo que as imagens embutidas em emails (com multipart/related ou multipart/mixed) sejam corretamente mostradas em emails arquivados. Os links do 380 //tipo "./inc/show_embedded_attach.php?msg_folder=[folder]&msg_num=[msg_num]&msg_part=[part]" 381 //são substituidos pelos links dos anexos capturados pelo gears. 382 383 var thumbs= retorno.thumbs; 384 var anexos= retorno.array_attach; 385 for (i in anexos) 386 { 387 nomeArquivo = anexos[i]['name'].substring(0,anexos[i]['name'].length - 4); 388 if(anexos[i]['name'] && anexos[i]['name'].match(/((jpg)|(jpeg)|(png)|(gif)|(bmp))/gi)) 389 { 390 var er_imagens = new RegExp("\\.\\/inc\\/show_embedded_attach.php\\?msg_folder=[\\w/]+\\&msg_num=[0-9]+\\&msg_part="+anexos[i]['pid']); 391 var Result_imagens = er_imagens.exec(retorno['body']); 392 retorno['body'] = retorno['body'].replace(Result_imagens,anexos[i]['url']); 393 if(thumbs && thumbs[i]){ 394 er_imagens = new RegExp("\\.\\/inc\\/show_thumbs.php\\?file_type=image\\/[\\w]+\\&msg_num=[0-9]+\\&msg_folder=[\\w/%]+\\&msg_part="+anexos[i]['pid']); 395 Result_imagens = er_imagens.exec(thumbs[i]); 396 thumbs[i] = thumbs[i].replace(Result_imagens,"'"+anexos[i]['url']+"'"); 397 er_imagens = new RegExp("\\.\\/inc\\/show_img.php\\?msg_num=[0-9]+\\&msg_folder=[\\w/%]+\\&msg_part="+anexos[i]['pid']); 398 Result_imagens = er_imagens.exec(thumbs[i]); 399 thumbs[i] = thumbs[i].replace(Result_imagens,"'"+anexos[i]['url']+"'"); 400 thumbs[i] = thumbs[i].replace(/<IMG/i,'<img width="120"'); 338 401 } 339 340 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); 341 var retorno = null; 342 if(rs.isValidRow()) { 343 retorno = rs.field(1); 402 } 403 } 404 405 retorno['to'] = connector.unserialize(rs.field(5)); 406 retorno['cc'] = connector.unserialize(rs.field(6)); 407 408 retorno['local_message'] = true; 409 retorno['msg_folder'] = "local_"+rs.field(7); //Now it's a local folder 410 retorno['msg_number'] = rs.field(0)+plus_id; //the message number is the rowid 411 412 } 413 414 rs.close(); 415 this.finalize(); 416 return retorno; 417 } 418 419 local_messages.prototype.insert_attachments = function(id_msg,anexos) { 420 //insert_mail already close and open gears. 421 for (var i = 0; i < anexos.length; i++) { 422 this.dbGears.execute("insert into anexo (id_mail,nome_anexo,url,pid) values (?,?,?,?)", [id_msg, anexos[i]['name'],anexos[i]['url'],anexos[i]['pid']]); 423 this.capt_url(anexos[i]['url']); 424 } 425 } 426 427 local_messages.prototype.capt_url = function (url) { 428 //insert_mail already close and open gears. 429 var call_back = function(url,success,captureId) { 430 //alert("Capturado: " + url); 431 } 432 //alert(url); 433 this.store.capture(url,call_back); 434 } 435 436 local_messages.prototype.strip_tags = function (str) { 437 return str.replace(/<\/?[^>]+>/gi, ''); 438 } 439 440 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) { 441 442 this.init_local_messages(); 443 var retorno = new Array(); 444 msg_range_begin--; 445 446 filter = " "; 447 if(search=="FLAGGED") { 448 filter = "and (header like '%\"Flagged\";s:1:\"F%' or header like '%\"Importance\";s:5:\"High%') "; 449 } 450 if(search=="UNSEEN") { 451 filter = "and unseen = 1 "; 452 } 453 if(search=="SEEN") { 454 filter = "and unseen = 0 "; 455 } 456 if (search=="ANSWERED") { 457 filter = "and header like '%\"Answered\";s:1:\"A%' "; 458 } 459 460 sql = 'select mail.rowid as rowid,mail.header as header,mail.size as size,mail.timestamp as timestamp,mail.unseen as unseen,substr(mail.body,1,300) as body,case when lower(mail.ffrom) like ? then ltrim(ltrim(substr(UPPER(ffrom),21,length(ffrom)),\':\'),\'"\') else ltrim(ltrim(substr(UPPER(fto),7,length(fto)),\':\'),\'"\') end as order_from,mail.subject from mail inner join folder on mail.id_folder=folder.rowid where mail.uid_usuario=? and folder.folder=? order by ' 461 462 if(sort == 'SORTFROM') { 463 sql += 'order_from '; 464 } 465 if(sort == 'SORTARRIVAL') { 466 sql += 'timestamp '; 467 } 468 if(sort == 'SORTSIZE') { 469 sql += 'size '; 470 } 471 if(sort == 'SORTSUBJECT') { 472 sql += 'UPPER(subject) '; 473 } 474 475 476 sql+= sort_reverse==0?"ASC ":"DESC "; 477 sql +='limit ?,? '; 478 479 480 var rs = this.dbGears.execute(sql,['%'+Element("user_email").value+'%',account_id,folder,msg_range_begin,emails_per_page]); 481 var cont = 0; 482 483 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=?'+filter,[account_id,folder]); 484 485 while (rs.isValidRow()) { 486 //var email = rs.field(1); 487 var head = rs.field(1); 488 var codigoMail = rs.field(0); 489 490 var msg_body = rs.field(5);//recebe o conteudo da coluna "body" do banco de dados; 491 492 var rs2 = this.dbGears.execute('select count(*) from anexo where id_mail = '+codigoMail); 493 var head_unserialized = connector.unserialize(head); 494 head_unserialized.Size = rs.field(2); 495 if(rs.field(4)==1) 496 head_unserialized.Unseen = 'U'; 497 498 499 head_unserialized.subject=(head_unserialized.subject==null)?"":head_unserialized.subject; 500 501 //var email_unserialized = connector.unserialize(email); 502 retorno[cont] = head_unserialized; 503 retorno[cont]['msg_number'] = codigoMail; 504 505 //declaracao do array() para receber o body de cada mensagem encontrada na busca sql realizada; 506 507 retorno[cont]['msg_sample'] = new Array(); 508 509 if( (preview_msg_subject == 0) && (preview_msg_tip == 0) ) 510 { 511 retorno[cont]['msg_sample']['body'] = ""; 512 } 513 else 514 { 515 msg_body += ">"; 516 msg_body=this.strip_tags(msg_body); 517 msg_body=msg_body.replace(/\ /ig," "); 518 retorno[cont]['msg_sample']['body'] = " - " + msg_body.substr(2,msg_body.length-1); 519 } 520 521 cont++; 522 rs.next(); 523 } 524 retorno['num_msgs'] = rs3.field(0); 525 rs3.close(); 526 rs.close(); 527 if(cont>0) 528 rs2.close(); 529 this.finalize(); 530 return retorno; 531 } 532 533 local_messages.prototype.get_url_anexo = function(msg_number,pid) { 534 this.init_local_messages(); 535 var matches = ''; 536 if(matches = this.parse_id_mail(msg_number)) { 537 msg_number = matches[1]; 538 } 539 540 var retorno; 541 var rs = this.dbGears.execute("select url from anexo where id_mail="+msg_number+" and pid = '"+pid+"'"); 542 retorno = rs.field(0) 543 this.finalize(); 544 545 return retorno; 546 } 547 548 local_messages.prototype.getInputFileFromAnexo = function (element,url) { 549 this.init_local_messages(); 550 fileSubmitter = this.store.createFileSubmitter(); 551 fileSubmitter.setFileInputElement(element,url); 552 this.finalize(); 553 } 554 555 local_messages.prototype.finalize = function() { 556 this.dbGears.close(); 557 this.dbGears = null; 558 } 559 560 local_messages.prototype.delete_msgs = function(msgs_number,border_ID) { 561 this.init_local_messages(); 562 var rs = this.dbGears.execute("select url from anexo where id_mail in ("+msgs_number+")"); 563 while(rs.isValidRow()) { 564 this.store.remove(rs.field(0)); 565 rs.next(); 566 } 567 this.dbGears.execute("delete from anexo where id_mail in ("+msgs_number+")"); 568 this.dbGears.execute("delete from mail where rowid in ("+msgs_number+")"); 569 this.finalize(); 570 if (msgs_number.length == 1) 571 write_msg(get_lang("The message was deleted.")); 572 else 573 write_msg(get_lang("The messages were deleted.")); 574 575 mail_msg = Element("tbody_box"); 576 577 try { 578 msgs_exploded = msgs_number.split(","); 579 }catch(error) { 580 msgs_exploded = new Array(); 581 msgs_exploded[0] = msgs_number; 582 } 583 var msg_to_delete; 584 for (var i=0; i<msgs_exploded.length; i++){ 585 msg_to_delete = Element(msgs_exploded[i]); 586 if (msg_to_delete){ 587 if ( (msg_to_delete.style.backgroundColor != '') && (preferences.use_shortcuts == '1') ) 588 select_msg('null', 'down'); 589 mail_msg.removeChild(msg_to_delete); 590 decrement_folder_unseen(); 591 } 592 } 593 Element('chk_box_select_all_messages').checked = false; 594 if (border_ID != 'null') 595 delete_border(border_ID,'false'); 596 597 } 598 599 local_messages.prototype.get_source_msg = function(id_msg) { 600 this.init_local_messages(); 601 var rs = this.dbGears.execute("select mail from mail where rowid="+id_msg); 602 603 604 mail = connector.unserialize(rs.field(0)); 605 download_local_attachment(mail.url_export_file) 606 607 this.finalize(); 608 } 609 610 611 612 local_messages.prototype.set_messages_flag = function(msgs_number, flag) { 613 this.init_local_messages(); 614 var msgs_to_set; 615 if (msgs_number == 'get_selected_messages') { 616 var msgs_to_set = get_selected_messages(); 617 msgs_to_set= msgs_to_set.split(","); 618 } 619 else { //Just one message 620 msgs_to_set = new Array(); 621 msgs_to_set[0] = msgs_number; 622 } 623 for (var i in msgs_to_set) { 624 625 var matches = '';//Messages comming from other tabs. 626 if(matches = this.parse_id_mail(msgs_to_set[i])) { 627 msgs_to_set[i] = matches[1]; 628 } 629 630 var rs = this.dbGears.execute("select header,unseen from mail where rowid=" + msgs_to_set[i]); 631 header = connector.unserialize(rs.field(0)); 632 unseen = rs.field(1); 633 switch(flag) { 634 case "unseen": 635 set_msg_as_unread(msgs_to_set[i]); 636 header["Unseen"] = "U"; 637 unseen = 1; 638 break; 639 case "flagged": 640 set_msg_as_flagged(msgs_to_set[i]); 641 header["Flagged"] = "F"; 642 break; 643 case "unflagged": 644 if (header["Importance"].indexOf("High") != -1) 645 write_msg(get_lang("At least one of selected message cant be marked as normal")); 646 else { 647 set_msg_as_unflagged(msgs_to_set[i]); 648 header["Flagged"] = "N"; 344 649 } 345 retorno = connector.unserialize(retorno); 346 347 //alert('tipo retorno.source: ' + typeof(retorno.source)); 348 349 if (typeof(retorno.source) == 'string') 350 { 351 retorno.msg_number=rs.field(0)+plus_id; 352 retorno.original_ID=rs.field(8); 353 retorno.msg_folder=rs.field(7); 354 355 //alert('tipo retorno: '+typeof(retorno)) 356 //show_msg(retorno); 357 } 358 else 359 { 360 retorno['from'] = connector.unserialize(rs.field(2)); 361 retorno['subject'] = rs.field(3); 362 retorno['body'] = rs.field(4); 363 //Codigo que as imagens embutidas em emails (com multipart/related ou multipart/mixed) sejam corretamente mostradas em emails arquivados. Os links do 364 //tipo "./inc/show_embedded_attach.php?msg_folder=[folder]&msg_num=[msg_num]&msg_part=[part]" 365 //são substituidos pelos links dos anexos capturados pelo gears. 366 367 var thumbs= retorno.thumbs; 368 var anexos= retorno.array_attach; 369 for (i in anexos) 370 { 371 nomeArquivo = anexos[i]['name'].substring(0,anexos[i]['name'].length - 4); 372 if(anexos[i]['name'] && anexos[i]['name'].match(/((jpg)|(jpeg)|(png)|(gif)|(bmp))/gi)) 373 { 374 var er_imagens = new RegExp("\\.\\/inc\\/show_embedded_attach.php\\?msg_folder=[\\w/]+\\&msg_num=[0-9]+\\&msg_part="+anexos[i]['pid']); 375 var Result_imagens = er_imagens.exec(retorno['body']); 376 retorno['body'] = retorno['body'].replace(Result_imagens,anexos[i]['url']); 377 if(thumbs && thumbs[i]){ 378 er_imagens = new RegExp("\\.\\/inc\\/show_thumbs.php\\?file_type=image\\/[\\w]+\\&msg_num=[0-9]+\\&msg_folder=[\\w/%]+\\&msg_part="+anexos[i]['pid']); 379 Result_imagens = er_imagens.exec(thumbs[i]); 380 thumbs[i] = thumbs[i].replace(Result_imagens,"'"+anexos[i]['url']+"'"); 381 er_imagens = new RegExp("\\.\\/inc\\/show_img.php\\?msg_num=[0-9]+\\&msg_folder=[\\w/%]+\\&msg_part="+anexos[i]['pid']); 382 Result_imagens = er_imagens.exec(thumbs[i]); 383 thumbs[i] = thumbs[i].replace(Result_imagens,"'"+anexos[i]['url']+"'"); 384 thumbs[i] = thumbs[i].replace(/<IMG/i,'<img width="120"'); 385 } 386 } 387 } 388 389 retorno['to'] = connector.unserialize(rs.field(5)); 390 retorno['cc'] = connector.unserialize(rs.field(6)); 391 392 retorno['local_message'] = true; 393 retorno['msg_folder'] = "local_"+rs.field(7); //Now it's a local folder 394 retorno['msg_number'] = rs.field(0)+plus_id; //the message number is the rowid 395 396 } 397 398 rs.close(); 399 this.finalize(); 400 return retorno; 401 } 402 403 local_messages.prototype.insert_attachments = function(id_msg,anexos) { 404 //insert_mail already close and open gears. 405 for (var i = 0; i < anexos.length; i++) { 406 this.dbGears.execute("insert into anexo (id_mail,nome_anexo,url,pid) values (?,?,?,?)", [id_msg, anexos[i]['name'],anexos[i]['url'],anexos[i]['pid']]); 407 this.capt_url(anexos[i]['url']); 408 } 409 } 410 411 local_messages.prototype.capt_url = function (url) { 412 //insert_mail already close and open gears. 413 var call_back = function(url,success,captureId) { 414 //alert("Capturado: " + url); 415 } 416 //alert(url); 417 this.store.capture(url,call_back); 418 } 419 420 local_messages.prototype.strip_tags = function (str) { 421 return str.replace(/<\/?[^>]+>/gi, ''); 422 } 423 424 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) { 425 426 this.init_local_messages(); 427 var retorno = new Array(); 428 msg_range_begin--; 429 430 filter = " "; 431 if(search=="FLAGGED") { 432 filter = "and (header like '%\"Flagged\";s:1:\"F%' or header like '%\"Importance\";s:5:\"High%') "; 433 } 434 if(search=="UNSEEN") { 435 filter = "and unseen = 1 "; 436 } 437 if(search=="SEEN") { 438 filter = "and unseen = 0 "; 439 } 440 if (search=="ANSWERED") { 441 filter = "and header like '%\"Answered\";s:1:\"A%' "; 442 } 443 444 sql = 'select mail.rowid as rowid,mail.header as header,mail.size as size,mail.timestamp as timestamp,mail.unseen as unseen,substr(mail.body,1,300) as body,case when lower(mail.ffrom) like ? then ltrim(ltrim(substr(UPPER(ffrom),21,length(ffrom)),\':\'),\'"\') else ltrim(ltrim(substr(UPPER(fto),7,length(fto)),\':\'),\'"\') end as order_from,mail.subject from mail inner join folder on mail.id_folder=folder.rowid where mail.uid_usuario=? and folder.folder=? order by ' 445 446 if(sort == 'SORTFROM') { 447 sql += 'order_from '; 448 } 449 if(sort == 'SORTARRIVAL') { 450 sql += 'timestamp '; 451 } 452 if(sort == 'SORTSIZE') { 453 sql += 'size '; 454 } 455 if(sort == 'SORTSUBJECT') { 456 sql += 'UPPER(subject) '; 457 } 458 459 460 sql+= sort_reverse==0?"ASC ":"DESC "; 461 sql +='limit ?,? '; 462 463 464 var rs = this.dbGears.execute(sql,['%'+Element("user_email").value+'%',account_id,folder,msg_range_begin,emails_per_page]); 465 var cont = 0; 466 467 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=?'+filter,[account_id,folder]); 468 469 while (rs.isValidRow()) { 470 //var email = rs.field(1); 471 var head = rs.field(1); 472 var codigoMail = rs.field(0); 473 474 var msg_body = rs.field(5);//recebe o conteudo da coluna "body" do banco de dados; 475 476 var rs2 = this.dbGears.execute('select count(*) from anexo where id_mail = '+codigoMail); 477 var head_unserialized = connector.unserialize(head); 478 head_unserialized.Size = rs.field(2); 479 if(rs.field(4)==1) 480 head_unserialized.Unseen = 'U'; 481 482 483 head_unserialized.subject=(head_unserialized.subject==null)?"":head_unserialized.subject; 484 485 //var email_unserialized = connector.unserialize(email); 486 retorno[cont] = head_unserialized; 487 retorno[cont]['msg_number'] = codigoMail; 488 489 //declaracao do array() para receber o body de cada mensagem encontrada na busca sql realizada; 490 491 retorno[cont]['msg_sample'] = new Array(); 492 493 if( (preview_msg_subject == 0) && (preview_msg_tip == 0) ) 494 { 495 retorno[cont]['msg_sample']['body'] = ""; 496 } 497 else 498 { 499 msg_body += ">"; 500 msg_body=this.strip_tags(msg_body); 501 msg_body=msg_body.replace(/\ /ig," "); 502 retorno[cont]['msg_sample']['body'] = " - " + msg_body.substr(2,msg_body.length-1); 503 } 504 505 cont++; 506 rs.next(); 507 } 508 retorno['num_msgs'] = rs3.field(0); 509 rs3.close(); 510 rs.close(); 511 if(cont>0) 512 rs2.close(); 513 this.finalize(); 514 return retorno; 515 } 516 517 local_messages.prototype.get_url_anexo = function(msg_number,pid) { 518 this.init_local_messages(); 519 var matches = ''; 520 if(matches = this.parse_id_mail(msg_number)) { 521 msg_number = matches[1]; 522 } 523 524 var retorno; 525 var rs = this.dbGears.execute("select url from anexo where id_mail="+msg_number+" and pid = '"+pid+"'"); 526 retorno = rs.field(0) 527 this.finalize(); 528 529 return retorno; 530 } 531 532 local_messages.prototype.getInputFileFromAnexo = function (element,url) { 533 this.init_local_messages(); 534 fileSubmitter = this.store.createFileSubmitter(); 535 fileSubmitter.setFileInputElement(element,url); 536 this.finalize(); 537 } 538 539 local_messages.prototype.finalize = function() { 540 this.dbGears.close(); 541 this.dbGears = null; 542 } 543 544 local_messages.prototype.delete_msgs = function(msgs_number,border_ID) { 545 this.init_local_messages(); 546 var rs = this.dbGears.execute("select url from anexo where id_mail in ("+msgs_number+")"); 547 while(rs.isValidRow()) { 548 this.store.remove(rs.field(0)); 549 rs.next(); 550 } 551 this.dbGears.execute("delete from anexo where id_mail in ("+msgs_number+")"); 552 this.dbGears.execute("delete from mail where rowid in ("+msgs_number+")"); 553 this.finalize(); 554 if (msgs_number.length == 1) 555 write_msg(get_lang("The message was deleted.")); 556 else 557 write_msg(get_lang("The messages were deleted.")); 558 559 mail_msg = Element("tbody_box"); 560 561 try { 562 msgs_exploded = msgs_number.split(","); 563 }catch(error) { 564 msgs_exploded = new Array(); 565 msgs_exploded[0] = msgs_number; 566 } 567 var msg_to_delete; 568 for (var i=0; i<msgs_exploded.length; i++){ 569 msg_to_delete = Element(msgs_exploded[i]); 570 if (msg_to_delete){ 571 if ( (msg_to_delete.style.backgroundColor != '') && (preferences.use_shortcuts == '1') ) 572 select_msg('null', 'down'); 573 mail_msg.removeChild(msg_to_delete); 574 decrement_folder_unseen(); 575 } 576 } 577 Element('chk_box_select_all_messages').checked = false; 578 if (border_ID != 'null') 579 delete_border(border_ID,'false'); 580 581 } 582 583 local_messages.prototype.get_source_msg = function(id_msg) { 584 this.init_local_messages(); 585 var rs = this.dbGears.execute("select mail from mail where rowid="+id_msg); 586 587 588 mail = connector.unserialize(rs.field(0)); 589 download_local_attachment(mail.url_export_file) 590 591 this.finalize(); 592 } 593 594 595 596 local_messages.prototype.set_messages_flag = function(msgs_number, flag) { 597 this.init_local_messages(); 598 var msgs_to_set; 599 if (msgs_number == 'get_selected_messages') { 600 var msgs_to_set = get_selected_messages(); 601 msgs_to_set= msgs_to_set.split(","); 602 } 603 else { //Just one message 604 msgs_to_set = new Array(); 605 msgs_to_set[0] = msgs_number; 606 } 607 for (var i in msgs_to_set) { 608 609 var matches = '';//Messages comming from other tabs. 610 if(matches = this.parse_id_mail(msgs_to_set[i])) { 611 msgs_to_set[i] = matches[1]; 612 } 613 614 var rs = this.dbGears.execute("select header,unseen from mail where rowid=" + msgs_to_set[i]); 615 header = connector.unserialize(rs.field(0)); 616 unseen = rs.field(1); 617 switch(flag) { 618 case "unseen": 619 set_msg_as_unread(msgs_to_set[i]); 620 header["Unseen"] = "U"; 621 unseen = 1; 622 break; 623 case "flagged": 624 set_msg_as_flagged(msgs_to_set[i]); 625 header["Flagged"] = "F"; 626 break; 627 case "unflagged": 628 if (header["Importance"].indexOf("High") != -1) 629 write_msg(get_lang("At least one of selected message cant be marked as normal")); 630 else { 631 set_msg_as_unflagged(msgs_to_set[i]); 632 header["Flagged"] = "N"; 633 } 634 break; 635 case "seen": 636 header["Unseen"] = "N"; 637 set_msg_as_read(msgs_to_set[i],true); 638 unseen = 0; 639 break; 640 case "answered": 641 header["Draft"]=""; 642 header["Answered"]="A"; 643 Element("td_message_answered_"+msgs_to_set[i]).innerHTML = '<img src=templates/default/images/answered.gif title=Respondida>'; 644 break; 645 case "forwarded": 646 header["Draft"]="X"; 647 header["Answered"]="A"; 648 Element("td_message_answered_"+msgs_to_set[i]).innerHTML = '<img src=templates/default/images/forwarded.gif title=Encaminhada>'; 649 break; 650 } 651 652 rs.close(); 653 654 if(Element("check_box_message_" + msgs_to_set[i])) 655 Element("check_box_message_" + msgs_to_set[i]).checked = false; 656 657 this.dbGears.execute("update mail set header='"+connector.serialize(header)+"',unseen="+unseen+" where rowid="+msgs_to_set[i]); 658 } 659 if(Element('chk_box_select_all_messages')) 660 Element('chk_box_select_all_messages').checked = false; 661 this.finalize(); 662 663 } 664 665 local_messages.prototype.set_message_flag = function(msg_number,flag) { 666 this.set_messages_flag(msg_number,flag); 667 } 668 669 local_messages.prototype.get_unseen_msgs_number = function() { 670 this.init_local_messages(); 671 var rs = this.dbGears.execute("select count(*) from mail where unseen=1"); 672 var retorno = rs.field(0); 673 rs.close(); 674 this.finalize(); 675 return retorno; 676 } 677 678 local_messages.prototype.create_folder = function(folder) { 679 680 if (folder.indexOf("local_") != -1) 681 return false; //can't create folder with string local_ 682 683 this.init_local_messages(); 684 try { 685 this.dbGears.execute("insert into folder (folder,uid_usuario) values (?,?)",[folder,account_id]); 686 } catch (error) { 687 this.finalize(); 688 throw error; 689 return false; 690 } 691 this.finalize(); 692 return true; 693 } 694 695 local_messages.prototype.list_local_folders = function(folder) { 696 this.init_local_messages(); 697 var retorno = new Array(); 698 rs = this.dbGears.execute("select folder,rowid from folder where uid_usuario=?",[account_id]); 699 while(rs.isValidRow()) { 700 var temp = new Array(); 701 temp[0] = rs.field(0); 702 703 var rs2 = this.dbGears.execute("select count(*) from mail where id_folder=? and unseen=1",[rs.field(1)]); 704 temp[1] = rs2.field(0); 705 706 var rs3 = this.dbGears.execute("select * from folder where folder like ? limit 1",[temp[0]+"/%"]); 707 if(rs3.isValidRow()) 708 temp[2] = 1; 709 else 710 temp[2] = 0; 711 retorno.push(temp); 712 rs.next(); 713 } 714 715 rs.close(); 716 this.finalize(); 717 return retorno; 718 } 719 720 local_messages.prototype.rename_folder = function(folder,old_folder) { 721 if (folder.indexOf("local_") != -1) 722 return false; //can't create folder with string local_ 723 this.init_local_messages(); 724 if (old_folder.indexOf("/") != "-1") { 725 final_pos = old_folder.lastIndexOf("/"); 726 folder = old_folder.substr(0, final_pos) + "/" + folder; 727 } 728 try { 729 this.dbGears.execute("update folder set folder=? where folder=? and uid_usuario=?",[folder,old_folder,account_id]); 730 } catch (error) { 731 this.finalize(); 732 return false; 733 } 734 rs = this.dbGears.execute("select folder from folder where folder like ? and uid_usuario=?",[old_folder+'/%',account_id]); 735 while(rs.isValidRow()) { 736 folder_tmp = rs.field(0); 737 folder_new = folder_tmp.replace(old_folder,folder); 738 this.dbGears.execute("update folder set folder=? where folder=?",[folder_new,folder_tmp]); 739 rs.next(); 740 } 741 742 743 this.finalize(); 744 return true; 745 } 746 747 local_messages.prototype.remove_folder = function(folder) { 748 this.init_local_messages(); 749 var rs = this.dbGears.execute("select count(rowid) from folder where folder like ? and uid_usuario=?",[folder+"/%",account_id]); 750 var sons = rs.field(0); 751 rs.close(); 752 753 if(sons == 0){ 754 var rs = this.dbGears.execute("select rowid from folder where folder=? and uid_usuario=?",[folder,account_id]); 755 var folder_id = rs.field(0); 756 rs.close(); 757 this.dbGears.execute("delete from folder where rowid=?",[folder_id]); 758 rs = this.dbGears.execute("select rowid,mail from mail where id_folder=?",[folder_id]); 759 while(rs.isValidRow()) { 760 var rs2 = this.dbGears.execute("select url from anexo where id_mail=?",[rs.field(0)]); 761 while(rs2.isValidRow()) { 762 this.store.remove(rs2.field(0)); 763 rs2.next(); 764 } 765 rs2.close(); 766 this.dbGears.execute("delete from anexo where id_mail=?",[rs.field(0)]); 767 var mail = connector.unserialize(rs.field(1)); 768 this.store.remove(mail.url_export_file); 769 rs.next(); 770 } 771 rs.close(); 772 this.dbGears.execute("delete from mail where id_folder=?",[folder_id]); 773 return true 774 this.finalize(); 775 }else { 776 return false 777 this.finalize(); 778 } 779 780 } 781 782 local_messages.prototype.move_messages = function(new_folder,msgs_number) { 783 this.init_local_messages(); 784 var rs = this.dbGears.execute("select rowid from folder where folder=? and uid_usuario=?",[new_folder,account_id]); 785 var id_folder = rs.field(0); 786 rs.close(); 787 this.dbGears.execute("update mail set id_folder="+id_folder+" where rowid in ("+msgs_number.toString()+")"); //usando statement nï¿œo tava funcionando quando tinha mais de um email... 788 this.finalize(); 789 } 790 791 local_messages.prototype.search = function(folders,sFilter) { 792 this.init_local_messages(); 793 var filters = sFilter.replace(/^##|##$/g,"").split('##'); 794 var friendly_filters = new Array(); 795 796 if (sFilter.indexOf('ALL') != -1) { //all filters... 797 filters[0] = sFilter.replace(/##/g,""); 798 tmp = filters[0].split("<=>"); 799 800 searchKey = new Array(); 801 searchKey.push("SUBJECT"); 802 searchKey.push(tmp[1]); 803 friendly_filters.push(searchKey); 804 805 searchKey = new Array(); 806 searchKey.push("BODY"); 807 searchKey.push(tmp[1]); 808 friendly_filters.push(searchKey); 809 810 searchKey = new Array(); 811 searchKey.push("FROM"); 812 searchKey.push(tmp[1]); 813 friendly_filters.push(searchKey); 814 815 searchKey = new Array(); 816 searchKey.push("TO"); 817 searchKey.push(tmp[1]); 818 friendly_filters.push(searchKey); 819 820 searchKey = new Array(); 821 searchKey.push("CC"); 822 searchKey.push(tmp[1]); 823 friendly_filters.push(searchKey); 824 } 825 else { 826 for (var i=0; i<filters.length; i++) 827 { 828 if (filters[i] != ""){ 829 //tmp[0] = tmp[0].replace(/^\s+|\s+$/g,""); 830 //tmp[1] = tmp[1].replace(/^\s+|\s+$/g,""); 831 friendly_filters.push(filters[i].split("<=>")); 832 } 833 } 834 } 835 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 ("; 836 for(var fnum in folders) { 837 sql+="'"+folders[fnum]+"'"; 838 if(fnum<folders.length-1) 839 sql+=","; 840 } 841 sql += ") and ("; 842 for (var z=0;z<friendly_filters.length;z++) { 843 if (z != 0) { 844 if (sFilter.indexOf('ALL') != -1) 845 sql += " or"; 846 else 847 sql += " and"; 848 } 849 var cond = friendly_filters[z][0].replace(/^\s+|\s+$/g,""); 850 if (cond == "SINCE" || cond == "BEFORE" | cond == "ON"){ 851 852 tmpDate = url_decode(friendly_filters[z][1]).split('/'); 853 854 // Date = url_decode(friendly_filters[z][1]); 855 sql+=" mail.timestamp " + this.aux_convert_filter_field(friendly_filters[z][0], tmpDate); 856 } 857 else if (!friendly_filters[z][1]) 858 { 859 sql+=" mail."+this.aux_convert_filter_field(friendly_filters[z][0]); 860 } 861 else 862 { 863 sql+=" mail."+this.aux_convert_filter_field(friendly_filters[z][0])+" like '%"+url_decode(friendly_filters[z][1])+"%'"; 864 } 865 } 866 sql += ")"; 867 var rs = this.dbGears.execute(sql); 868 var retorno = ""; 869 while(rs.isValidRow()) { 870 var header = connector.unserialize(rs.field(0)); 871 retorno+="##"+"local_"+rs.field(1)+"--"+header["from"]["name"]+"--"+header["subject"]+"--"+header["udate"]+"--"+this.aux_convert_size(rs.field(3))+"--"+header["Unseen"]+header["Recent"]+header["Flagged"]+header["Draft"]+"--"+rs.field(2)+"##"; 872 rs.next(); 873 } 874 875 this.finalize(); 876 return retorno==""?false:retorno; 877 878 } 879 880 local_messages.prototype.aux_convert_size = function(size) { 881 var tmp = Math.floor(size/1024); 882 if(tmp >= 1){ 883 return tmp + " kb"; 884 }else{ 885 return size + " b"; 886 } 887 888 } 889 890 local_messages.prototype.aux_convert_filter_field = function(filter,date) { 891 if (typeof date != 'undefined'){ 892 var dateObj=new Date(); 893 dateObj.setFullYear(date[2],date[1]-1,date[0]); 894 } 895 896 if((filter=="SUBJECT ") || (filter=="SUBJECT")) 897 return "subject"; 898 else if((filter=="BODY ") || (filter=="BODY")) 899 return "body"; 900 else if((filter=="FROM ") || (filter=="FROM")) 901 return "ffrom"; 902 else if((filter=="TO ") || (filter=="TO")) 903 return "fto"; 904 else if((filter=="CC ") || (filter=="CC")) 905 return "cc"; 906 else if (filter.replace(/^\s+|\s+$/g,"") == "SINCE"){ 907 dateObj.setHours(0, 0, 0, 0); 908 return ">= " + dateObj.getTime().toString(10).substr(0, 10); 909 } 910 else if (filter.replace(/^\s+|\s+$/g,"") == "BEFORE"){ 911 dateObj.setHours(23, 59, 59, 999); 912 return "<= " + dateObj.getTime().toString(10).substr(0, 10); 913 } 914 else if (filter.replace(/^\s+|\s+$/g,"") == "ON"){ 915 dateObj.setHours(0, 0, 0, 0); 916 var ts1 = dateObj.getTime().toString(10).substr(0, 10); 917 dateObj.setHours(23, 59, 59, 999); 918 var ts2 = dateObj.getTime().toString(10).substr(0, 10); 919 return ">= " + ts1 + ") and (timestamp <= " + ts2; 920 } 921 else if (filter.replace(/^\s+|\s+$/g,"") == "FLAGGED") 922 return "flagged = 1"; 923 else if (filter.replace(/^\s+|\s+$/g,"") == "UNFLAGGED") 924 return "flagged = 0"; 925 else if (filter.replace(/^\s+|\s+$/g,"") == "UNSEEN") 926 return "unseen = 1"; 927 else if (filter.replace(/^\s+|\s+$/g,"") == "SEEN") 928 return "unseen = 0"; 929 else if (filter.replace(/^\s+|\s+$/g,"") == "ANSWERED") 930 return "answered = 1"; 931 else if (filter.replace(/^\s+|\s+$/g,"") == "UNANSWERED") 932 return "answered = 0"; 933 else if (filter.replace(/^\s+|\s+$/g,"") == "RECENT") 934 return "recent = 1"; 935 else if (filter.replace(/^\s+|\s+$/g,"") == "OLD") 936 return "recent = 0"; 937 938 } 939 940 local_messages.prototype.has_local_mails = function() { 941 this.init_local_messages(); 942 var rs = this.dbGears.execute("select rowid from folder limit 0,1"); 943 var retorno; 944 if(rs.isValidRow()) 945 retorno = true; 946 else 947 retorno = false; 948 this.finalize(); 949 return retorno; 950 } 951 952 //Por Bruno Costa(bruno.vieira-costa@serpro.gov.br - Simple AJAX function used to get the RFC822 email source. 953 local_messages.prototype.get_src = function(url){ 954 AJAX = false; 955 if (window.XMLHttpRequest) { // Mozilla, Safari,... 956 AJAX = new XMLHttpRequest(); 957 if (AJAX.overrideMimeType) { 958 AJAX.overrideMimeType('text/xml'); 959 } 960 } else if (window.ActiveXObject) { // IE 961 try { 962 AJAX = new ActiveXObject("Msxml2.XMLHTTP"); 963 } catch (e) { 964 try { 965 AJAX = new ActiveXObject("Microsoft.XMLHTTP"); 966 } catch (e) {} 967 } 968 } 969 970 if (!AJAX) { 971 alert('ERRO :(Seu navegador não suporta a aplicação usada neste site'); 972 return false; 973 } 974 975 AJAX.onreadystatechange = function() { 976 if (AJAX.readyState == 4) { 977 AJAX.src=AJAX.responseText; 978 if (AJAX.status == 200) { 979 return AJAX.responseText; 980 } else { 981 return false; 982 } 983 } 984 } 985 986 AJAX.open('get', url, false); 987 AJAX.send(null); 988 return AJAX.responseText; 989 }; 990 991 //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 992 //para que elas sejam inseridas no imap pela funᅵᅵo imap_functions.unarchive_mail. 993 local_messages.prototype.unarchive_msgs = function (folder,new_folder,msgs_number){ 994 995 if(!new_folder) 996 new_folder='INBOX'; 997 this.init_local_messages(); 998 // alert(folder+new_folder+msgs_number); 999 var handler_unarchive = function(data) 1000 { 1001 if(data.error == '') 1002 write_msg(get_lang('All messages are successfully unarchived')); 1003 else 1004 alert(data.error); 1005 } 1006 if(msgs_number =='selected' || !msgs_number) 1007 { 1008 msgs_number = get_selected_messages() 1009 if (!msgs_number){ 1010 write_msg(get_lang('No selected message.')); 1011 return; 1012 } 1013 var rs = this.dbGears.execute("select mail,timestamp from mail where rowid in ("+msgs_number+")"); 1014 var source=""; 1015 var timestamp=""; 1016 while(rs.isValidRow()) { 1017 mail=connector.unserialize(rs.field(0)); 1018 source_tmp=escape(this.get_src(mail.url_export_file)); 1019 source+="#@#@#@"+source_tmp; 1020 timestamp+="#@#@#@"+rs.field(1); 1021 rs.next(); 1022 } 1023 rs.close(); 1024 this.finalize(); 1025 } 1026 else 1027 { 1028 var rs = this.dbGears.execute("select mail,timestamp from mail where rowid="+msgs_number); 1029 mail=connector.unserialize(rs.field(0)); 1030 var source =""; 1031 source = this.get_src(mail.url_export_file); 1032 timestamp=rs.field(1); 1033 rs.close(); 1034 this.finalize(); 1035 } 1036 params="&folder="+new_folder+"&source="+source+"×tamp="+timestamp; 1037 cExecute ("$this.imap_functions.unarchive_mail&", handler_unarchive, params); 1038 } 1039 1040 local_messages.prototype.get_msg_date = function (original_id, is_local){ 1041 1042 this.init_local_messages(); 1043 1044 if (typeof(is_local) == 'undefined') 1045 { 1046 is_local = false; 1047 } 1048 1049 var rs; 1050 1051 if (is_local) 1052 { 1053 rs = this.dbGears.execute("select mail from mail where rowid="+original_id); 1054 } 1055 else 1056 { 1057 rs = this.dbGears.execute("select mail from mail where original_id="+original_id); 1058 } 1059 var tmp = connector.unserialize(rs.field(0)); 1060 var ret = new Array(); 1061 ret.fulldate = tmp.fulldate.substr(0,16); 1062 ret.smalldate = tmp.msg_day; 1063 ret.msg_day = tmp.msg_day; 1064 ret.msg_hour = tmp.msg_day; 1065 1066 rs.close(); 1067 this.finalize(); 1068 return ret; 1069 } 1070 1071 1072 local_messages.prototype.download_all_local_attachments = function(folder,id){ 1073 this.init_local_messages(); 1074 var rs = this.dbGears.execute("select mail from mail where rowid="+id); 1075 var tmp = connector.unserialize(rs.field(0)); 1076 rs.close(); 1077 this.finalize(); 1078 source = this.get_src(tmp.url_export_file); 1079 source = escape(source); 1080 var handler_source = function(data){ 1081 download_attachments(null, null, data, null,null,'anexos.zip'); 1082 } 1083 cExecute("$this.imap_functions.download_all_local_attachments",handler_source,"source="+source); 1084 } 1085 1086 /*************************************************************************/ 650 break; 651 case "seen": 652 header["Unseen"] = "N"; 653 set_msg_as_read(msgs_to_set[i],true); 654 unseen = 0; 655 break; 656 case "answered": 657 header["Draft"]=""; 658 header["Answered"]="A"; 659 Element("td_message_answered_"+msgs_to_set[i]).innerHTML = '<img src=templates/default/images/answered.gif title=Respondida>'; 660 break; 661 case "forwarded": 662 header["Draft"]="X"; 663 header["Answered"]="A"; 664 Element("td_message_answered_"+msgs_to_set[i]).innerHTML = '<img src=templates/default/images/forwarded.gif title=Encaminhada>'; 665 break; 666 } 667 668 rs.close(); 669 670 if(Element("check_box_message_" + msgs_to_set[i])) 671 Element("check_box_message_" + msgs_to_set[i]).checked = false; 672 673 this.dbGears.execute("update mail set header='"+connector.serialize(header)+"',unseen="+unseen+" where rowid="+msgs_to_set[i]); 674 } 675 if(Element('chk_box_select_all_messages')) 676 Element('chk_box_select_all_messages').checked = false; 677 this.finalize(); 678 679 } 680 681 local_messages.prototype.set_message_flag = function(msg_number,flag) { 682 this.set_messages_flag(msg_number,flag); 683 } 684 685 local_messages.prototype.get_unseen_msgs_number = function() { 686 this.init_local_messages(); 687 var rs = this.dbGears.execute("select count(*) from mail where unseen=1"); 688 var retorno = rs.field(0); 689 rs.close(); 690 this.finalize(); 691 return retorno; 692 } 693 694 local_messages.prototype.create_folder = function(folder) { 695 696 if (folder.indexOf("local_") != -1) 697 return false; //can't create folder with string local_ 698 699 this.init_local_messages(); 700 try { 701 this.dbGears.execute("insert into folder (folder,uid_usuario) values (?,?)",[folder,account_id]); 702 } catch (error) { 703 this.finalize(); 704 throw error; 705 return false; 706 } 707 this.finalize(); 708 return true; 709 } 710 711 local_messages.prototype.list_local_folders = function(folder) { 712 this.init_local_messages(); 713 var retorno = new Array(); 714 var retorno_defaults = new Array(); 715 rs = this.dbGears.execute("select folder,rowid from folder where uid_usuario=?",[account_id]); 716 // rs = this.dbGears.execute("select folder.folder,sum(mail.unseen) from folder left join mail on "+ 717 // "folder.rowid=mail.id_folder where folder.uid_usuario=? group by folder.folder",[account_id]); 718 var achouInbox = false,achouSent = false ,achouSentConf = false,achouTrash = false,achouDrafts = false; 719 while(rs.isValidRow()) { 720 var temp = new Array(); 721 temp[0] = rs.field(0); 722 var rs2 = this.dbGears.execute("select count(*) from mail where id_folder=? and unseen=1",[rs.field(1)]); 723 rs2.field(0)? temp[1] = rs2.field(0):temp[1]=0; 724 725 var rs3 = this.dbGears.execute("select * from folder where folder like ? limit 1",[temp[0]+"/%"]); 726 if(rs3.isValidRow()) 727 temp[2] = 1; 728 else 729 temp[2] = 0; 730 731 if(sentfolder == preferences.save_in_folder.replace("INBOX/","") || preferences.save_in_folder.replace("INBOX/","") == trashfolder || preferences.save_in_folder.replace("INBOX/","") == draftsfolder) 732 achouSentConf= true; 733 734 switch (temp[0]) { 735 case 'Inbox': 736 retorno_defaults[0] = temp; 737 achouInbox = true; 738 break; 739 case sentfolder : 740 retorno_defaults[1] = temp; 741 achouSent = true; 742 break; 743 case trashfolder: 744 retorno_defaults[3] = temp; 745 achouTrash = true; 746 break; 747 case draftsfolder: 748 retorno_defaults[4] = temp; 749 achouDrafts = true; 750 break; 751 case preferences.save_in_folder.replace("INBOX/",""): 752 retorno_defaults[2] = temp; 753 achouSentConf = true; 754 break; 755 default: 756 retorno.push(temp); 757 } 758 759 rs.next(); 760 } 761 762 rs.close(); 763 this.finalize(); 764 765 if(achouInbox && achouSent && achouSentConf && achouTrash && achouDrafts){ 766 var retorno_final = retorno_defaults.concat(retorno.sort(charOrdA)); 767 return retorno_final; 768 }else{ 769 if(!achouInbox) 770 this.create_folder('Inbox'); 771 if(!achouSent) 772 this.create_folder(sentfolder); 773 if(!achouTrash) 774 this.create_folder(trashfolder); 775 if(!achouDrafts) 776 this.create_folder(draftsfolder); 777 if(!achouSentConf) 778 this.create_folder(preferences.save_in_folder.replace("INBOX/","")); 779 return this.list_local_folders(); 780 } 781 782 } 783 local_messages.prototype.rename_folder = function(folder,old_folder) { 784 if (folder.indexOf("local_") != -1) 785 return false; //can't create folder with string local_ 786 this.init_local_messages(); 787 if (old_folder.indexOf("/") != "-1") { 788 final_pos = old_folder.lastIndexOf("/"); 789 folder = old_folder.substr(0, final_pos) + "/" + folder; 790 } 791 try { 792 this.dbGears.execute("update folder set folder=? where folder=? and uid_usuario=?",[folder,old_folder,account_id]); 793 } catch (error) { 794 this.finalize(); 795 return false; 796 } 797 rs = this.dbGears.execute("select folder from folder where folder like ? and uid_usuario=?",[old_folder+'/%',account_id]); 798 while(rs.isValidRow()) { 799 folder_tmp = rs.field(0); 800 folder_new = folder_tmp.replace(old_folder,folder); 801 this.dbGears.execute("update folder set folder=? where folder=?",[folder_new,folder_tmp]); 802 rs.next(); 803 } 804 805 806 this.finalize(); 807 return true; 808 } 809 810 local_messages.prototype.remove_folder = function(folder) { 811 this.init_local_messages(); 812 var rs = this.dbGears.execute("select count(rowid) from folder where folder like ? and uid_usuario=?",[folder+"/%",account_id]); 813 var sons = rs.field(0); 814 rs.close(); 815 816 if(sons == 0){ 817 var rs = this.dbGears.execute("select rowid from folder where folder=? and uid_usuario=?",[folder,account_id]); 818 var folder_id = rs.field(0); 819 rs.close(); 820 this.dbGears.execute("delete from folder where rowid=?",[folder_id]); 821 rs = this.dbGears.execute("select rowid,mail from mail where id_folder=?",[folder_id]); 822 while(rs.isValidRow()) { 823 var rs2 = this.dbGears.execute("select url from anexo where id_mail=?",[rs.field(0)]); 824 while(rs2.isValidRow()) { 825 this.store.remove(rs2.field(0)); 826 rs2.next(); 827 } 828 rs2.close(); 829 this.dbGears.execute("delete from anexo where id_mail=?",[rs.field(0)]); 830 var mail = connector.unserialize(rs.field(1)); 831 this.store.remove(mail.url_export_file); 832 rs.next(); 833 } 834 rs.close(); 835 this.dbGears.execute("delete from mail where id_folder=?",[folder_id]); 836 return true 837 this.finalize(); 838 }else { 839 return false 840 this.finalize(); 841 } 842 843 } 844 845 local_messages.prototype.move_messages = function(new_folder,msgs_number) { 846 this.init_local_messages(); 847 var rs = this.dbGears.execute("select rowid from folder where folder=? and uid_usuario=?",[new_folder,account_id]); 848 var id_folder = rs.field(0); 849 rs.close(); 850 this.dbGears.execute("update mail set id_folder="+id_folder+" where rowid in ("+msgs_number.toString()+")"); //usando statement nï¿œo tava funcionando quando tinha mais de um email... 851 this.finalize(); 852 } 853 854 local_messages.prototype.search = function(folders,sFilter) { 855 this.init_local_messages(); 856 var filters = sFilter.replace(/^##|##$/g,"").split('##'); 857 var friendly_filters = new Array(); 858 859 if (sFilter.indexOf('ALL') != -1) { //all filters... 860 filters[0] = sFilter.replace(/##/g,""); 861 tmp = filters[0].split("<=>"); 862 863 searchKey = new Array(); 864 searchKey.push("SUBJECT"); 865 searchKey.push(tmp[1]); 866 friendly_filters.push(searchKey); 867 868 searchKey = new Array(); 869 searchKey.push("BODY"); 870 searchKey.push(tmp[1]); 871 friendly_filters.push(searchKey); 872 873 searchKey = new Array(); 874 searchKey.push("FROM"); 875 searchKey.push(tmp[1]); 876 friendly_filters.push(searchKey); 877 878 searchKey = new Array(); 879 searchKey.push("TO"); 880 searchKey.push(tmp[1]); 881 friendly_filters.push(searchKey); 882 883 searchKey = new Array(); 884 searchKey.push("CC"); 885 searchKey.push(tmp[1]); 886 friendly_filters.push(searchKey); 887 } 888 else { 889 for (var i=0; i<filters.length; i++) 890 { 891 if (filters[i] != ""){ 892 //tmp[0] = tmp[0].replace(/^\s+|\s+$/g,""); 893 //tmp[1] = tmp[1].replace(/^\s+|\s+$/g,""); 894 friendly_filters.push(filters[i].split("<=>")); 895 } 896 } 897 } 898 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 ("; 899 for(var fnum in folders) { 900 sql+="'"+folders[fnum]+"'"; 901 if(fnum<folders.length-1) 902 sql+=","; 903 } 904 sql += ") and ("; 905 for (var z=0;z<friendly_filters.length;z++) { 906 if (z != 0) { 907 if (sFilter.indexOf('ALL') != -1) 908 sql += " or"; 909 else 910 sql += " and"; 911 } 912 var cond = friendly_filters[z][0].replace(/^\s+|\s+$/g,""); 913 if (cond == "SINCE" || cond == "BEFORE" | cond == "ON"){ 914 915 tmpDate = url_decode(friendly_filters[z][1]).split('/'); 916 917 // Date = url_decode(friendly_filters[z][1]); 918 sql+=" mail.timestamp " + this.aux_convert_filter_field(friendly_filters[z][0], tmpDate); 919 } 920 else if (!friendly_filters[z][1]) 921 { 922 sql+=" mail."+this.aux_convert_filter_field(friendly_filters[z][0]); 923 } 924 else 925 { 926 sql+=" mail."+this.aux_convert_filter_field(friendly_filters[z][0])+" like '%"+url_decode(friendly_filters[z][1])+"%'"; 927 } 928 } 929 sql += ")"; 930 var rs = this.dbGears.execute(sql); 931 var retorno = ""; 932 while(rs.isValidRow()) { 933 var header = connector.unserialize(rs.field(0)); 934 retorno+="##"+"local_"+rs.field(1)+"--"+header["from"]["name"]+"--"+header["subject"]+"--"+header["udate"]+"--"+this.aux_convert_size(rs.field(3))+"--"+header["Unseen"]+header["Recent"]+header["Flagged"]+header["Draft"]+"--"+rs.field(2)+"##"; 935 rs.next(); 936 } 937 938 this.finalize(); 939 return retorno==""?false:retorno; 940 941 } 942 943 local_messages.prototype.aux_convert_size = function(size) { 944 var tmp = Math.floor(size/1024); 945 if(tmp >= 1){ 946 return tmp + " kb"; 947 }else{ 948 return size + " b"; 949 } 950 951 } 952 953 local_messages.prototype.aux_convert_filter_field = function(filter,date) { 954 if (typeof date != 'undefined'){ 955 var dateObj=new Date(); 956 dateObj.setFullYear(date[2],date[1]-1,date[0]); 957 } 958 959 if((filter=="SUBJECT ") || (filter=="SUBJECT")) 960 return "subject"; 961 else if((filter=="BODY ") || (filter=="BODY")) 962 return "body"; 963 else if((filter=="FROM ") || (filter=="FROM")) 964 return "ffrom"; 965 else if((filter=="TO ") || (filter=="TO")) 966 return "fto"; 967 else if((filter=="CC ") || (filter=="CC")) 968 return "cc"; 969 else if (filter.replace(/^\s+|\s+$/g,"") == "SINCE"){ 970 dateObj.setHours(0, 0, 0, 0); 971 return ">= " + dateObj.getTime().toString(10).substr(0, 10); 972 } 973 else if (filter.replace(/^\s+|\s+$/g,"") == "BEFORE"){ 974 dateObj.setHours(23, 59, 59, 999); 975 return "<= " + dateObj.getTime().toString(10).substr(0, 10); 976 } 977 else if (filter.replace(/^\s+|\s+$/g,"") == "ON"){ 978 dateObj.setHours(0, 0, 0, 0); 979 var ts1 = dateObj.getTime().toString(10).substr(0, 10); 980 dateObj.setHours(23, 59, 59, 999); 981 var ts2 = dateObj.getTime().toString(10).substr(0, 10); 982 return ">= " + ts1 + ") and (timestamp <= " + ts2; 983 } 984 else if (filter.replace(/^\s+|\s+$/g,"") == "FLAGGED") 985 return "flagged = 1"; 986 else if (filter.replace(/^\s+|\s+$/g,"") == "UNFLAGGED") 987 return "flagged = 0"; 988 else if (filter.replace(/^\s+|\s+$/g,"") == "UNSEEN") 989 return "unseen = 1"; 990 else if (filter.replace(/^\s+|\s+$/g,"") == "SEEN") 991 return "unseen = 0"; 992 else if (filter.replace(/^\s+|\s+$/g,"") == "ANSWERED") 993 return "answered = 1"; 994 else if (filter.replace(/^\s+|\s+$/g,"") == "UNANSWERED") 995 return "answered = 0"; 996 else if (filter.replace(/^\s+|\s+$/g,"") == "RECENT") 997 return "recent = 1"; 998 else if (filter.replace(/^\s+|\s+$/g,"") == "OLD") 999 return "recent = 0"; 1000 1001 } 1002 1003 local_messages.prototype.has_local_mails = function() { 1004 this.init_local_messages(); 1005 var rs = this.dbGears.execute("select rowid from folder limit 0,1"); 1006 var retorno; 1007 if(rs.isValidRow()) 1008 retorno = true; 1009 else 1010 retorno = false; 1011 this.finalize(); 1012 return retorno; 1013 } 1014 1015 //Por Bruno Costa(bruno.vieira-costa@serpro.gov.br - Simple AJAX function used to get the RFC822 email source. 1016 local_messages.prototype.get_src = function(url){ 1017 AJAX = false; 1018 if (window.XMLHttpRequest) { // Mozilla, Safari,... 1019 AJAX = new XMLHttpRequest(); 1020 if (AJAX.overrideMimeType) { 1021 AJAX.overrideMimeType('text/xml'); 1022 } 1023 } else if (window.ActiveXObject) { // IE 1024 try { 1025 AJAX = new ActiveXObject("Msxml2.XMLHTTP"); 1026 } catch (e) { 1027 try { 1028 AJAX = new ActiveXObject("Microsoft.XMLHTTP"); 1029 } catch (e) {} 1030 } 1031 } 1032 1033 if (!AJAX) { 1034 alert('ERRO :(Seu navegador não suporta a aplicação usada neste site'); 1035 return false; 1036 } 1037 1038 AJAX.onreadystatechange = function() { 1039 if (AJAX.readyState == 4) { 1040 AJAX.src=AJAX.responseText; 1041 if (AJAX.status == 200) { 1042 return AJAX.responseText; 1043 } else { 1044 return false; 1045 } 1046 } 1047 } 1048 1049 AJAX.open('get', url, false); 1050 AJAX.send(null); 1051 return AJAX.responseText; 1052 }; 1053 1054 //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 1055 //para que elas sejam inseridas no imap pela funᅵᅵo imap_functions.unarchive_mail. 1056 local_messages.prototype.unarchive_msgs = function (folder,new_folder,msgs_number){ 1057 1058 if(!new_folder) 1059 new_folder='INBOX'; 1060 this.init_local_messages(); 1061 // alert(folder+new_folder+msgs_number); 1062 var handler_unarchive = function(data) 1063 { 1064 if(data.error == '') 1065 write_msg(get_lang('All messages are successfully unarchived')); 1066 else 1067 alert(data.error); 1068 } 1069 if(msgs_number =='selected' || !msgs_number) 1070 { 1071 msgs_number = get_selected_messages() 1072 if (!msgs_number){ 1073 write_msg(get_lang('No selected message.')); 1074 return; 1075 } 1076 var rs = this.dbGears.execute("select mail,timestamp from mail where rowid in ("+msgs_number+")"); 1077 var source=""; 1078 var timestamp=""; 1079 while(rs.isValidRow()) { 1080 mail=connector.unserialize(rs.field(0)); 1081 source_tmp=escape(this.get_src(mail.url_export_file)); 1082 source+="#@#@#@"+source_tmp; 1083 timestamp+="#@#@#@"+rs.field(1); 1084 rs.next(); 1085 } 1086 rs.close(); 1087 this.finalize(); 1088 } 1089 else 1090 { 1091 var rs = this.dbGears.execute("select mail,timestamp from mail where rowid="+msgs_number); 1092 mail=connector.unserialize(rs.field(0)); 1093 var source =""; 1094 source = this.get_src(mail.url_export_file); 1095 timestamp=rs.field(1); 1096 rs.close(); 1097 this.finalize(); 1098 } 1099 params="&folder="+new_folder+"&source="+source+"×tamp="+timestamp; 1100 cExecute ("$this.imap_functions.unarchive_mail&", handler_unarchive, params); 1101 } 1102 1103 local_messages.prototype.get_msg_date = function (original_id, is_local){ 1104 1105 this.init_local_messages(); 1106 1107 if (typeof(is_local) == 'undefined') 1108 { 1109 is_local = false; 1110 } 1111 1112 var rs; 1113 1114 if (is_local) 1115 { 1116 rs = this.dbGears.execute("select mail from mail where rowid="+original_id); 1117 } 1118 else 1119 { 1120 rs = this.dbGears.execute("select mail from mail where original_id="+original_id); 1121 } 1122 var tmp = connector.unserialize(rs.field(0)); 1123 var ret = new Array(); 1124 ret.fulldate = tmp.fulldate.substr(0,16); 1125 ret.smalldate = tmp.msg_day; 1126 ret.msg_day = tmp.msg_day; 1127 ret.msg_hour = tmp.msg_day; 1128 1129 rs.close(); 1130 this.finalize(); 1131 return ret; 1132 } 1133 1134 1135 local_messages.prototype.download_all_local_attachments = function(folder,id){ 1136 this.init_local_messages(); 1137 var rs = this.dbGears.execute("select mail from mail where rowid="+id); 1138 var tmp = connector.unserialize(rs.field(0)); 1139 rs.close(); 1140 this.finalize(); 1141 source = this.get_src(tmp.url_export_file); 1142 source = escape(source); 1143 var handler_source = function(data){ 1144 download_attachments(null, null, data, null,null,'anexos.zip'); 1145 } 1146 cExecute("$this.imap_functions.download_all_local_attachments",handler_source,"source="+source); 1147 } 1148 1149 /*************************************************************************/ 1087 1150 /* Funcao usada para exportar mensagens arquivadas localmente. 1088 1151 * Rommel de Brito Cysne (rommel.cysne@serpro.gov.br) 1089 1152 * em 22/12/2008. 1090 1153 */ 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1154 local_messages.prototype.local_messages_to_export = function(){ 1155 1156 if (openTab.type[currentTab] > 1){ 1157 var msgs_to_export_id = currentTab.substring(0,currentTab.length-2,currentTab); 1158 }else{ 1159 var msgs_to_export_id = get_selected_messages(); 1160 } 1161 var handler_local_mesgs_to_export = function(data){ 1162 download_attachments(null, null, data, null,null,'mensagens.zip'); 1163 } 1164 if(msgs_to_export_id){ 1165 this.init_local_messages(); 1166 var l_msg = "t"; 1167 var mesgs =""; 1168 var subjects =""; 1169 var rs = this.dbGears.execute("select mail,subject from mail where rowid in ("+msgs_to_export_id+")"); 1170 while(rs.isValidRow()){ 1171 mail = connector.unserialize(rs.field(0)); 1172 mail.msg_source?src = mail.msg_source:src = this.get_src(mail.url_export_file); 1173 subject = rs.field(1); 1174 mesgs += src; 1175 mesgs += "@@"; 1176 subjects += subject; 1177 subjects += "@@"; 1178 rs.next(); 1179 } 1180 rs.close(); 1181 this.finalize(); 1182 mesgs = escape(mesgs); 1183 subjects = escape(subjects); 1184 params = "subjects="+subjects+"&mesgs="+mesgs+"&l_msg="+l_msg+"&msgs_to_export="+msgs_to_export_id; 1185 cExecute ("$this.exporteml.makeAll&", handler_local_mesgs_to_export, params); 1186 } 1187 return true; 1188 } 1189 1190 local_messages.prototype.get_all_local_folder_messages= function(folder_name){ 1191 1192 1193 var mesgs = new Array(); 1194 var subjects = new Array(); 1195 var hoje = new Date(); 1196 var msgs_to_export = new Array(); 1197 var l_msg="t"; 1198 1199 this.init_local_messages(); 1200 var query = "select mail,subject,mail.rowid from mail inner join folder on (mail.id_folder=folder.rowid) where folder.folder='" + folder_name + "'"; 1201 1202 var rs = this.dbGears.execute(" "+query) 1203 1204 var handler_local_mesgs_to_export = function(data){ 1205 //alert("data - " + data + " - tipo - " + typeof(data)); 1206 download_attachments(null, null, data, null,null,'mensagens.zip'); 1207 } 1208 var j=0; 1209 while (rs.isValidRow()){ 1210 msgs_to_export[j]=rs.field(2) 1211 mail = connector.unserialize(rs.field(0)); 1212 mail.msg_source?src = mail.msg_source:src = this.get_src(mail.url_export_file); 1213 subject = rs.field(1); 1214 mesgs += msg; 1215 mesgs += "@@"; 1216 subjects += subject; 1217 subjects += "@@"; 1218 rs.next(); 1219 j++; 1220 1221 } 1222 rs.close(); 1223 this.finalize(); 1224 source = escape(mesgs); 1225 subjects = escape(subjects); 1226 params = "folder="+folder_name+"&subjects="+subjects+"&mesgs="+source+"&l_msg="+l_msg+"&msgs_to_export="+msgs_to_export; 1227 cExecute ("$this.exporteml.makeAll&", handler_local_mesgs_to_export, params); 1165 1228 1166 1229 1167 1168 1169 1170 1230 } 1231 1232 1233 /*************************************************************************/ 1171 1234 1172 1235 … … 1175 1238 ******************************************************************/ 1176 1239 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 temp[1] = rs.field(1);1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1240 local_messages.prototype.is_offline_installed = function() { 1241 this.init_local_messages(); 1242 var check = this.localServer.openManagedStore('expresso-offline'); 1243 this.finalize(); 1244 if(check==null) 1245 return false; 1246 else 1247 return true; 1248 1249 } 1250 local_messages.prototype.update_offline = function(redirect) { 1251 this.init_local_messages(); 1252 var managedStore = this.localServer.openManagedStore('expresso-offline'); 1253 1254 if(managedStore!=null){ 1255 1256 managedStore.oncomplete = function(details){ 1257 if(redirect!=null) 1258 location.href=redirect; 1259 } 1260 1261 managedStore.checkForUpdate(); 1262 } else if(redirect!=null) { 1263 location.href=redirect; 1264 } 1265 this.finalize(); 1266 } 1267 1268 local_messages.prototype.uninstall_offline = function() { 1269 if (!window.google || !google.gears) { 1270 temp = confirm(document.getElementById('lang_gears_redirect').value); 1271 if (temp) { 1272 expresso_local_messages.installGears(); 1273 } 1274 return; 1275 1276 } 1277 this.init_local_messages(); 1278 this.localServer.removeManagedStore('expresso-offline'); 1279 alert(document.getElementById('lang_offline_uninstalled').value); 1280 //this.dbGears.execute('drop table user'); 1281 //this.dbGears.execute('drop table queue'); 1282 //this.dbGears.execute('drop table attachments_queue'); 1283 this.finalize(); 1284 } 1285 1286 local_messages.prototype.get_folders_to_sync = function() {//Precisa ter visibilidade ao array de linguagens. 1287 this.init_local_messages(); 1288 var rs = this.dbGears.execute("select id_folder,folder_name from folders_sync where uid_usuario="+account_id); 1289 var retorno = new Array(); 1290 while(rs.isValidRow()) { 1291 temp = new Array(); 1292 temp[0] = rs.field(0); 1293 if(temp[0]=='INBOX/Drafts' ||temp[0]=='INBOX/Trash' || temp[0]=='INBOX/Sent') { 1294 temp[1] = array_lang[rs.field(1).toLowerCase()]; 1295 } 1296 else { 1297 temp[1] = rs.field(1); 1298 } 1299 1300 retorno.push(temp); 1301 rs.next(); 1302 } 1303 this.finalize(); 1304 return retorno; 1305 } 1306 1307 local_messages.prototype.install_offline = function(urlOffline,urlIcone,uid_usuario,login,pass,redirect) { 1308 if (!window.google || !google.gears) { 1309 temp = confirm(document.getElementById('lang_gears_redirect').value); 1310 if (temp) { 1311 expresso_local_messages.installGears(); 1312 } 1313 return; 1314 1315 } 1316 1317 if(pass.length>0) { 1318 only_spaces = true; 1319 for(cont=0;cont<pass.length;cont++) { 1320 if(pass.charAt(cont)!=" ") 1321 only_spaces = false; 1322 } 1323 if(only_spaces) { 1324 alert(document.getElementById('lang_only_spaces_not_allowed').value); 1325 return false; 1326 } 1327 } 1328 1329 modal('loading'); 1330 var desktop = google.gears.factory.create('beta.desktop'); 1331 desktop.createShortcut('ExpressoMail Offline', 1332 urlOffline, 1270 1333 {'32x32': urlIcone}, 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1334 'ExpressoMail Offline'); 1335 1336 1337 this.init_local_messages(); 1338 1339 //user with offline needs to have at least the folder Inbox already created. 1340 tmp_rs = this.dbGears.execute("select rowid from folder where folder='Inbox' and uid_usuario=?",[uid_usuario]); 1341 if(!tmp_rs.isValidRow()) 1342 this.dbGears.execute("insert into folder (folder,uid_usuario) values (?,?)",['Inbox',uid_usuario]); 1343 1344 this.localServer.removeManagedStore('expresso-offline'); 1345 1346 var managedStore = this.localServer.createManagedStore('expresso-offline'); 1347 managedStore.manifestUrl = 'js/manifest'; 1348 1349 managedStore.onerror = function (error) { 1350 alert(error); 1351 } 1352 1353 managedStore.oncomplete = function(details) { 1354 if (close_lightbox_div) { 1355 close_lightbox(); 1356 close_lightbox_div = false; 1357 alert(document.getElementById('lang_offline_installed').value); 1358 location.href=redirect; 1359 } 1360 } 1361 1362 //create structure to user in db 1363 this.dbGears.execute('create table if not exists user (uid_usuario int,login text,pass text, logged int,unique(uid_usuario))'); 1364 this.dbGears.execute('create table if not exists queue (ffrom text, fto text, cc text, cco text,'+ 1365 'subject text, conf_receipt int, important int,body text,sent int,user int)'); 1366 this.dbGears.execute('create table if not exists attachments_queue ('+ 1367 'id_queue int, url_attach text)'); 1368 this.dbGears.execute('create table if not exists sent_problems (' + 1369 'id_queue int,message text)'); 1370 1371 //d = new Date(); 1372 1373 try { 1374 var rs = this.dbGears.execute("select uid_usuario from user where uid_usuario=?",[uid_usuario]); 1375 if(!rs.isValidRow()) 1376 this.dbGears.execute("insert into user (uid_usuario,login,pass) values (?,?,?)",[uid_usuario,login,pass]); 1377 else 1378 this.dbGears.execute("update user set pass=? where uid_usuario=?",[pass,uid_usuario]); 1379 } catch (error) { 1380 this.finalize(); 1381 alert(error); 1382 return false; 1383 } 1384 managedStore.checkForUpdate(); 1385 this.capt_url('controller.php?action=$this.db_functions.get_dropdown_contacts_to_cache'); 1386 1387 this.finalize(); 1388 } 1389 1390 /** 1328 1391 * Return all users in an array following the structure below. 1329 1392 * … … 1331 1394 * value: user login 1332 1395 */ 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 else if (form.elements[i].name == 'input_return_receipt' )1391 1392 1393 1394 else1395 if (form.elements[i].name == 'body')1396 1397 else1398 if (form.elements[i].name == 'input_from')1399 1400 else1401 if (form.elements[i].name == 'input_to')1402 1403 else1404 if (form.elements[i].name == 'input_cc')1405 1406 else1407 if (form.elements[i].name == 'input_cco')1408 1409 else1410 if (form.elements[i].name == 'input_subject')1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1396 local_messages.prototype.get_all_users = function() { 1397 this.init_local_messages(); 1398 var users = new Array(); 1399 var rs = this.dbGears.execute("select uid_usuario,login from user"); 1400 while(rs.isValidRow()) { 1401 users[rs.field(0)] = rs.field(1); 1402 rs.next(); 1403 } 1404 this.finalize(); 1405 return users; 1406 } 1407 1408 local_messages.prototype.set_as_logged = function(uid_usuario,pass,bypass) { 1409 this.init_local_messages(); 1410 if (!bypass) { 1411 var rs = this.dbGears.execute("select pass from user where uid_usuario=?", [uid_usuario]); 1412 if (!rs.isValidRow() || (pass != rs.field(0) && pass != MD5(rs.field(0)))) { 1413 this.finalize(); 1414 return false; 1415 } 1416 } 1417 d = new Date(); 1418 1419 this.dbGears.execute("update user set logged=null"); //Logoff in everybody 1420 this.dbGears.execute("update user set logged=? where uid_usuario=?",[d.getTime(),uid_usuario]); //Login just in one... 1421 this.finalize(); 1422 return true; 1423 } 1424 1425 local_messages.prototype.unset_as_logged = function() { 1426 this.init_local_messages(); 1427 this.dbGears.execute("update user set logged=null"); //Logoff in everybody 1428 this.finalize(); 1429 } 1430 1431 local_messages.prototype.user_logged = function() { 1432 this.init_local_messages(); 1433 var user_logged = new Array(); 1434 var rs = this.dbGears.execute("select uid_usuario,logged from user where logged is not null"); 1435 if(!rs.isValidRow()) { 1436 this.finalize(); 1437 return null; 1438 } 1439 user_logged[0] = rs.field(0); 1440 user_logged[1] = rs.field(1); 1441 this.finalize(); 1442 return user_logged; 1443 } 1444 1445 local_messages.prototype.send_to_queue = function (form) { 1446 this.init_local_messages(); 1447 var mail_values = new Array(); 1448 1449 for (var i=0;i<form.length;i++) { 1450 if (form.elements[i].name != '') { //I.E made me to do that... 1451 if(form.elements[i].name=='folder' || form.elements[i].name=='msg_id' || form.elements[i].name=='' || form.elements[i].name==null) 1452 continue; 1453 else if (form.elements[i].name == 'input_return_receipt' ) 1454 mail_values['conf_receipt'] = form.elements[i].checked ? 1 : 0; 1455 else if(form.elements[i].name == 'input_important_message') 1456 mail_values['important'] = form.elements[i].checked ? 1 : 0; 1457 else 1458 if (form.elements[i].name == 'body') 1459 mail_values['body'] = form.elements[i].value; 1460 else 1461 if (form.elements[i].name == 'input_from') 1462 mail_values['ffrom'] = form.elements[i].value; 1463 else 1464 if (form.elements[i].name == 'input_to') 1465 mail_values['fto'] = form.elements[i].value; 1466 else 1467 if (form.elements[i].name == 'input_cc') 1468 mail_values['cc'] = form.elements[i].value; 1469 else 1470 if (form.elements[i].name == 'input_cco') 1471 mail_values['cco'] = form.elements[i].value; 1472 else 1473 if (form.elements[i].name == 'input_subject') 1474 mail_values['subject'] = form.elements[i].value; 1475 } 1476 } 1477 //mail_values['fto'] = input_to; 1478 //mail_values['cc'] = input_cc; 1479 //mail_values['cco'] = input_cco; 1480 //mail_values['subject'] = input_subject; 1481 //mail_values['conf_receipt'] = input_return_receipt; 1482 //mail_values['important'] = input_important_message; 1483 1484 try { 1485 this.dbGears.execute("insert into queue (ffrom,fto,cc,cco,subject,conf_receipt,important,body,sent,user) values (?,?,?,?,?,?,?,?,0,?)", [mail_values['ffrom'], mail_values['fto'], mail_values['cc'], mail_values['cco'], mail_values['subject'], mail_values['conf_receipt'], mail_values['important'], mail_values['body'], account_id]); 1486 this.send_attach_to_queue(this.dbGears.lastInsertRowId,form); 1487 }catch(error) { 1488 alert(error); 1489 return get_lang('Error sending a mail to queue. Verify if you have installed ExpressoMail Offline'); 1490 } 1491 this.finalize(); 1492 return true; 1493 } 1494 1495 local_messages.prototype.send_attach_to_queue = function(id_queue,form) { 1496 1497 for(i=0;i<form.elements.length;i++) { 1498 1499 if(form.elements[i].name.indexOf("file_")!=-1) { 1500 var tmp_input = form.elements[i]; 1501 var d = new Date(); 1502 var url_local = 'local_attachs/'+d.getTime(); 1503 this.store.captureFile(tmp_input, url_local); 1504 this.dbGears.execute("insert into attachments_queue (id_queue,url_attach) values (?,?)",[id_queue,url_local]); 1505 } 1506 else if(form.elements[i].name.indexOf("offline_forward_")!=-1){ 1507 //alert(); 1508 this.dbGears.execute("insert into attachments_queue (id_queue,url_attach) values (?,?)",[id_queue,form.elements[i].value]); 1509 } 1510 } 1511 } 1512 1513 1514 local_messages.prototype.get_num_msgs_to_send = function() { 1515 this.init_local_messages(); 1516 1517 var rs = this.dbGears.execute("select count(*) from queue where user=? and sent=0",[account_id]); 1518 var to_return = rs.field(0); 1519 1520 this.finalize(); 1521 return to_return; 1522 } 1523 1524 local_messages.prototype.set_problem_on_sent = function(rowid_message,msg) { 1525 this.init_local_messages(); 1526 this.dbGears.execute("update queue set sent = 2 where rowid=?",[rowid_message]); 1527 this.dbGears.execute("insert into sent_problems (id_queue,message) values (?,?)"[rowid_message,msg]); 1528 this.finalize(); 1529 } 1530 1531 local_messages.prototype.set_as_sent = function(rowid_message) { 1532 this.init_local_messages(); 1533 this.dbGears.execute("update queue set sent = 1 where rowid=?",[rowid_message]); 1534 this.finalize(); 1535 } 1536 1537 local_messages.prototype.get_form_msg_to_send = function() { 1538 this.init_local_messages(); 1539 var rs = this.dbGears.execute('select ffrom,fto,cc,cco,subject,conf_receipt,important,body,rowid from queue where sent=0 and user = ? limit 0,1',[account_id]); 1540 if(!rs.isValidRow()) 1541 return false; 1542 1543 var form = document.createElement('form'); 1544 form.method = 'POST'; 1545 form.name = 'form_queue_'+rs.field(8); 1546 form.style.display = 'none'; 1484 1547 form.onsubmit = function(){return false;} 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1548 if(!is_ie) 1549 form.enctype="multipart/form-data"; 1550 else 1551 form.encoding="multipart/form-data"; 1552 1553 var ffrom = document.createElement('TEXTAREA'); 1554 ffrom.name = "input_from"; 1555 ffrom.value = rs.field(0); 1556 form.appendChild(ffrom); 1557 1558 var fto = document.createElement('TEXTAREA'); 1559 fto.name = "input_to"; 1560 fto.value = rs.field(1); 1561 form.appendChild(fto); 1562 1563 var cc = document.createElement('TEXTAREA'); 1564 cc.name = "input_cc"; 1565 cc.value = rs.field(2); 1566 form.appendChild(cc); 1567 1568 var cco = document.createElement('TEXTAREA'); 1569 cco.name = "input_cco"; 1570 cco.value = rs.field(3); 1571 form.appendChild(cco); 1572 1573 var subject = document.createElement('TEXTAREA'); 1574 subject.name = "input_subject"; 1575 subject.value = rs.field(4); 1576 form.appendChild(subject); 1577 1578 var folder = document.createElement('input'); 1579 folder.name='folder'; 1580 folder.value=preferences.save_in_folder; 1581 form.appendChild(folder); 1582 1583 if (rs.field(5) == 1) { 1584 var conf_receipt = document.createElement('input'); 1585 conf_receipt.type='text'; 1586 conf_receipt.name = "input_return_receipt"; 1587 conf_receipt.value = 'on'; 1588 form.appendChild(conf_receipt); 1589 } 1590 1591 if (rs.field(6) == 1) { 1592 var important = document.createElement('input'); 1593 important.type='text'; 1594 important.name = "input_important_message"; 1595 important.value = 'on'; 1596 form.appendChild(important); 1597 } 1598 1599 var body = document.createElement('TEXTAREA'); 1600 body.name = "body"; 1601 body.value = rs.field(7); 1602 form.appendChild(body); 1603 1604 var rowid = document.createElement('input'); 1605 rowid.type = 'hidden'; 1606 rowid.name = 'rowid'; 1607 rowid.value = rs.field(8); 1608 form.appendChild(rowid); 1609 1610 //Mounting the attachs 1611 var divFiles = document.createElement("div"); 1612 divFiles.id = 'divFiles_queue_'+rs.field(8); 1613 1614 form.appendChild(divFiles); 1615 1616 document.getElementById('forms_queue').appendChild(form); 1617 1618 var is_local_forward = false; 1619 try { 1620 1621 var rs_attach = this.dbGears.execute('select url_attach from attachments_queue where id_queue=?', [rs.field(8)]); 1622 while (rs_attach.isValidRow()) { 1623 if(rs_attach.field(0).indexOf('../tmpLclAtt/')==-1) { 1624 tmp_field = addForwardedFile('queue_' + rs.field(8), this.store.getCapturedFileName(rs_attach.field(0)), 'nothing'); 1625 } 1626 else { 1627 var tempNomeArquivo = rs_attach.field(0).split("/"); 1628 var nomeArquivo = tempNomeArquivo[tempNomeArquivo.length-1]; 1629 nomeArquivo = nomeArquivo.substring(0,nomeArquivo.length - 4); //Anexos no gears sï¿œo todos com extensï¿œo .php. tenho que tirar a extensï¿œo para ficar o nome real do arquivo. 1630 is_local_forward = true; 1631 tmp_field = addForwardedFile('queue_' + rs.field(8), nomeArquivo, 'nothing'); 1632 } 1633 fileSubmitter = this.store.createFileSubmitter(); 1634 fileSubmitter.setFileInputElement(tmp_field,rs_attach.field(0)); 1635 // alert(form.innerHTML); 1636 // div.appendChild(tmp_field); 1637 rs_attach.next(); 1638 } 1639 1640 if(is_local_forward) { 1641 var is_lcl_fw = document.createElement('input'); 1642 is_lcl_fw.type = 'hidden'; 1643 is_lcl_fw.name = 'is_local_forward'; 1644 is_lcl_fw.value = "1"; 1645 form.appendChild(is_lcl_fw); 1646 } 1584 1647 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1648 } 1649 catch(exception) { 1650 alert(exception); 1651 } 1652 1653 this.finalize(); 1654 return form; 1655 } 1656 1657 var expresso_local_messages; 1658 expresso_local_messages = new local_messages(); 1659 expresso_local_messages.create_objects();
Note: See TracChangeset
for help on using the changeset viewer.