[1518] | 1 | /** |
---|
| 2 | * @author diogenes |
---|
| 3 | */ |
---|
[1595] | 4 | |
---|
| 5 | /** |
---|
| 6 | * @param folders: |
---|
| 7 | * 1 - rowid of folder in sqlite |
---|
| 8 | * 2 - folder name in sqlite |
---|
| 9 | * 3 - ids to not download(for auto archiving) or ids to download(for archiving) |
---|
| 10 | * 4 - true for auto archiving and false for normal archiving. |
---|
| 11 | */ |
---|
[1518] | 12 | function mail_sync() { |
---|
[3068] | 13 | if (typeof(google) == 'undefined') |
---|
| 14 | return false; |
---|
[1595] | 15 | // this.dbGears = null; |
---|
| 16 | // this.localServer = null; |
---|
| 17 | // this.store = null; |
---|
[1518] | 18 | this.folders = new Array(); |
---|
| 19 | this.messages = null; |
---|
| 20 | this.attachs = null; |
---|
| 21 | this.url_attachs = null; |
---|
[1595] | 22 | this.working = false; |
---|
| 23 | this.is_auto = null; |
---|
| 24 | this.errors = new Array(); |
---|
| 25 | // this.main_title = null; |
---|
| 26 | |
---|
[1518] | 27 | this.main_title = null; |
---|
[1595] | 28 | this.dbGears = google.gears.factory.create('beta.database'); |
---|
| 29 | this.localServer = google.gears.factory.create('beta.localserver'); |
---|
| 30 | this.store = this.localServer.createStore('test-store'); |
---|
[3364] | 31 | this.update_folder = false; |
---|
[1518] | 32 | } |
---|
| 33 | |
---|
| 34 | mail_sync.prototype.open_conn = function(){ |
---|
| 35 | var db_in_other_use = true; |
---|
[1595] | 36 | var start_trying = new Date().getTime(); |
---|
[1518] | 37 | while (db_in_other_use) { |
---|
| 38 | try { |
---|
| 39 | this.dbGears.open('database-test'); |
---|
| 40 | db_in_other_use = false; |
---|
| 41 | } |
---|
| 42 | catch (ex) { |
---|
[1857] | 43 | if(new Date().getTime()-start_trying>10000) { //too much time trying, throw an exception |
---|
[1595] | 44 | throw ex; |
---|
| 45 | } |
---|
[1518] | 46 | } |
---|
| 47 | } |
---|
| 48 | } |
---|
| 49 | |
---|
| 50 | mail_sync.prototype.start_sync = function() { |
---|
[3364] | 51 | if (is_ie) |
---|
| 52 | connector.loadScript('TreeShow'); |
---|
[1595] | 53 | if(this.working) { |
---|
[1518] | 54 | //Já está sincronizando... |
---|
| 55 | return; |
---|
| 56 | } |
---|
[1624] | 57 | |
---|
| 58 | this.open_conn(); |
---|
[1621] | 59 | |
---|
[1624] | 60 | var rs = this.dbGears.execute("select id_folder,folder_name from folders_sync where uid_usuario=?",[account_id]); |
---|
[1857] | 61 | if(!rs.isValidRow()) { |
---|
| 62 | this.dbGears.close(); |
---|
[1624] | 63 | return; |
---|
[1857] | 64 | } |
---|
| 65 | |
---|
[1624] | 66 | |
---|
[1595] | 67 | this.working=true; |
---|
[1518] | 68 | this.messages = null; |
---|
| 69 | this.attachs = null; |
---|
| 70 | this.url_attachs = null; |
---|
| 71 | |
---|
| 72 | document.getElementById('main_title').innerHTML = get_lang("Creating folders structure"); |
---|
| 73 | while(rs.isValidRow()) { |
---|
| 74 | var temp = new Array(); |
---|
| 75 | temp[0] = rs.field(0); |
---|
| 76 | temp[1] = rs.field(1); |
---|
| 77 | temp[2] = null; |
---|
[1595] | 78 | temp[3] = false; |
---|
[1518] | 79 | var rs2 = this.dbGears.execute("select mail.original_id from mail inner join folder on mail.id_folder=folder.rowid where folder.folder = ? and mail.uid_usuario=?",[temp[1]==get_lang('Inbox')?'Inbox':temp[1],account_id]); |
---|
| 80 | while(rs2.isValidRow()) { |
---|
| 81 | if(temp[2]==null) |
---|
| 82 | temp[2]=rs2.field(0)+","; |
---|
| 83 | else |
---|
| 84 | temp[2]+=rs2.field(0)+","; |
---|
| 85 | rs2.next(); |
---|
| 86 | } |
---|
| 87 | this.folders.push(temp); |
---|
| 88 | |
---|
| 89 | |
---|
| 90 | //Criando estrutura de pastas... |
---|
| 91 | var folders_to_check = temp[0].split("/");//Todas as pastas tem ao menos INBOX/ |
---|
| 92 | if (folders_to_check.length == 1) |
---|
| 93 | var actual_check = "Inbox"; |
---|
| 94 | else { |
---|
| 95 | folders_to_check = folders_to_check.slice(1); |
---|
| 96 | var actual_check = folders_to_check[0]; |
---|
| 97 | } |
---|
| 98 | for (var i in folders_to_check) { |
---|
| 99 | var rs2 = this.dbGears.execute("select rowid from folder where folder=? and uid_usuario=?", [actual_check, account_id]); |
---|
| 100 | |
---|
| 101 | if (!rs2.isValidRow()) { |
---|
[3364] | 102 | if((!preferences.hide_folders) || (preferences.hide_folders=="0")) |
---|
| 103 | this.update_folder = true; //Precisa atualizar as pastas na arvore de pastas |
---|
[1518] | 104 | this.dbGears.execute("insert into folder (folder,uid_usuario) values (?,?)", [actual_check, account_id]); |
---|
| 105 | } |
---|
[1619] | 106 | if(parseInt(i)+1<folders_to_check.length) |
---|
[1518] | 107 | actual_check += "/"+folders_to_check[parseInt(i)+1]; |
---|
| 108 | } |
---|
[3364] | 109 | |
---|
[1518] | 110 | rs.next(); |
---|
| 111 | } |
---|
| 112 | this.dbGears.close(); |
---|
| 113 | this.syncronize_folders(); |
---|
| 114 | } |
---|
| 115 | |
---|
[1595] | 116 | mail_sync.prototype.archive_msgs = function(folder,folder_dest,ids) { |
---|
| 117 | //this.main_title = document.getElementById('main_title').innerHTML; |
---|
| 118 | var temp = new Array(); |
---|
| 119 | temp[0] = folder; |
---|
| 120 | temp[1] = folder_dest.substr(6); |
---|
| 121 | temp[2] = ids; |
---|
| 122 | temp[3] = true; |
---|
| 123 | this.folders.push(temp); |
---|
| 124 | Element('chk_box_select_all_messages').checked = false; |
---|
| 125 | |
---|
| 126 | array_ids = ids.split(","); |
---|
| 127 | for (var i in array_ids) { |
---|
| 128 | if (Element("check_box_message_" + array_ids[i])) |
---|
| 129 | Element("check_box_message_" + array_ids[i]).checked = false; |
---|
| 130 | remove_className(Element(array_ids[i]), 'selected_msg'); |
---|
| 131 | } |
---|
| 132 | if(!this.working) { |
---|
| 133 | this.working=true; |
---|
| 134 | this.syncronize_folders(); |
---|
| 135 | } |
---|
| 136 | else { |
---|
| 137 | write_msg(get_lang("An archiving is in process, but dont worry, expresso will process this messages after the actual archiving")); |
---|
| 138 | } |
---|
| 139 | } |
---|
| 140 | |
---|
[1518] | 141 | mail_sync.prototype.syncronize_folders = function() { |
---|
| 142 | if (this.folders.length == 0) { |
---|
| 143 | document.getElementById('main_title').innerHTML = get_lang("Deleting downloadeds msgs..."); |
---|
| 144 | expresso_mail_sync.remove_archived_mails(); |
---|
[3364] | 145 | if((!preferences.hide_folders) || (preferences.hide_folders=="0")) { |
---|
| 146 | if (expresso_mail_sync.update_folder) { |
---|
| 147 | ttreeBox.update_folder(); |
---|
| 148 | expresso_mail_sync.update_folder = false; |
---|
| 149 | } |
---|
| 150 | else |
---|
| 151 | draw_tree_local_folders(); |
---|
| 152 | } |
---|
| 153 | expresso_mail_sync.working=false; |
---|
[1518] | 154 | return; |
---|
| 155 | } |
---|
| 156 | var folder_to_sync = this.folders.pop(); |
---|
[1595] | 157 | folder_to_sync[1] = folder_to_sync[0].toUpperCase()=="INBOX" && !folder_to_sync[3]?"Inbox":folder_to_sync[1]; |
---|
[1518] | 158 | |
---|
[1595] | 159 | if(folder_to_sync[3]) { //Em caso de arquivamento normal, pode ser que a pasta inbox ainda não tenha sido criada. |
---|
| 160 | expresso_mail_sync.open_conn() |
---|
[3364] | 161 | if(folder_to_sync[1]=="Inbox" && !expresso_mail_sync.has_inbox_folder()) { |
---|
| 162 | if((!preferences.hide_folders) || (preferences.hide_folders=="0")) |
---|
| 163 | expresso_mail_sync.update_folder = true; //Precisa atualizar as pastas na arvore de pastas |
---|
[1595] | 164 | expresso_mail_sync.dbGears.execute("insert into folder (folder,uid_usuario) values (?,?)",["Inbox",account_id]); |
---|
| 165 | } |
---|
| 166 | expresso_mail_sync.dbGears.close(); |
---|
| 167 | |
---|
[3364] | 168 | |
---|
[1595] | 169 | } |
---|
| 170 | |
---|
[1518] | 171 | var start_sync_mails = function(data) { |
---|
[3364] | 172 | if (!data) { //Erro ao pegar lista de e-mails a serem baixados |
---|
| 173 | write_msg(get_lang("Problems while downloading mails, please try later")); |
---|
| 174 | expresso_mail_sync.working=false; |
---|
| 175 | window.setTimeout("eval('document.getElementById(\"main_title\").innerHTML =\"Expresso Mail\"')",3000); |
---|
| 176 | return; |
---|
| 177 | } |
---|
[1518] | 178 | expresso_mail_sync.messages=data; |
---|
[1595] | 179 | if(expresso_mail_sync.is_auto) |
---|
| 180 | document.getElementById('main_title').innerHTML = get_lang("Auto archiving")+" "+lang_folder(folder_to_sync[1])+": 0 / "+data.length; |
---|
| 181 | else |
---|
| 182 | document.getElementById('main_title').innerHTML = get_lang("Archiving messages on folder")+" "+lang_folder(folder_to_sync[1])+": 0 / "+data.length; |
---|
[1518] | 183 | |
---|
| 184 | expresso_mail_sync.syncronize_mails(folder_to_sync[1]); |
---|
| 185 | } |
---|
[1595] | 186 | |
---|
| 187 | |
---|
| 188 | if (folder_to_sync[3]) { |
---|
| 189 | document.getElementById('main_title').innerHTML = get_lang("Starting to archive messages"); |
---|
| 190 | cExecute("$this.imap_functions.get_info_msgs&folder=" + folder_to_sync[0] + "&msgs_number=" + folder_to_sync[2], start_sync_mails); |
---|
| 191 | this.is_auto = false; |
---|
| 192 | } |
---|
| 193 | else { |
---|
| 194 | document.getElementById('main_title').innerHTML = get_lang("Starting to sync folder")+" "+lang_folder(folder_to_sync[1]); |
---|
[1857] | 195 | var params = "folder="+folder_to_sync[0]+"&mails="+folder_to_sync[2]; |
---|
| 196 | cExecute("$this.imap_functions.msgs_to_archive", start_sync_mails,params); |
---|
[1595] | 197 | this.is_auto = true; |
---|
| 198 | } |
---|
| 199 | |
---|
[1518] | 200 | } |
---|
| 201 | |
---|
| 202 | mail_sync.prototype.syncronize_mails = function(folder_dest) { |
---|
| 203 | if (expresso_mail_sync.messages == null || expresso_mail_sync.messages.length == 0) { |
---|
| 204 | expresso_mail_sync.syncronize_folders(); |
---|
| 205 | return; |
---|
| 206 | } |
---|
| 207 | |
---|
| 208 | msg_to_sync = expresso_mail_sync.messages.pop(); |
---|
| 209 | |
---|
| 210 | //refresh loading |
---|
| 211 | var value_to_change = document.getElementById('main_title').innerHTML.match(/\d+ \//); |
---|
| 212 | value_to_change += ""; |
---|
| 213 | var new_value = value_to_change.replace(" /",""); |
---|
| 214 | new_value = parseInt(new_value) + 1; |
---|
| 215 | document.getElementById('main_title').innerHTML = document.getElementById('main_title').innerHTML.replace(value_to_change,new_value+" /"); |
---|
[1595] | 216 | msg_to_sync = connector.unserialize(msg_to_sync); |
---|
[1518] | 217 | |
---|
| 218 | var source_msg = new Array(); |
---|
| 219 | source_msg['url'] = msg_to_sync.url_export_file; |
---|
[1595] | 220 | |
---|
[1518] | 221 | if (typeof(msg_to_sync['array_attach'])=='object'&&(msg_to_sync['array_attach'] instanceof Array)) |
---|
| 222 | expresso_mail_sync.attachs = msg_to_sync['array_attach'].slice(); |
---|
| 223 | else |
---|
| 224 | expresso_mail_sync.attachs = new Array(); |
---|
| 225 | expresso_mail_sync.attachs.push(source_msg); |
---|
| 226 | expresso_mail_sync.download_attachs(msg_to_sync,folder_dest); |
---|
| 227 | } |
---|
| 228 | |
---|
| 229 | mail_sync.prototype.download_attachs = function(msg,folder_dest) { |
---|
| 230 | if (expresso_mail_sync.attachs == null || expresso_mail_sync.attachs.length == 0) { |
---|
| 231 | expresso_mail_sync.insert_mail(msg, folder_dest); |
---|
[1595] | 232 | |
---|
[1518] | 233 | return; |
---|
| 234 | } |
---|
| 235 | |
---|
| 236 | attach_to_capt = expresso_mail_sync.attachs.pop(); |
---|
| 237 | |
---|
| 238 | var call_back = function(url,success,captureId) { |
---|
[1595] | 239 | if (!success) { |
---|
| 240 | /* |
---|
| 241 | * 0 - original id |
---|
| 242 | * 1 - message subject |
---|
| 243 | * 2 - original folder |
---|
| 244 | */ |
---|
| 245 | var mail_error = new Array(); |
---|
| 246 | mail_error[0] = msg.msg_number; |
---|
| 247 | mail_error[1] = msg.subject; |
---|
| 248 | mail_error[2] = msg.msg_folder; |
---|
| 249 | expresso_mail_sync.errors.push(mail_error); |
---|
| 250 | alert('erro ao baixar: '+url); |
---|
| 251 | |
---|
| 252 | /*if (typeof(msg['array_attach']) == 'object' && (msg['array_attach'] instanceof Array)) { |
---|
| 253 | for (var i in msg['array_attach']) { //remove os anexos que já foram baixados para essa mensagem... |
---|
| 254 | expresso_mail_sync.store.remove(msg['array_attach'][i]['url']); |
---|
| 255 | } |
---|
| 256 | }*/ |
---|
| 257 | expresso_mail_sync.syncronize_mails(folder_dest); //Pula para o próximo e-mail. |
---|
| 258 | } |
---|
| 259 | else { |
---|
| 260 | expresso_mail_sync.download_attachs(msg, folder_dest);//continua baixando o próximo anexo |
---|
| 261 | } |
---|
[1518] | 262 | } |
---|
| 263 | expresso_mail_sync.store.capture(attach_to_capt['url'],call_back); |
---|
| 264 | } |
---|
| 265 | |
---|
| 266 | mail_sync.prototype.insert_mail = function(msg,folder) { |
---|
| 267 | try { |
---|
[1595] | 268 | |
---|
[1518] | 269 | expresso_mail_sync.open_conn(); |
---|
[1595] | 270 | |
---|
[1518] | 271 | var msg_info = msg; |
---|
| 272 | var msg_header = msg['header']; |
---|
| 273 | var anexos = msg['array_attach']; |
---|
| 274 | |
---|
| 275 | |
---|
| 276 | var unseen = 0; |
---|
| 277 | var login = msg_info.login; |
---|
| 278 | var original_id = msg_info.msg_number; |
---|
[1595] | 279 | var original_folder = msg_info.msg_folder=='INBOX/Lixeira/tmpMoveToLocal'?msg_info.msg_folder+(Date.parse(new Date)):msg_info.msg_folder; |
---|
| 280 | |
---|
[1518] | 281 | //Os campos abaixo precisam estar isolados para busca de mensagens em cima deles. |
---|
| 282 | var from = connector.serialize(msg_info.from); |
---|
| 283 | var subject = msg_info.subject; |
---|
| 284 | var body = msg_info.body; |
---|
| 285 | var to = connector.serialize(msg_info.toaddress2); |
---|
| 286 | var cc = connector.serialize(msg_info.cc); |
---|
| 287 | var size = msg_header.Size; |
---|
| 288 | |
---|
| 289 | //Zero os campos que foram isolados para não ter informações duplicadas |
---|
| 290 | msg_info.from = null; |
---|
| 291 | msg_info.subject = null; |
---|
| 292 | msg_info.body = null; |
---|
| 293 | msg_info.to = null; |
---|
| 294 | msg_info.cc = null; |
---|
| 295 | msg_header.Size=null; |
---|
[3222] | 296 | |
---|
[1518] | 297 | /** |
---|
| 298 | * The importance attribute can be empty, and javascript consider as null causing nullpointer. |
---|
| 299 | */ |
---|
| 300 | if((msg_header.Importance == null) || (msg_header.Importance == "")) |
---|
| 301 | msg_header.Importance = "Normal"; |
---|
| 302 | |
---|
| 303 | |
---|
| 304 | var mail = connector.serialize(msg_info); |
---|
| 305 | var header = connector.serialize(msg_header); |
---|
| 306 | |
---|
| 307 | var timestamp = msg_info.timestamp; |
---|
| 308 | var id_folder; |
---|
| 309 | |
---|
| 310 | var rs = this.dbGears.execute("select rowid from folder where folder=? and uid_usuario=?", [folder, account_id]); |
---|
| 311 | id_folder = rs.field(0); |
---|
| 312 | |
---|
| 313 | if(msg_info.Unseen=="U") |
---|
| 314 | unseen = 1; |
---|
| 315 | 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]); |
---|
| 316 | |
---|
[1595] | 317 | |
---|
| 318 | |
---|
[1518] | 319 | //Preenche os anexos. |
---|
| 320 | var id_mail = this.dbGears.lastInsertRowId; |
---|
| 321 | |
---|
| 322 | for (var i = 0; i < anexos.length; i++) { |
---|
| 323 | this.dbGears.execute("insert into anexo (id_mail,nome_anexo,url,pid) values (?,?,?,?)", [id_mail, anexos[i]['name'],anexos[i]['url'],anexos[i]['pid']]); |
---|
| 324 | } |
---|
| 325 | |
---|
[1595] | 326 | var check_remove; |
---|
| 327 | if(this.is_auto) |
---|
| 328 | check_remove = preferences.keep_after_auto_archiving; |
---|
| 329 | else |
---|
| 330 | check_remove = preferences.keep_archived_messages; |
---|
[1518] | 331 | |
---|
| 332 | |
---|
[1595] | 333 | |
---|
| 334 | if(check_remove!=1) |
---|
| 335 | this.dbGears.execute("insert into msgs_to_remove (id_msg,folder,uid_usuario) values (?,?,?)",[original_id,original_folder,account_id]); |
---|
| 336 | |
---|
[1518] | 337 | } catch (error) { |
---|
[1595] | 338 | /* |
---|
| 339 | * 0 - original id |
---|
| 340 | * 1 - message subject |
---|
| 341 | * 2 - original folder |
---|
| 342 | */ |
---|
| 343 | var mail_error = new Array(); |
---|
| 344 | mail_error[0] = original_id; |
---|
| 345 | mail_error[1] = subject; |
---|
| 346 | mail_error[2] = original_folder; |
---|
| 347 | this.errors.push(mail_error); |
---|
| 348 | |
---|
| 349 | if (typeof(msg_info['array_attach'])=='object'&&(msg_info['array_attach'] instanceof Array)) { |
---|
| 350 | for(var i in msg_info['array_attach']) { //remove os anexos que já foram baixados para essa mensagem... |
---|
| 351 | this.store.remove(msg_info['array_attach'][i]['url']); |
---|
| 352 | } |
---|
| 353 | } |
---|
| 354 | |
---|
[1518] | 355 | } |
---|
| 356 | this.dbGears.close(); |
---|
| 357 | this.syncronize_mails(folder); |
---|
| 358 | } |
---|
| 359 | |
---|
[3364] | 360 | mail_sync.prototype.has_inbox_folder = function() {//This function considers that the connection with base is already opened. |
---|
| 361 | var rs = this.dbGears.execute("select rowid from folder where folder='Inbox' and uid_usuario=?",[account_id]); |
---|
[1595] | 362 | if(rs.isValidRow()) |
---|
| 363 | return true; |
---|
| 364 | else |
---|
| 365 | return false; |
---|
| 366 | } |
---|
| 367 | |
---|
[1518] | 368 | mail_sync.prototype.remove_archived_mails = function() { |
---|
| 369 | |
---|
| 370 | expresso_mail_sync.open_conn(); |
---|
| 371 | |
---|
| 372 | var rs = this.dbGears.execute("select distinct(folder) from msgs_to_remove where uid_usuario=?",[account_id]); |
---|
| 373 | if(rs.isValidRow()) { |
---|
| 374 | var folder_to_remove_msgs = rs.field(0); |
---|
| 375 | var rs2 = this.dbGears.execute("select id_msg from msgs_to_remove where folder=? and uid_usuario=?",[folder_to_remove_msgs,account_id]); |
---|
| 376 | |
---|
| 377 | var msgs = null; |
---|
| 378 | while(rs2.isValidRow()) { |
---|
| 379 | if(msgs==null) |
---|
| 380 | msgs = rs2.field(0); |
---|
| 381 | else |
---|
| 382 | msgs += ","+rs2.field(0); |
---|
| 383 | rs2.next(); |
---|
| 384 | } |
---|
| 385 | |
---|
| 386 | |
---|
| 387 | var handler_delete_msgs = function(data){ |
---|
| 388 | if (current_folder == data.folder) { |
---|
| 389 | mail_msg = Element("tbody_box"); |
---|
| 390 | var msg_to_delete; |
---|
| 391 | for (var i = 0; i < data.msgs_number.length; i++) { |
---|
| 392 | msg_to_delete = Element(data.msgs_number[i]); |
---|
| 393 | if (msg_to_delete) { |
---|
| 394 | mail_msg.removeChild(msg_to_delete); |
---|
| 395 | } |
---|
| 396 | } |
---|
| 397 | Element('tot_m').innerHTML = parseInt(Element('tot_m').innerHTML) - data.msgs_number.length; |
---|
| 398 | } |
---|
[3364] | 399 | |
---|
[1518] | 400 | refresh(); |
---|
| 401 | expresso_mail_sync.remove_archived_mails(); |
---|
| 402 | } |
---|
| 403 | |
---|
| 404 | cExecute ("$this.imap_functions.delete_msgs&folder="+folder_to_remove_msgs+"&msgs_number="+msgs, handler_delete_msgs); |
---|
| 405 | this.dbGears.execute("delete from msgs_to_remove where folder=? and uid_usuario=?",[folder_to_remove_msgs,account_id]); |
---|
| 406 | this.dbGears.close(); |
---|
| 407 | |
---|
| 408 | } |
---|
| 409 | else { |
---|
| 410 | this.dbGears.close(); |
---|
[1595] | 411 | document.getElementById('main_title').innerHTML = get_lang("End of archive messages"); |
---|
| 412 | if(this.errors.length>0) { |
---|
| 413 | //TODO: Tratar melhor quando existirem erros... |
---|
| 414 | write_msg(get_lang("at least, one of selected mails is already archived, expresso tried to archive the others, check them later")); |
---|
| 415 | this.errors=new Array(); |
---|
| 416 | } |
---|
| 417 | window.setTimeout("eval('document.getElementById(\"main_title\").innerHTML =\"Expresso Mail\"')",3000); |
---|
[1518] | 418 | } |
---|
| 419 | |
---|
| 420 | } |
---|
| 421 | |
---|
| 422 | mail_sync.prototype.configure_sync = function(folders,formul) { |
---|
| 423 | this.dbGears = google.gears.factory.create('beta.database'); |
---|
| 424 | this.localServer = google.gears.factory.create('beta.localserver'); |
---|
| 425 | this.store = this.localServer.createStore('test-store'); |
---|
| 426 | this.dbGears.open('database-test'); |
---|
| 427 | this.dbGears.execute("delete from folders_sync where uid_usuario=?",[account_id]); |
---|
| 428 | for (var i=0;i<folders.length;i++) { |
---|
| 429 | var pos = folders[i].value.indexOf("/"); |
---|
| 430 | if(pos=="-1") |
---|
| 431 | var folder_name = folders[i].text; |
---|
| 432 | else |
---|
| 433 | var folder_name = folders[i].value.substr(pos+1); |
---|
[3345] | 434 | |
---|
| 435 | folders[i].value = folders[i].value.replace(/#/g,' '); //Whitespaces has the # symbol in combo. |
---|
| 436 | folder_name = folder_name.replace(/#/g,' '); //Whitespaces has the # symbol in combo. |
---|
| 437 | |
---|
[1518] | 438 | this.dbGears.execute("insert into folders_sync (id_folder,folder_name,uid_usuario) values (?,?,?)",[folders[i].value,folder_name,account_id]); |
---|
| 439 | } |
---|
| 440 | this.dbGears.close(); |
---|
| 441 | formul.submit(); |
---|
| 442 | } |
---|
| 443 | |
---|
| 444 | mail_sync.prototype.fill_combos_of_folders = function(combo_sync) { |
---|
| 445 | var folders = expresso_local_messages.get_folders_to_sync(); |
---|
| 446 | |
---|
| 447 | for(var i=0;i<folders.length;i++) { |
---|
| 448 | var option = document.createElement('option'); |
---|
| 449 | option.value = folders[i][0]; |
---|
| 450 | if (folders[i][1].indexOf("/") != "-1") { |
---|
| 451 | final_pos = folders[i][1].lastIndexOf("/"); |
---|
| 452 | option.text =folders[i][1].substr(final_pos+1); |
---|
| 453 | } |
---|
| 454 | else |
---|
| 455 | option.text = folders[i][1]; |
---|
| 456 | try { |
---|
| 457 | combo_sync.add(option,null); |
---|
| 458 | }catch (ex) {// I.E |
---|
| 459 | combo_sync.add(option); |
---|
| 460 | } |
---|
| 461 | |
---|
| 462 | } |
---|
| 463 | } |
---|
| 464 | |
---|
| 465 | mail_sync.prototype.add_folder = function (select_sync_folders,select_available_folders) |
---|
| 466 | { |
---|
| 467 | var count_available_folders = select_available_folders.length; |
---|
| 468 | var count_sync_folders = select_sync_folders.options.length; |
---|
| 469 | var new_options = ''; |
---|
| 470 | |
---|
| 471 | for (i = 0 ; i < count_available_folders ; i++) |
---|
| 472 | { |
---|
| 473 | if (select_available_folders.options[i].selected) |
---|
| 474 | { |
---|
| 475 | if(document.all) |
---|
| 476 | { |
---|
| 477 | if ( (select_sync_folders.innerHTML.indexOf('value='+select_available_folders.options[i].value)) == '-1' ) |
---|
| 478 | { |
---|
| 479 | new_options += '<option value=' |
---|
| 480 | + select_available_folders.options[i].value |
---|
| 481 | + '>' |
---|
| 482 | + select_available_folders.options[i].text |
---|
| 483 | + '</option>'; |
---|
| 484 | } |
---|
| 485 | } |
---|
| 486 | else |
---|
| 487 | { |
---|
| 488 | if ( (select_sync_folders.innerHTML.indexOf('value="'+select_available_folders.options[i].value+'"')) == '-1' ) |
---|
| 489 | { |
---|
| 490 | new_options += '<option value=' |
---|
| 491 | + select_available_folders.options[i].value |
---|
| 492 | + '>' |
---|
| 493 | + select_available_folders.options[i].text |
---|
| 494 | + '</option>'; |
---|
| 495 | } |
---|
| 496 | } |
---|
| 497 | } |
---|
| 498 | } |
---|
| 499 | |
---|
| 500 | if (new_options != '') |
---|
| 501 | { |
---|
| 502 | select_sync_folders.innerHTML = ' ' + new_options + select_sync_folders.innerHTML; |
---|
| 503 | select_sync_folders.outerHTML = select_sync_folders.outerHTML; |
---|
| 504 | } |
---|
| 505 | } |
---|
| 506 | |
---|
| 507 | mail_sync.prototype.remove_folder = function(select_sync_folders) |
---|
| 508 | { |
---|
| 509 | for(var i = 0;i < select_sync_folders.options.length; i++) |
---|
| 510 | if(select_sync_folders.options[i].selected) |
---|
| 511 | select_sync_folders.options[i--] = null; |
---|
| 512 | } |
---|
| 513 | |
---|
| 514 | var expresso_mail_sync; |
---|
| 515 | expresso_mail_sync = new mail_sync(); |
---|
| 516 | |
---|