From 7f26e8b12154c0a5a69c3044eaf45a9d6325ec7b Mon Sep 17 00:00:00 2001 From: Andrew Van Tassel Date: Fri, 4 May 2012 02:43:04 -0600 Subject: [PATCH] Added new prefs for hosting option Reformatted prefs into tabs --- chrome/content/mailhops.js | 111 +++++++++++++++++++------------- chrome/content/preferences.js | 112 ++++++++++++++++++++++++++++++++- chrome/content/preferences.xul | 80 +++++++++++++++++------ install.rdf | 2 +- 4 files changed, 242 insertions(+), 63 deletions(-) diff --git a/chrome/content/mailhops.js b/chrome/content/mailhops.js index 6fa6924..52c1dd8 100644 --- a/chrome/content/mailhops.js +++ b/chrome/content/mailhops.js @@ -18,14 +18,11 @@ var mailHops = mailhopsDataPaneMailer: null, mailhopsDataPaneDNSBL: null, mailhopsListContainer: null, + mailhopsAuthContainer: null, resultListDataPane: null, isLoaded: false, - showDetails: false, - showWeather: false, - showHost: false, - map: 'goog', - unit: 'mi', - appVersion: 'MailHops Postbox 0.6.9.2' + options: {'map':'goog','unit':'mi','api_url':'http://api.mailhops.com'}, + appVersion: 'MailHops Postbox 0.6.9.3' } mailHops.init = function() @@ -45,12 +42,14 @@ mailHops.init = function() mailHops.resultMapLink = document.getElementById ( "mailhopsDataPaneMapLink"); //auth + mailHops.mailhopsAuthContainer = document.getElementById ( "dataPaneMailHopsAuthContainer"); mailHops.mailhopsDataPaneSPF = document.getElementById ( "mailhopsDataPaneSPF"); mailHops.mailhopsDataPaneDKIM = document.getElementById ( "mailhopsDataPaneDKIM"); mailHops.mailhopsDataPaneMailer = document.getElementById ( "mailhopsDataPaneMailer"); mailHops.mailhopsDataPaneDNSBL = document.getElementById ( "mailhopsDataPaneDNSBL"); //list mailHops.mailhopsListContainer = document.getElementById ( "dataPaneMailHopsListContainer"); + mailHops.resultListDataPane = document.getElementById ( "mailhopsListDataPane"); //event listner for route click to launch map @@ -83,11 +82,33 @@ mailHops.init = function() mailHops.loadPref = function() { //get preferences - mailHops.map = mailHops.getCharPref('mail.mailHops.map','goog'); - mailHops.unit = mailHops.getCharPref('mail.mailHops.unit','mi'); - mailHops.showDetails = mailHops.getCharPref('mail.mailHops.show_details','false')=='true'?true:false; - mailHops.showWeather = mailHops.getCharPref('mail.mailHops.show_weather','false')=='true'?true:false; - mailHops.showHost = mailHops.getCharPref('mail.mailHops.show_host','false')=='true'?true:false; + mailHops.options.map = mailHops.getCharPref('mail.mailHops.map','goog'); + mailHops.options.unit = mailHops.getCharPref('mail.mailHops.unit','mi'); + + //Display Boxes + mailHops.options.show_details = mailHops.getCharPref('mail.mailHops.show_details','false')=='true'?true:false; + mailHops.options.show_auth = mailHops.getCharPref('mail.mailHops.show_auth','true')=='true'?true:false; + mailHops.options.show_lists = mailHops.getCharPref('mail.mailHops.show_lists','true')=='true'?true:false; + + //Details options + mailHops.options.show_host = mailHops.getCharPref('mail.mailHops.show_host','false')=='true'?true:false; + mailHops.options.show_weather = mailHops.getCharPref('mail.mailHops.show_weather','false')=='true'?true:false; + + //Auth options + mailHops.options.show_dkim = mailHops.getCharPref('mail.mailHops.show_dkim','true')=='true'?true:false; + mailHops.options.show_spf = mailHops.getCharPref('mail.mailHops.show_spf','true')=='true'?true:false; + mailHops.options.show_mailer = mailHops.getCharPref('mail.mailHops.show_mailer','true')=='true'?true:false; + mailHops.options.show_dnsbl = mailHops.getCharPref('mail.mailHops.show_dnsbl','true')=='true'?true:false; + + //Hosting + mailHops.options.use_private = mailHops.getCharPref('mail.mailHops.use_private','false')=='true'?true:false; + mailHops.options.hosting = mailHops.getCharPref('mail.mailHops.hosting','personal'); + + if(mailHops.options.use_private) + mailHops.options.api_url = mailHops.getCharPref('mail.mailHops.api_url','http://api.mailhops.com'); + else + mailHops.options.api_url='http://api.mailhops.com'; + }; mailHops.StreamListener = @@ -159,19 +180,26 @@ var regexAllIp = /(1\d{0,2}|2(?:[0-4]\d{0,1}|[6789]|5[0-5]?)?|[3-9]\d?|0)\.(1\d{ var headReceived = mailHops.headers.extractHeader ( "Received" , true ) ; var headXOrigIP = mailHops.headers.extractHeader ( "X-Originating-IP" , false ) ; - - var headXMailer = mailHops.headers.extractHeader ( "X-Mailer" , false ) ; - var headUserAgent = mailHops.headers.extractHeader ( "User-Agent" , false ) ; - var headXMimeOLE = mailHops.headers.extractHeader ( "X-MimeOLE" , false ) ; - var headReceivedSPF = mailHops.headers.extractHeader ( "Received-SPF" , false ) ; - var headAuth = mailHops.headers.extractHeader ( "Authentication-Results" , false ) ; - - var headListUnsubscribe = mailHops.headers.extractHeader ( "List-Unsubscribe" , false ) ; + //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; + var headReceivedSPF = (mailHops.options.show_auth && mailHops.options.show_spf) ? mailHops.headers.extractHeader ( "Received-SPF" , false ) : null; + var headAuth = mailHops.options.show_auth ? mailHops.headers.extractHeader ( "Authentication-Results" , false ) : null; + //lists box + var headListUnsubscribe = mailHops.options.show_lists ? mailHops.headers.extractHeader ( "List-Unsubscribe" , false ) : null; //display auth - mailHops.displayResultAuth(headXMailer,headUserAgent,headXMimeOLE,headAuth,headReceivedSPF); + if(mailHops.options.show_auth) + mailHops.displayResultAuth(headXMailer,headUserAgent,headXMimeOLE,headAuth,headReceivedSPF); + else + mailHops.mailhopsAuthContainer.style.display='none'; + //display unsubscribe link - mailHops.displayResultLists(headListUnsubscribe); + if(mailHops.options.show_lists) + mailHops.displayResultLists(headListUnsubscribe); + else + mailHops.mailhopsListContainer.style.display='none'; var received_ips; var all_ips = new Array(); @@ -309,7 +337,7 @@ mailHops.displayResultAuth = function( header_xmailer, header_useragent, header_ break; } } - if(dkim_result){ + if(mailHops.options.show_dkim && dkim_result){ dkim_result=dkim_result.replace(/^\s+/,""); var dkimArr=dkim_result.split(' '); mailHops.mailhopsDataPaneDKIM.setAttribute('value','DKIM: '+dkimArr[0].replace('dkim=','')); @@ -320,7 +348,7 @@ mailHops.displayResultAuth = function( header_xmailer, header_useragent, header_ else{ mailHops.mailhopsDataPaneDKIM.style.display='none'; } - if(spf_result){ + if(mailHops.options.show_spf && spf_result){ spf_result=spf_result.replace(/^\s+/,""); var spfArr=spf_result.split(' '); mailHops.mailhopsDataPaneSPF.setAttribute('value','SPF: '+spfArr[0].replace('spf=','')); @@ -386,7 +414,8 @@ switch(result){ case 'pass': return 'The message was signed, the signature or signatures were acceptable to the verifier, and the signature(s) passed verification tests.'; - case 'fail': + case 'fail': + case 'hardfail': return 'The message was signed and the signature or signatures were acceptable to the verifier, but they failed the verification test(s).'; case 'policy': @@ -538,7 +567,7 @@ mailHops.displayResult = function ( header_route, response ){ //build tooltip var tiptext = response.route[i].ip; - if(!mailHops.showHost){ + if(!mailHops.options.show_host){ if(response.route[i].host) tiptext+=' '+response.route[i].host; if(response.route[i].whois && response.route[i].whois.descr) @@ -553,14 +582,14 @@ mailHops.displayResult = function ( header_route, response ){ mailHops.resultDetails.appendChild(label); //append host - if(mailHops.showHost && response.route[i].host){ + if(mailHops.options.show_host && response.route[i].host){ var host = document.createElement('label'); host.setAttribute('value',response.route[i].host); mailHops.resultDetails.appendChild(host); } //append weather - if(mailHops.showWeather && response.route[i].weather){ + if(mailHops.options.show_weather && response.route[i].weather){ var weather = document.createElement('label'); if(response.route[i].weather.image){ var wimage = response.route[i].weather.image.split('/'); @@ -570,7 +599,7 @@ mailHops.displayResult = function ( header_route, response ){ wimage[5] = 'cloudy_night.png'; weather.style.backgroundImage = 'url(chrome://mailhops/content/images/weather/'+wimage[5]+')'; } - if(mailHops.unit=='mi') + if(mailHops.options.unit=='mi') weather.setAttribute('value',response.route[i].weather.cond+' '+response.route[i].weather.temp.F+'\u00B0F'); else weather.setAttribute('value',response.route[i].weather.cond+' '+response.route[i].weather.temp.C+'\u00B0C'); @@ -602,7 +631,7 @@ mailHops.displayResult = function ( header_route, response ){ else if(countryName) displayText = countryName; if(response.distance && response.distance.miles > 0){ - if(mailHops.unit=='mi') + if(mailHops.options.unit=='mi') distanceText =' ( '+mailHops.addCommas(Math.round(response.distance.miles))+' mi traveled )'; else distanceText =' ( '+mailHops.addCommas(Math.round(response.distance.kilometers))+' km traveled )'; @@ -631,7 +660,7 @@ mailHops.displayResult = function ( header_route, response ){ mailHops.resultDetailsLink.style.display = 'block'; mailHops.resultMapLink.style.display = 'block'; //show details by default - if(mailHops.showDetails){ + if(mailHops.options.show_details){ mailHops.resultContainerDetails.style.display = 'block'; mailHops.resultDetailsLink.setAttribute('class','text-link dataPaneMoreLink active'); } @@ -736,12 +765,8 @@ mailHops.unregisterObserver = function(){ mailHops.observe = function ( aSubject , aTopic , aData ) { - if ( aTopic != "nsPref:changed" ){ - return ; - } - - //load preferences - mailHops.loadPref(); + if ( aTopic == "nsPref:changed" ) + mailHops.loadPref(); }; mailHops.getCharPref = function ( strName , strDefault ){ @@ -771,9 +796,9 @@ mailHops.lookup = function(header_route){ //call mailhops api for lookup var xmlhttp = new XMLHttpRequest(); - var lookupURL='http://api.mailhops.com/v1/lookup/?pb&app='+mailHops.appVersion+'&r='+String(header_route); + var lookupURL=mailHops.options.api_url+'/v1/lookup/?pb&app='+mailHops.appVersion+'&r='+String(header_route); - if(mailHops.showWeather) + if(mailHops.options.show_weather) lookupURL+='&w=1'; xmlhttp.open("GET", lookupURL ,true); @@ -811,19 +836,19 @@ mailHops.addCommas = function(nStr){ mailHops.launchWhoIs = function(ip){ var messenger = Components.classes["@mozilla.org/messenger;1"].createInstance(); messenger = messenger.QueryInterface(Components.interfaces.nsIMessenger); - messenger.launchExternalURL('http://www.mailhops.com/whois/'+ip); + messenger.launchExternalURL(encodeURIComponent('http://www.mailhops.com/whois/'+ip)); }; mailHops.launchSpamHausURL = function(ip){ var messenger = Components.classes["@mozilla.org/messenger;1"].createInstance(); messenger = messenger.QueryInterface(Components.interfaces.nsIMessenger); - messenger.launchExternalURL('http://www.spamhaus.org/query/bl?ip='+ip); + messenger.launchExternalURL(encodeURIComponent('http://www.spamhaus.org/query/bl?ip='+ip)); }; mailHops.launchMap = function(route){ //launch mailhops api map - var lookupURL='http://api.mailhops.com/v1/map/?pb&app='+mailHops.appVersion+'&m='+mailHops.map+'&u='+mailHops.unit+'&r='+String(route); - if(mailHops.showWeather) + var lookupURL=mailHops.options.api_url+'/v1/map/?pb&app='+mailHops.appVersion+'&m='+mailHops.options.map+'&u='+mailHops.options.unit+'&r='+String(route); + if(mailHops.options.show_weather) lookupURL+='&w=1'; - var openwin = window.openDialog(lookupURL,"MailHops",'toolbar=no,location=no,directories=no,menubar=yes,scrollbars=yes,close=yes,width=732,height=332'); + var openwin = window.openDialog(encodeURIComponent(lookupURL),"MailHops",'toolbar=no,location=no,directories=no,menubar=yes,scrollbars=yes,close=yes,width=732,height=332'); openwin.focus(); }; diff --git a/chrome/content/preferences.js b/chrome/content/preferences.js index 47aceec..d9fb9a4 100644 --- a/chrome/content/preferences.js +++ b/chrome/content/preferences.js @@ -5,8 +5,20 @@ if (!pref) var mailHopPreferences = { + use_private: null, + + api_url: null, + + hosting: null, + loadPreferences: function() { + this.use_private = document.getElementById("mailhop.use_private"); + + this.api_url = document.getElementById("mailhop.api_url"); + + this.hosting = document.getElementById("mailhop.hosting"); + if(pref.getCharPref("mail.mailHops.map",'goog')=='goog') document.getElementById("mailhop.map").selectedIndex = 0; else @@ -16,12 +28,24 @@ var mailHopPreferences = document.getElementById("mailhop.unit").selectedIndex = 0; else document.getElementById("mailhop.unit").selectedIndex = 1; - + + //Display Box Options if(pref.getCharPref("mail.mailHops.show_details",'true')=='true') document.getElementById("mailhop.show_details").checked = true; else document.getElementById("mailhop.show_details").checked = false; + + if(pref.getCharPref("mail.mailHops.show_lists",'true')=='true') + document.getElementById("mailhop.show_lists").checked = true; + else + document.getElementById("mailhop.show_lists").checked = false; + if(pref.getCharPref("mail.mailHops.show_auth",'true')=='true') + document.getElementById("mailhop.show_auth").checked = true; + else + document.getElementById("mailhop.show_auth").checked = false; + + //Details Options if(pref.getCharPref("mail.mailHops.show_weather",'false')=='true') document.getElementById("mailhop.show_weather").checked = true; else @@ -32,6 +56,44 @@ var mailHopPreferences = else document.getElementById("mailhop.show_host").checked = false; + //Auth Options + if(pref.getCharPref("mail.mailHops.show_spf",'true')=='true') + document.getElementById("mailhop.show_spf").checked = true; + else + document.getElementById("mailhop.show_spf").checked = false; + + if(pref.getCharPref("mail.mailHops.show_dkim",'true')=='true') + document.getElementById("mailhop.show_dkim").checked = true; + else + document.getElementById("mailhop.show_dkim").checked = false; + + if(pref.getCharPref("mail.mailHops.show_mailer",'true')=='true') + document.getElementById("mailhop.show_mailer").checked = true; + else + document.getElementById("mailhop.show_mailer").checked = false; + + if(pref.getCharPref("mail.mailHops.show_dnsbl",'true')=='true') + document.getElementById("mailhop.show_dnsbl").checked = true; + else + document.getElementById("mailhop.show_dnsbl").checked = false; + + //Hosting Options + if(pref.getCharPref("mail.mailHops.hosting",'personal')=='personal') + document.getElementById("mailhop.hosting").selectedIndex = 0; + else if(pref.getCharPref("mail.mailHops.hosting",'personal')=='edu') + document.getElementById("mailhop.hosting").selectedIndex = 1; + else + document.getElementById("mailhop.hosting").selectedIndex = 2; + + if(pref.getCharPref("mail.mailHops.use_private",'false')=='true'){ + document.getElementById("mailhop.use_private").checked = true; + this.api_url.removeAttribute("disabled"); + } + else + document.getElementById("mailhop.use_private").checked = false; + + this.api_url.value = pref.getCharPref("mail.mailHops.api_url",'http://api.mailhops.com'); + } , savePreferences: function() { @@ -40,5 +102,53 @@ var mailHopPreferences = pref.setCharPref("mail.mailHops.show_details", String(document.getElementById("mailhop.show_details").checked)) ; pref.setCharPref("mail.mailHops.show_weather", String(document.getElementById("mailhop.show_weather").checked)) ; pref.setCharPref("mail.mailHops.show_host", String(document.getElementById("mailhop.show_host").checked)) ; + pref.setCharPref("mail.mailHops.show_spf", String(document.getElementById("mailhop.show_spf").checked)) ; + pref.setCharPref("mail.mailHops.show_dkim", String(document.getElementById("mailhop.show_dkim").checked)) ; + pref.setCharPref("mail.mailHops.show_mailer", String(document.getElementById("mailhop.show_mailer").checked)) ; + pref.setCharPref("mail.mailHops.show_dnsbl", String(document.getElementById("mailhop.show_dnsbl").checked)) ; + pref.setCharPref("mail.mailHops.show_lists", String(document.getElementById("mailhop.show_lists").checked)) ; + pref.setCharPref("mail.mailHops.show_auth", String(document.getElementById("mailhop.show_auth").checked)) ; + pref.setCharPref("mail.mailHops.use_private", String(document.getElementById("mailhop.use_private").checked)) ; + pref.setCharPref("mail.mailHops.hosting", document.getElementById("mailhop.hosting").selectedItem.value) ; + pref.setCharPref("mail.mailHops.api_url", String(document.getElementById("mailhop.api_url").value)) ; } } + +function ChangePrivate(item){ + if(item.checked){ + mailHopPreferences.api_url.removeAttribute("disabled"); + mailHopPreferences.api_url.focus(); + } + else{ + mailHopPreferences.api_url.setAttribute("disabled","true"); + mailHopPreferences.api_url.value='http://api.mailhops.com'; + } +} + +function TestConnection(){ + var xmlhttp = new XMLHttpRequest(); + var nativeJSON = Components.classes["@mozilla.org/dom/json;1"].createInstance(Components.interfaces.nsIJSON); + var lookupURL=mailHopPreferences.api_url.value+'/v1/lookup/?pb&app='+mailHops.appVersion+'&watchmouse'; + xmlhttp.open("GET", lookupURL ,true); + xmlhttp.onreadystatechange=function() { + if (xmlhttp.readyState==4) { + try{ + var data = JSON.parse(xmlhttp.responseText); + if(data && data.meta.code==200){ + alert('Connection Succeeded to '+mailHopPreferences.api_url.value+'!'); + } else { + //display the error + alert('Connection Failed to '+mailHopPreferences.api_url.value+'!'); + } + } + catch (ex){ + alert('Connection Failed to '+mailHopPreferences.api_url.value+'!'); + } + } + }; + xmlhttp.send(null); +} + +function ResetConnection(){ + mailHopPreferences.api_url.value='http://api.mailhops.com'; +} \ No newline at end of file diff --git a/chrome/content/preferences.xul b/chrome/content/preferences.xul index c3d7466..5134033 100644 --- a/chrome/content/preferences.xul +++ b/chrome/content/preferences.xul @@ -13,29 +13,73 @@