diff --git a/chrome/content/mailhops.js b/chrome/content/mailhops.js
index b0eddcd..12b9bab 100644
--- a/chrome/content/mailhops.js
+++ b/chrome/content/mailhops.js
@@ -16,11 +16,12 @@ var mailHops =
'api_host':'api.mailhops.com',
'debug':false,
'country_tag':false,
+ 'travel_time_junk':false,
'country_filter':[]
},
message: {
secure:[]
- ,time: 0
+ ,time: null
}
};
@@ -86,6 +87,8 @@ mailHops.loadPref = function()
mailHops.options.country_tag = mailHops.getCharPref('mail.mailHops.country_tag','false')=='true'?true:false;
+ mailHops.options.travel_time_junk = mailHops.getCharPref('mail.mailHops.travel_time_junk','false')=='true'?true:false;
+
mailHops.options.country_filter = mailHops.getCharPref('mail.mailHops.country_filter',[]);
//init display
@@ -162,9 +165,10 @@ mailHops.getRoute = function(){
var regexIPV6 = /(::|(([a-fA-F0-9]{1,4}):){7}(([a-fA-F0-9]{1,4}))|(:(:([a-fA-F0-9]{1,4})){1,6})|((([a-fA-F0-9]{1,4}):){1,6}:)|((([a-fA-F0-9]{1,4}):)(:([a-fA-F0-9]{1,4})){1,6})|((([a-fA-F0-9]{1,4}):){2}(:([a-fA-F0-9]{1,4})){1,5})|((([a-fA-F0-9]{1,4}):){3}(:([a-fA-F0-9]{1,4})){1,4})|((([a-fA-F0-9]{1,4}):){4}(:([a-fA-F0-9]{1,4})){1,3})|((([a-fA-F0-9]{1,4}):){5}(:([a-fA-F0-9]{1,4})){1,2}))/;
var headReceived = mailHops.headers.extractHeader ( "Received" , true );
+ var headDate = mailHops.headers.extractHeader ( "Date" , true );
var headXReceived = mailHops.headers.extractHeader ( "X-Received" , false );
var headXOrigIP = mailHops.headers.extractHeader ( "X-Originating-IP" , false );
- //auth box
+ // auth box
var headXMailer = (mailHops.options.show_auth && mailHops.options.show_mailer) ? mailHops.headers.extractHeader ( "X-Mailer" , false ) : null;
var headUserAgent = (mailHops.options.show_auth && mailHops.options.show_mailer) ? mailHops.headers.extractHeader ( "User-Agent" , false ) : null;
var headXMimeOLE = (mailHops.options.show_auth && mailHops.options.show_mailer) ? mailHops.headers.extractHeader ( "X-MimeOLE" , false ) : null;
@@ -174,10 +178,10 @@ mailHops.getRoute = function(){
var headListUnsubscribe = mailHops.options.show_lists ? mailHops.headers.extractHeader ( "List-Unsubscribe" , false ) : null;
var all_ips = new Array();
- var rline = '',firstDate,lastDate;
+ var rline = '',firstDate=headDate,lastDate;
//empty secure and time
mailHops.message.secure = [];
- mailHops.message.time = 0;
+ mailHops.message.time = null;
if(mailHops.options.show_lists){
mailHopsDisplay.lists( headListUnsubscribe );
@@ -197,11 +201,12 @@ mailHops.getRoute = function(){
if(headReceivedArr[h].indexOf(';')==-1)
continue;
- // first and last dates are used to calculate time Traveled
+ // first and last dates are used to calculate time traveled
if(rline.indexOf(';')!==-1){
if(!lastDate)
lastDate = rline.substring(rline.indexOf(';')+1).trim();
- firstDate = rline.substring(rline.indexOf(';')+1).trim();
+ else
+ firstDate = rline.substring(rline.indexOf(';')+1).trim();
}
// parse IPs out of Received line
@@ -224,17 +229,21 @@ mailHops.getRoute = function(){
}
// parse dates
- if(firstDate.indexOf('(')!==-1)
+ if(firstDate && firstDate.indexOf('(')!==-1)
firstDate = firstDate.substring(0,firstDate.indexOf('(')).trim();
- if(lastDate.indexOf('(')!==-1)
+ if(lastDate && lastDate.indexOf('(')!==-1)
lastDate = lastDate.substring(0,lastDate.indexOf('(')).trim();
-
- try {
- firstDate = new Date(firstDate);
- lastDate = new Date(lastDate);
- mailHops.message.time = lastDate-firstDate;
- } catch(e){
- mailHops.LOG('parse time traveled dates Error: '+JSON.stringify(e));
+ if(firstDate && lastDate){
+ try {
+ firstDate = new Date(firstDate);
+ lastDate = new Date(lastDate);
+ mailHops.message.time = lastDate-firstDate;
+ } catch(e){
+ mailHops.LOG('travel dates parse Error: '+JSON.stringify(e));
+ mailHops.message.time = null;
+ }
+ } else {
+ mailHops.message.time = null;
}
//get the originating IP address
@@ -359,9 +368,9 @@ mailHops.lookupRoute = function(header_route){
if(mailHops.options.fkey != '')
lookupURL += '&fkey='+mailHops.options.fkey;
- if(mailHops.message.time > 0)
+ if(mailHops.message.time != null)
lookupURL += '&t='+mailHops.message.time;
-
+
//check for cache
var cached_results = mailHops.getResults();
@@ -424,7 +433,7 @@ mailHops.saveResults = function(results,route){
//Add tag
if(!!route){
try{
- var countryCode = mailHopsUtils.getXOriginatingCountryCode(route);
+ var countryCode = mailHopsUtils.getOriginatingCountryCode(route);
var msg = Components.classes["@mozilla.org/array;1"].createInstance(Components.interfaces.nsIMutableArray);
msg.clear();
msg.appendElement(msgHdr, false);
@@ -446,6 +455,10 @@ mailHops.saveResults = function(results,route){
msgHdr.folder.setJunkScoreForMessages(msg, "100");
}
}
+ // tag as junk if travel time is longer than 10 seconds
+ if(!!mailHops.options.travel_time_junk && mailHops.message.time != null && mailHops.message.time > 10000){
+ msgHdr.folder.setJunkScoreForMessages(msg, "100");
+ }
} catch(e){
mailHops.LOG( "Error adding CountryCode tag: "+e );
diff --git a/chrome/content/pb-overlay.js b/chrome/content/pb-overlay.js
index fe382ba..b17de44 100644
--- a/chrome/content/pb-overlay.js
+++ b/chrome/content/pb-overlay.js
@@ -269,19 +269,39 @@ var mailHopsDisplay =
}
//append meta
- if(this.options.show_meta){
- for(var index in meta){
- var mlabel = document.createElement('label');
- mlabel.setAttribute('value',index+': '+meta[index]);
- this.resultMeta.appendChild(mlabel);
- }
- var mlabel = document.createElement('label');
- mlabel.setAttribute('value','api url');
- mlabel.setAttribute('class','text-link');
- mlabel.setAttribute('href',lookup_url);
- this.resultMeta.appendChild(mlabel);
-
- }
+ try {
+ if(this.options.show_meta){
+ for(var i in meta){
+ var mlabel = document.createElement('label');
+ if(typeof meta[i] == 'object'){
+ mlabel.setAttribute('value',i+': ');
+ this.resultMeta.appendChild(mlabel);
+ for(var ii in meta[i]){
+ var mlabel = document.createElement('label');
+ if(ii=='reset'){
+ if(parseInt(meta[i][ii])/60 < 60)
+ mlabel.setAttribute('value',' '+ii+': '+Math.round(parseInt(meta[i][ii])/60).toString()+' min.');
+ else
+ mlabel.setAttribute('value',' '+ii+': '+Math.round(parseInt(meta[i][ii])/60/60).toString()+' hr.');
+ } else {
+ mlabel.setAttribute('value',' '+ii+': '+meta[i][ii]);
+ }
+ this.resultMeta.appendChild(mlabel);
+ }
+ } else {
+ mlabel.setAttribute('value',i+': '+meta[i]);
+ this.resultMeta.appendChild(mlabel);
+ }
+ }
+ var mlabel = document.createElement('label');
+ mlabel.setAttribute('value','api url');
+ mlabel.setAttribute('class','text-link');
+ mlabel.setAttribute('href',lookup_url);
+ this.resultMeta.appendChild(mlabel);
+ }
+ } catch(e){
+ // parseInt error?
+ }
if(response && response.route && response.route.length){
@@ -438,9 +458,9 @@ var mailHopsDisplay =
displayText = ' Local message.';
}
- if(message.time>0){
+ if(message.time != null){
message.time = message.time/1000;
- if(message.time<60)
+ if(message.time < 60)
distanceText += ' in '+message.time+' sec.';
else if(message.time<3600) //something is wrong if it takes this long
distanceText += ' in '+Math.round(message.time/60)+' min.';
@@ -455,7 +475,7 @@ var mailHopsDisplay =
this.resultTextDataPane.style.backgroundImage = 'url('+image+')';
this.resultTextDataPane.value = displayText;
-
+
if(distanceText){
this.resultTextDataPane2.style.display = 'block';
this.resultTextDataPane2.value = ' ( '+distanceText+' )';
diff --git a/chrome/content/preferences.js b/chrome/content/preferences.js
index 370acd6..a12a3ee 100644
--- a/chrome/content/preferences.js
+++ b/chrome/content/preferences.js
@@ -110,6 +110,11 @@ var mailHopPreferences = {
else
document.getElementById("mailhop.country_tag").checked = true;
+ if(pref.getCharPref("mail.mailHops.travel_time_junk",'false')=='false')
+ document.getElementById("mailhop.travel_time_junk").checked = false;
+ else
+ document.getElementById("mailhop.travel_time_junk").checked = true;
+
document.getElementById("mailhops-membership-link").addEventListener("click", function () {
mailHopsUtils.launchExternalURL(this.getAttribute('data-account-url'));
});
@@ -134,7 +139,7 @@ var mailHopPreferences = {
pref.setCharPref("mail.mailHops.debug", String(document.getElementById("mailhop.debug").checked));
//API vars
- if(document.getElementById("key_details").getAttribute("valid") == "false")
+ if(document.getElementById("plan").getAttribute("valid") == "false")
this.api_key.value='';
pref.setCharPref("mail.mailHops.api_key", this.api_key.value);
pref.setCharPref("mail.mailHops.api_http", this.api_http.value);
@@ -150,6 +155,7 @@ var mailHopPreferences = {
}
pref.setCharPref("mail.mailHops.country_filter", String(JSON.stringify(this.country_filter)));
pref.setCharPref("mail.mailHops.country_tag", String(document.getElementById("mailhop.country_tag").checked));
+ pref.setCharPref("mail.mailHops.travel_time_junk", String(document.getElementById("mailhop.travel_time_junk").checked));
return true;
},
@@ -159,7 +165,17 @@ var mailHopPreferences = {
document.getElementById("country_"+mailHopsUtils.countries[c]).checked=all;
}
},
-
+ planError: function(error){
+ document.getElementById("plan-error").style.display = 'block';
+ document.getElementById("plan-error").value=error;
+ document.getElementById("plan").value='';
+ document.getElementById("plan").setAttribute("valid","false");
+ document.getElementById("rate-limit").value='';
+ document.getElementById("rate-remaining").value='';
+ document.getElementById("rate-reset").value='';
+ document.getElementById("mailhops-membership-link").value='Join MailHops';
+ document.getElementById("mailhops-membership-link").setAttribute('data-account-url','https://mailhops.com');
+ },
saveAPIKey: function() {
if(!!this.api_key && this.api_key.value != ''){
@@ -167,35 +183,38 @@ var mailHopPreferences = {
var nativeJSON = Components.classes["@mozilla.org/dom/json;1"].createInstance(Components.interfaces.nsIJSON);
var apiBase = this.api_http.value+this.api_host.value,
accountURL = '/v2/accounts/?api_key='+this.api_key.value,
- api_key = this.api_key.value;
+ api_key = this.api_key.value,
+ self = this;
xmlhttp.open("GET", apiBase+accountURL,true);
xmlhttp.onreadystatechange=function() {
if (xmlhttp.readyState===4) {
- try{
+ try {
var data = JSON.parse(xmlhttp.responseText);
if(xmlhttp.status===200){
+ document.getElementById("plan-error").style.display = 'none';
+ // set plan info
+ document.getElementById("plan").value = "Plan: "+data.account.subscriptions.data[0].plan.id;
+ document.getElementById("plan").setAttribute("valid","true");
+ document.getElementById("rate-limit").value = "Limit: "+data.account.rate.limit;
+ document.getElementById("rate-remaining").value = "Remaining: "+data.account.rate.remaining;
+ if(data.account.rate.reset/60 < 60)
+ document.getElementById("rate-reset").value = "Resets in: "+Math.round(data.account.rate.reset/60)+" min.";
+ else
+ document.getElementById("rate-reset").value = "Resets in: "+Math.round(data.account.rate.reset/60/60)+" hr.";
document.getElementById("mailhops-membership-link").value='My Account';
document.getElementById("mailhops-membership-link").setAttribute('data-account-url','https://mailhops.com/account/'+api_key);
- document.getElementById("key_details").innerHTML = JSON.stringify(data.account).replace(/\,/g,'\n');
- document.getElementById("key_details").setAttribute("valid","true");
} else if(!!data.error){
- document.getElementById("mailhops-membership-link").value='Join MailHops';
- document.getElementById("mailhops-membership-link").setAttribute('data-account-url','https://mailhops.com');
- document.getElementById("key_details").innerHTML = xmlhttp.status+': '+data.error.message;
- document.getElementById("key_details").setAttribute("valid","false");
+ self.planError(xmlhttp.status+': '+data.error.message);
}
- }
- catch (ex){
- document.getElementById("key_details").innerHTML = 'Connection Failed to\n '+apiBase+'!';
- document.getElementById("key_details").setAttribute("valid","false");
+ } catch (e){
+ self.planError('Connection Failed to\n '+apiBase+'!');
}
}
};
xmlhttp.send(null);
} else {
- document.getElementById("key_details").innerHTML = 'Enter a valid API key above.';
- document.getElementById("key_details").setAttribute("valid","false");
+ this.planError('Enter a valid API key above.');
}
},
diff --git a/chrome/content/preferences.xul b/chrome/content/preferences.xul
index 4937f33..9434ff6 100644
--- a/chrome/content/preferences.xul
+++ b/chrome/content/preferences.xul
@@ -32,23 +32,35 @@
API Key
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -56,6 +68,8 @@
+
+
Mark messages as Junk from Countries checked below.
@@ -482,13 +496,13 @@
-
+
-
+
@@ -501,7 +515,7 @@
-
+
@@ -513,11 +527,13 @@
+
+
MailHops API uses to get the weather of the sender, register for an API Key to enable this feature.
-
+
diff --git a/chrome/content/tb-overlay.js b/chrome/content/tb-overlay.js
index b4572c3..d9b0cdf 100644
--- a/chrome/content/tb-overlay.js
+++ b/chrome/content/tb-overlay.js
@@ -301,16 +301,16 @@ var mailHopsDisplay =
displayText = ' Local message.';
}
- if(message.time>0){
+ if(message.time != null){
message.time = message.time/1000;
- if(message.time<60)
+ if(message.time < 60)
distanceText += ' in '+message.time+' sec.';
else if(message.time<3600) //something is wrong if it takes this long
distanceText += ' in '+Math.round(message.time/60)+' min.';
else //something is wrong if it takes this long
distanceText += ' in '+Math.round(message.time/60/60)+' hrs.';
}
-
+
if(header_route)
this.mapLink.setAttribute("data-route", header_route);
else
diff --git a/chrome/content/utils.js b/chrome/content/utils.js
index a95741f..b0ca673 100644
--- a/chrome/content/utils.js
+++ b/chrome/content/utils.js
@@ -202,17 +202,15 @@ getDistance: function(from, to, unit) {
return dist;
},
- getXOriginatingCountryCode: function(route) {
- var countryCode = '';
+ getOriginatingCountryCode: function(route) {
if(route && route.length){
- route.forEach(function(e,i,arr){
- if(!route[i].local && !!route[i].countryCode){
- countryCode = route[i].countryCode;
- return;
+ for(var r=0; r