home *** CD-ROM | disk | FTP | other *** search
- /***********************************************************
- Library - Web Update
-
- Notify web site update.
-
- @ver 0.2
- ***********************************************************/
- var DB_FILE_NAME = "wmn/wudata.txt";
-
- WebMailNotifier.prototype.loadDBFile=function(name){
- var str=WebMailNotifier.prototype.loadFile(name);
- str=str.split("\r\n");
- var data={};
- for(var i=0;i<str.length-1;i+=2){
- data[str[i]]=str[i+1].replace(/\\n/g,"\n").replace(/\\r/g,"\r");;
- }
- return data;
- }
-
- WebMailNotifier.prototype.saveDBFile=function(name,data){
- var str="";
- for(i in data) {
- str+=i+"\r\n";
- var d=data[i];
- if(!d)d="";
- d=d.replace(/\r/g,"\\r").replace(/\n/g,"\\n");
- str+=d+"\r\n";
- }
- WebMailNotifier.prototype.saveFile(name,str);
- }
- WebMailNotifier.prototype.wuGetVal=function(id,user,num){
- if(!this.fileDB){
- this.fileDB=this.loadDBFile(DB_FILE_NAME);
- }
- return this.fileDB[id+"\t"+user+"\t"+num];
- }
- WebMailNotifier.prototype.wuSetVal=function(id,user,num,val){
- if(!this.fileDB){
- this.fileDB=this.loadDBFile(DB_FILE_NAME);
- }
- this.fileDB[id+"\t"+user+"\t"+num]=val.toString();
- this.saveDBFile(DB_FILE_NAME,this.fileDB);
- }
- WebMailNotifier.prototype.wuCompare=function(obj){
- if(!this.fileDB){
- this.fileDB=this.loadDBFile(DB_FILE_NAME);
- }
- var fnd=obj.findString(obj.data);
- if(fnd){
- var key=obj.id+"\t"+obj.user;
- var db=this.fileDB;
- if(db[key+"\t0"]){
- for(var i=0;i<obj.cache;++i){
- if(db[key+"\t"+i]==fnd)return 0;
- }
- //no match
- obj.newData=fnd;
- return 1;
- }else{
- for(var i=0;i<obj.cache;++i){
- db[key+"\t"+i]=fnd;
- }
- this.saveDBFile(DB_FILE_NAME,this.fileDB);
- return 0;
- }
- }else{
- return -1;
- }
- }
- WebMailNotifier.prototype.wuCheckUpdate=function(obj){
- if(obj.newData){
- var db=this.fileDB;
- for(var i=obj.cache-1;i>0;--i){
- db[obj.id+"\t"+obj.user+"\t"+i]=db[obj.id+"\t"+obj.user+"\t"+(i-1)];
- }
- db[obj.id+"\t"+obj.user+"\t0"]=obj.newData;
- obj.newData=null;
- this.saveDBFile(DB_FILE_NAME,db);
- obj.mailCount=0;
- if(!this.newMailsOnly){
- obj.mailData.desc=obj.getDesc();
- this.setState(nsIWebMailNotifier.ST_MAILDATA,obj.ind);
- }
- return true;
- }
- return false;
- }
-
- function initUpdateHandler(handler){
- handler.cache=1;
- handler.initStage=ST_DATA;
- handler.start="";
- handler.capture="[\\s\\S]+";
- handler.end="";
- handler.timerMultiplier=3;
- handler.getCount=function(aData){
- return this.main.wuCompare(this);
- };
- handler.calcCount=function(){
- return this.mailCount;
- };
- handler.process=function (aHttpChannel, aData) {
- switch(this.stage){
- case ST_LOGIN_RES:
- this.stage=ST_DATA;
- case ST_DATA:
- if(this.runCount%this.timerMultiplier==0){
- ++this.runCount;
- break;
- }else{
- ++this.runCount;
- this.main.setState(nsIWebMailNotifier.ST_MAILDATA,this.ind);
- return true;
- }
- }
- return WebMailHandler.prototype.process.call(this,aHttpChannel, aData);
- };
-
- handler.getMailURL=function(){
- this.main.wuCheckUpdate(this);
- return this.mailURL;
- }
-
- handler.getDesc = function(){
- var aData=this.mailCount;
- return aData>0?"!":(aData==0?"=":"");
- }
- if(!handler.findString){
- handler.findString=function(aData){
- var reg=new RegExp(this.start+"("+this.capture+")"+this.end);
- var fnd=aData.match(reg);
- return fnd?fnd[1]:null;
- }
- }
- }
-