Index: sandbox/expressoMail1_2/MailArchiver/2.2/expressoMail1_2/js/MAQueryConfig.js
===================================================================
--- sandbox/expressoMail1_2/MailArchiver/2.2/expressoMail1_2/js/MAQueryConfig.js	(revision 4873)
+++ sandbox/expressoMail1_2/MailArchiver/2.2/expressoMail1_2/js/MAQueryConfig.js	(revision 4873)
@@ -0,0 +1,278 @@
+<!--
+/**
+ *MailArchiver Query Config API
+ *
+ *This api is intended to be used with MailArquiver JavaScript API.
+ *Basicly, it is responsable to provide a standard data format conversion
+ *to handle queryes under MailArquiver web services pooling. *
+ *
+ */
+
+
+//MailArchiver Query Config data structure
+var MAQueryConfig = function(){
+  this.lowerIndex = null;
+  this.upperIndex = null;
+  this.from = null;
+  this.to = null;
+  this.cc = null;
+  this.subject = null;
+  this.body = null;
+  this.date = null;
+  this.flag = null;
+  this.folder = null;
+  this.order = null;
+  this.defaults = null;
+}
+
+//Set up all criteria list received
+MAQueryConfig.prototype.setCriteriaList = function(cl){
+  for(var p in cl){
+    if(p.toLowerCase() == 'from')
+      this.setFrom(cl[p]);
+    if(p.toLowerCase() == 'to')
+      this.setTo(cl[p]);
+    if(p.toLowerCase() == 'cc')
+      this.setCc(cl[p]);
+    if(p.toLowerCase() == 'subject')
+      this.setSubject(cl[p]);
+    if(p.toLowerCase() == 'body')
+      this.setBody(cl[p]);
+    if(p.toLowerCase() == 'date')
+      this.setDate(cl[p]);
+    if(p.toLowerCase() == 'flags')
+      this.setFlags(cl[p]);
+    if(p.toLowerCase() == 'folder')
+      this.setFolder(cl[p]);
+    if(p.toLowerCase() == 'order')
+      this.setOrder(cl[p]);
+  }
+}
+
+MAQueryConfig.prototype.setDefaults = function(defaults){
+    this.defaults = defaults;
+}
+
+//PharseCriteria receives data to pharse structure format fields from, to, cc and subject
+MAQueryConfig.prototype.pharseCriteria = function(criteria, data){
+  var stdout = '"'+criteria+'":[';
+  if(data.equals)
+    stdout += '{"@equals":"'+data.equals+'"},';
+  if(data.equalsic)
+    stdout += '{"@equalsIgnoreCase":"'+data.equalsic+'"},';
+  if(data.like)
+    stdout += '{"@like":"'+data.like+'"},';
+  if(data.likeic)
+    stdout += '{"@likeIgnoreCase":"'+data.likeic+'"},';
+  var stdout = stdout.substr(0,stdout.length-1) + '],';
+  return(stdout);
+}
+
+//setbounds up and down
+MAQueryConfig.prototype.setBounds = function(low, high){
+  this.lowerIndex = '"@lowerIndex":"'+parseInt(low)+'",';
+  this.upperIndex = '"@upperIndex":"'+parseInt(high)+'",';
+}
+//From receives a array of structutred data, by the model
+MAQueryConfig.prototype.setFrom = function(data){
+  if(data.length <= 0){
+    this.from = null;
+    return;
+  }
+
+  subdata = this.pharseCriteria('from', data);
+  this.from = subdata;
+}
+
+//To receives a array of structutred data, by the model
+MAQueryConfig.prototype.setTo = function(data){
+  if(data.length <= 0){
+    this.to = null;
+    return;
+  }
+
+  subdata = this.pharseCriteria('to', data);
+  this.to = subdata;
+}
+
+//Cc data
+MAQueryConfig.prototype.setCc = function(data){
+  if(data.length <= 0){
+    this.cc = null;
+    return;
+  }
+
+  subdata = this.pharseCriteria('cc', data);
+  this.cc = subdata;
+}
+
+//Subject data
+MAQueryConfig.prototype.setSubject = function(sub){
+  if(sub.length <= 0){
+    this.subject = null;
+    return;
+  }
+
+  subdata = this.pharseCriteria('subject', sub);
+  this.subject = subdata;
+}
+
+//PREGMatch date format
+MAQueryConfig.prototype.validateDate = function (dat){
+ var dateregex = /^\d{1,2}(\-|\/|\.)\d{1,2}\1\d{4}$/;
+ if (dateregex.test(dat))
+   return true;
+ else
+   return false;
+}
+
+//PREGMatch time format
+MAQueryConfig.prototype.validateTime = function (tim){
+  //var timeregex = /^([1-9]|1[0-2]):[0-5]\d(:[0-5]\d(\.\d{1,3})?)?$/;
+  //var timeregex = /^[0-2][0-9]:[0-5][0-9]:[0-5][0-9]$/;
+  var timeregex = /^\d{1,2}[:]\d{2}([:]\d{2})?$/;
+  if (timeregex.test(tim))
+    return true;
+  else
+    return false;
+}
+
+//toStdDate returns date time as long. Format input:'DD/MM/YYYY HH:MM:SS'
+MAQueryConfig.prototype.toStdDate = function(dt){ 
+  if (dt.length <= 0)
+    return;
+
+  var date_time_picker = dt.split(" ");
+  var date_part = date_time_picker[0];
+  var time_part = date_time_picker[1];
+
+  if ((this.validateDate(date_part)) && (this.validateTime(time_part))){
+    var date_split = date_part.split("/");
+    var ddd = date_split[1]+'/'+date_split[0]+'/'+date_split[2] + ' ' + time_part;
+    var ndate = new Date(ddd);   
+    return(Date.parse(ndate));
+  }
+  else
+    return("");
+}
+
+//Date data
+MAQueryConfig.prototype.setDate = function(date_data){
+  if((!date_data.upper) && (!date_data.lower) && (!date_data.day)){
+    this.date = null;
+    return;
+  }
+
+  this.date = '"date":[';  
+  if(date_data.lower){
+    var dt1b = this.toStdDate(date_data.lower);
+    this.date += '{"@lower":"'+dt1b+'"},';
+  }
+  if(date_data.upper){
+    var dt2b = this.toStdDate(date_data.upper);
+    this.date += '{"@upper":"'+dt2b+'"},';
+  }
+  if(date_data.day){
+    var dt3b = this.toStdDate(date_data.day)
+    this.date += '{"@day":"'+dt3b+'"},';
+  }
+  this.date = this.date.substr(0,this.date.length-1) + '],';
+}
+
+//flags data
+MAQueryConfig.prototype.setFlags = function(flaglist){
+  if(flaglist.flags.length <= 0){
+    this.flag = null;
+    return;
+  }
+
+  this.flag = '"flag":[';
+  var flag_data = flaglist.flags.split(',');
+  if(flag_data.length > 0){
+    for(var k=0; k<flag_data.length; k++){
+      this.flag += '{"@value":"'+flag_data[k]+'"},'
+    }
+    this.flag = this.flag.substr(0,this.flag.length-1);
+  }
+  else{
+    this.flag += '{"@value":"'+flaglist.flags+'"},';
+  }
+  this.flag += '],';
+}
+
+//Folder data
+MAQueryConfig.prototype.setFolder = function(folderslist){
+  if(folderslist.folderlength <= 0){
+    this.folder = null;
+    return;
+  }
+
+  this.folder = '"folder":[';
+  var folder_data = folderslist.folder.split(',');
+  if(folder_data.length > 0){
+    for(var k=0; k<folder_data.length; k++){
+      this.folder += '{"@id":"'+folder_data[k]+'"},'
+    }
+    this.folder = this.folder.substr(0,this.folder.length-1);
+  }
+  else{
+    this.folder += '{"@id":"'+folderslist.folder+'"},';
+  }
+  this.folder += '],';
+}
+
+//Order criteria
+MAQueryConfig.prototype.setOrder = function(order){
+  if(order.length <= 0){
+    this.order = null;
+    return;
+  }
+
+  this.order = '"order":[';
+  for(var k in order){
+    if(k.toLowerCase().indexOf("date") != -1)
+      this.order += '{"@'+order[k]+'":"date"},';
+    if(k.toLowerCase().indexOf("from") != -1)
+      this.order += '{"@'+order[k]+'":"from"},';
+    if(k.toLowerCase().indexOf("subject") != -1)
+      this.order += '{"@'+order[k]+'":"subject"},';
+    if(k.toLowerCase().indexOf("size") != -1)
+      this.order += '{"@'+order[k]+'":"size"},';
+  }
+  this.order = this.order.substr(0,this.order.length-1) + ']';
+}
+
+//Body structrure
+MAQueryConfig.prototype.setBody = function(body_data){
+  if(body_data.length <= 0){
+    this.body = null;
+    return;
+  }
+  this.body = '"body":[';
+  for(var k in body_data){
+    if(k.toLowerCase() == "like")
+      this.body += '{"@like":"'+body_data[k]+'"},';
+    if(k.toLowerCase() == "likeic")
+      this.body += '{"@likeIgnoreCase":"'+body_data[k]+'"},';
+  }
+  this.body = this.body.substr(0,this.body.length-1) + '],';
+}
+
+//Query criteria (core api)
+MAQueryConfig.prototype.query = function(offsetlow,offsethight, criterialist){
+  this.setBounds(offsetlow, offsethight);
+  this.setCriteriaList(criterialist);
+  var querystring = '{"query":{' + this.lowerIndex + this.upperIndex;
+  querystring += this.from;
+  querystring += this.to;
+  querystring += this.cc;
+  querystring += this.subject;
+  querystring += this.body;
+  querystring += this.date;
+  querystring += this.flag;
+  querystring += this.folder;
+  querystring += this.order;
+  querystring += '}}';
+  return(querystring);
+}
+-->
