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