diff --git a/chrome/content/mailhops.js b/chrome/content/mailhops.js index 1200276..068bd94 100644 --- a/chrome/content/mailhops.js +++ b/chrome/content/mailhops.js @@ -8,7 +8,7 @@ var mailHops = { msgURI: null , isLoaded: false - , options: {'version':'MailHops Plugin 1.0.4','lan':'en','unit':'mi','api_url':'http://api.mailhops.com','debug':false} + , options: {'version':'MailHops Plugin 1.0.5','lan':'en','unit':'mi','api_url':'http://api.mailhops.com','debug':false} , message: { secure:[] } , client_location: null }; @@ -363,6 +363,9 @@ mailHops.lookupRoute = function(header_route){ if(mailHops.options.fkey != '') lookupURL += '&fkey='+mailHops.options.fkey; + if(mailHops.options.client_location != '') + lookupURL+='&c=0'; + mailHops.LOG(lookupURL); //check for cache diff --git a/chrome/content/pb-overlay.js b/chrome/content/pb-overlay.js index 4727963..a8d5741 100644 --- a/chrome/content/pb-overlay.js +++ b/chrome/content/pb-overlay.js @@ -302,8 +302,15 @@ var mailHopsDisplay = if(this.options.client_location){ var client_location = JSON.parse(this.options.client_location); - if(response.route[response.route.length-1].ip != client_location.route[0].ip) - response.route.push(client_location.route[0]); + //get distance from last route to client_location and add to response.distance.miles or kilometers + if(!response.route[response.route.length-1]['private']){ + if(this.options.unit=='km') + response.distance.kilometers += mailHopsUtils.getDistance(response.route[response.route.length-1],client_location.route[0],this.options.unit); + else + response.distance.miles += mailHopsUtils.getDistance(response.route[response.route.length-1],client_location.route[0],this.options.unit); + } + //push client location to the end of the route + response.route.push(client_location.route[0]); } for(var i=0; i 0){ - if(this.options.unit=='mi') - distanceText =' ( '+mailHopsUtils.addCommas(Math.round(response.distance.miles))+' mi traveled )'; - else - distanceText =' ( '+mailHopsUtils.addCommas(Math.round(response.distance.kilometers))+' km traveled )'; - } - else if(displayText=='') - displayText = ' Local message.'; + if(response.distance){ + if(this.options.unit=='km' && response.distance.kilometers > 0) + distanceText =' ( '+mailHopsUtils.addCommas(Math.round(response.distance.kilometers))+' km traveled )'; + else if(response.distance.miles > 0) + distanceText =' ( '+mailHopsUtils.addCommas(Math.round(response.distance.miles))+' mi traveled )'; + } + else if(displayText=='') + displayText = ' Local message.'; } if(header_route) diff --git a/chrome/content/tb-overlay.js b/chrome/content/tb-overlay.js index 31398ce..442b2c4 100644 --- a/chrome/content/tb-overlay.js +++ b/chrome/content/tb-overlay.js @@ -185,8 +185,15 @@ var mailHopsDisplay = if(this.options.client_location){ var client_location = JSON.parse(this.options.client_location); - if(response.route[response.route.length-1].ip != client_location.route[0].ip) - response.route.push(client_location.route[0]); + //get distance from last route to client_location and add to response.distance.miles or kilometers + if(!response.route[response.route.length-1]['private']){ + if(this.options.unit=='km') + response.distance.kilometers += mailHopsUtils.getDistance(response.route[response.route.length-1],client_location.route[0],this.options.unit); + else + response.distance.miles += mailHopsUtils.getDistance(response.route[response.route.length-1],client_location.route[0],this.options.unit); + } + //push client location to the end of the route + response.route.push(client_location.route[0]); } for(var i=0; i 0){ - if(this.options.unit=='mi') - distanceText =' ( '+mailHopsUtils.addCommas(Math.round(response.distance.miles))+' mi traveled )'; - else + if(response.distance){ + if(this.options.unit=='km' && response.distance.kilometers > 0) distanceText =' ( '+mailHopsUtils.addCommas(Math.round(response.distance.kilometers))+' km traveled )'; + else if(response.distance.miles > 0) + distanceText =' ( '+mailHopsUtils.addCommas(Math.round(response.distance.miles))+' mi traveled )'; } else if(displayText=='') displayText = ' Local message.'; } diff --git a/chrome/content/utils.js b/chrome/content/utils.js index 2ae628e..a6700f0 100644 --- a/chrome/content/utils.js +++ b/chrome/content/utils.js @@ -73,7 +73,7 @@ dnsbl: function(result,abbr){ case '127.0.0.3': if(abbr) return 'SBL'; - else + else return 'Static UBE sources, verified spam services and ROKSO spammers.'; case '127.0.0.4': @@ -82,14 +82,14 @@ dnsbl: function(result,abbr){ case '127.0.0.7': if(abbr) return 'XBL'; - else + else return 'Illegal 3rd party exploits, including proxies, worms and trojan exploits.'; case '127.0.0.10': case '127.0.0.11': if(abbr) return 'PBL'; - else + else return 'IP ranges which should not be delivering unauthenticated SMTP email.'; default: @@ -146,7 +146,7 @@ launchMap: function(route,options){ if(options.map_provider) lookupURL += '&mp='+options.map_provider; - window.openDialog("chrome://mailhops/content/mailhopsMap.xul","MailHops",'toolbar=no,location=no,directories=no,menubar=yes,scrollbars=yes,close=yes,width=1024,height=768,resizable=yes', {src: lookupURL}); + window.openDialog("chrome://mailhops/content/mailhopsMap.xul","MailHops",'toolbar=no,location=no,directories=no,menubar=yes,scrollbars=yes,close=yes,width=1024,height=768,resizable=yes', {src: lookupURL}); } }, @@ -177,6 +177,30 @@ getWeatherIcon: function(icon){ var hr = (new Date).getHours(); var time = (hr >= 4 && hr <= 18)?'day':'night'; return 'chrome://mailhops/content/images/weather/'+forecast_icons[icon][time]+'.png'; -} +}, -}; \ No newline at end of file +getDistance: function(from, to, unit) { + if(!from || !to || !from['lat'] || !to['lat']) + return 0; + + lat = parseFloat(from['lat']); + lon1 = parseFloat(from['lng']); + lat2 = parseFloat(to['lat']); + lon2 = parseFloat(to['lng']); + unit = unit || 'mi';//mi or km + + lat *= (Math.PI/180); + lon1 *= (Math.PI/180); + lat2 *= (Math.PI/180); + lon2 *= (Math.PI/180); + + dist = 2*Math.asin(Math.sqrt( Math.pow((Math.sin((lat-lat2)/2)),2) + Math.cos(lat)*Math.cos(lat2)*Math.pow((Math.sin((lon1-lon2)/2)),2))) * 6378.137; + + if (unit == 'mi') { + dist = (dist / 1.609344); + } + + return dist; + } + +}; diff --git a/install.rdf b/install.rdf index 5adbb2a..cac14db 100644 --- a/install.rdf +++ b/install.rdf @@ -5,7 +5,7 @@ 2 thunderbird@mailhops.com - 1.0.4 + 1.0.5 MailHops MailHops maps the route an email traveled to get to you. Using GeoIP it also displays distance traveled along with the location (city, state and country) of the sender.