1
0
mirror of https://github.com/MailHops/mailhops-plugin.git synced 2025-05-17 23:00:10 -07:00

Added new prefs for hosting option

Reformatted prefs into tabs
This commit is contained in:
Andrew Van Tassel 2012-05-04 02:43:04 -06:00
parent d2858eb09c
commit 7f26e8b121
4 changed files with 242 additions and 63 deletions

View File

@ -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();
};

View File

@ -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';
}

View File

@ -13,29 +13,73 @@
<script type="application/x-javascript" src="chrome://mailhops/content/mailhops.js"/>
<script type="application/x-javascript" src="chrome://mailhops/content/preferences.js"/>
<vbox width="200px">
<groupbox>
<vbox width="400px">
<tabbox id="mhTabs" selectedIndex="0">
<tabs>
<tab label="Defaults"/>
<tab label="Display"/>
<tab label="Authentication"/>
<tab label="Hosting"/>
</tabs>
<tabpanels>
<tabpanel>
<groupbox>
<caption label="Default Map"/>
<radiogroup id="mailhop.map">
<radio value="goog" label="Google" selected="true"/>
<radio value="bing" label="Bing"/>
</radiogroup>
</groupbox>
<groupbox>
<caption label="Default Unit"/>
<radiogroup id="mailhop.unit">
<radio value="mi" label="Miles" selected="true"/>
<radio value="km" label="Kilometers"/>
</radiogroup>
</groupbox>
<groupbox>
<caption label="Display Options"/>
<checkbox id="mailhop.show_details" label="Show Details" checked="false"/>
<checkbox id="mailhop.show_weather" label="Show Weather" checked="false"/>
<checkbox id="mailhop.show_host" label="Show Host" checked="false"/>
</groupbox>
</groupbox>
<groupbox>
<caption label="Default Unit"/>
<radiogroup id="mailhop.unit">
<radio value="mi" label="Miles" selected="true"/>
<radio value="km" label="Kilometers"/>
</radiogroup>
</groupbox>
</tabpanel>
<tabpanel>
<groupbox>
<caption label="Display Boxes"/>
<checkbox id="mailhop.show_details" label="Show Details" checked="false"/>
<checkbox id="mailhop.show_auth" label="Show Auth" checked="true"/>
<checkbox id="mailhop.show_lists" label="Show Unsubscribe Links" checked="true"/>
</groupbox>
<groupbox>
<caption label="Details Options"/>
<checkbox id="mailhop.show_host" label="Show Host" checked="false"/>
<checkbox id="mailhop.show_weather" label="Show Weather" checked="false"/>
</groupbox>
</tabpanel>
<tabpanel>
<groupbox>
<caption label="Authentication Options"/>
<checkbox id="mailhop.show_mailer" label="Show Mailer" checked="true"/>
<checkbox id="mailhop.show_spf" label="Show SPF" checked="true"/>
<checkbox id="mailhop.show_dkim" label="Show DKIM" checked="true"/>
<checkbox id="mailhop.show_dnsbl" label="Show DNS Blacklist" checked="true"/>
</groupbox>
</tabpanel>
<tabpanel>
<groupbox>
<caption label="MailHops API Hosting"/>
<description>
MailHops API is also available for download if you would like to host your own.
</description>
<radiogroup id="mailhop.hosting">
<radio value="personal" label="Personal (Free)" selected="true"/>
<radio value="edu" label="Educational (Free)"/>
<radio value="business" label="Business (Not-Free)"/>
</radiogroup>
<checkbox id="mailhop.use_private" label="Yes, I Agree to MailHops terms for the use of private hosting." checked="false" oncommand="ChangePrivate(this);"/>
<label class="text-link" value="MailHops Terms and Conditions" href="http://www.mailhops.com/terms"/>
<textbox id="mailhop.api_url" value="http://api.mailhops.com" disabled="true"/>
<label class="text-link" onclick="TestConnection();" value="Test Connection" /> <label class="text-link" onclick="ResetConnection();" value="Reset Connection" />
</groupbox>
</tabpanel>
</tabpanels>
</tabbox>
</vbox>
</dialog>

View File

@ -7,7 +7,7 @@
<em:id>postbox@mailhops.com</em:id>
<em:type>2</em:type>
<em:name>MailHops</em:name>
<em:version>0.6.9.2</em:version>
<em:version>0.6.9.3</em:version>
<em:description>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.</em:description>
<em:iconURL>chrome://mailhops/content/images/mailhops32.png</em:iconURL>
<em:homepageURL>http://mailhops.com</em:homepageURL>