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