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