/** * @author diogenes */ /** * @param folders: * 1 - rowid of folder in sqlite * 2 - folder name in sqlite * 3 - ids to not download(for auto archiving) or ids to download(for archiving) * 4 - true for auto archiving and false for normal archiving. */ function mail_sync() { if (typeof(google) == 'undefined') return false; // this.dbGears = null; // this.localServer = null; // this.store = null; this.folders = new Array(); this.messages = null; this.attachs = null; this.url_attachs = null; this.working = false; this.is_auto = null; this.errors = new Array(); // this.main_title = null; this.main_title = null; this.dbGears = google.gears.factory.create('beta.database'); this.localServer = google.gears.factory.create('beta.localserver'); this.store = this.localServer.createStore('test-store'); this.update_folder = false; } mail_sync.prototype.open_conn = function(){ var db_in_other_use = true; var start_trying = new Date().getTime(); while (db_in_other_use) { try { this.dbGears.open('database-test'); db_in_other_use = false; } catch (ex) { if(new Date().getTime()-start_trying>10000) { //too much time trying, throw an exception throw ex; } } } } mail_sync.prototype.start_sync = function() { if (is_ie) connector.loadScript('TreeShow'); if(this.working) { //Já está sincronizando... return; } this.open_conn(); var rs = this.dbGears.execute("select id_folder,folder_name from folders_sync where uid_usuario=?",[account_id]); if(!rs.isValidRow()) { this.dbGears.close(); return; } this.working=true; this.messages = null; this.attachs = null; this.url_attachs = null; document.getElementById('main_title').innerHTML = get_lang("Creating folders structure"); while(rs.isValidRow()) { var temp = new Array(); temp[0] = rs.field(0); temp[1] = rs.field(1); temp[2] = null; temp[3] = false; 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]); while(rs2.isValidRow()) { if(temp[2]==null) temp[2]=rs2.field(0)+","; else temp[2]+=rs2.field(0)+","; rs2.next(); } this.folders.push(temp); //Criando estrutura de pastas... var folders_to_check = temp[0].split("/");//Todas as pastas tem ao menos INBOX/ if (folders_to_check.length == 1) var actual_check = "Inbox"; else { folders_to_check = folders_to_check.slice(1); var actual_check = folders_to_check[0]; } for (var i in folders_to_check) { var rs2 = this.dbGears.execute("select rowid from folder where folder=? and uid_usuario=?", [actual_check, account_id]); if (!rs2.isValidRow()) { if((!preferences.hide_folders) || (preferences.hide_folders=="0")) this.update_folder = true; //Precisa atualizar as pastas na arvore de pastas this.dbGears.execute("insert into folder (folder,uid_usuario) values (?,?)", [actual_check, account_id]); } if(parseInt(i)+10) { //TODO: Tratar melhor quando existirem erros... write_msg(get_lang("at least, one of selected mails is already archived, expresso tried to archive the others, check them later")); this.errors=new Array(); } window.setTimeout("eval('document.getElementById(\"main_title\").innerHTML =\"Expresso Mail\"')",3000); } } mail_sync.prototype.configure_sync = function(folders,formul) { this.dbGears = google.gears.factory.create('beta.database'); this.localServer = google.gears.factory.create('beta.localserver'); this.store = this.localServer.createStore('test-store'); this.dbGears.open('database-test'); this.dbGears.execute("delete from folders_sync where uid_usuario=?",[account_id]); for (var i=0;i' + select_available_folders.options[i].text + ''; } } else { if ( (select_sync_folders.innerHTML.indexOf('value="'+select_available_folders.options[i].value+'"')) == '-1' ) { new_options += ''; } } } } if (new_options != '') { select_sync_folders.innerHTML = ' ' + new_options + select_sync_folders.innerHTML; select_sync_folders.outerHTML = select_sync_folders.outerHTML; } } mail_sync.prototype.remove_folder = function(select_sync_folders) { for(var i = 0;i < select_sync_folders.options.length; i++) if(select_sync_folders.options[i].selected) select_sync_folders.options[i--] = null; } var expresso_mail_sync; expresso_mail_sync = new mail_sync();