mirror of
https://github.com/MailHops/mailhops-plugin.git
synced 2025-05-17 23:00:10 -07:00
Added lookup cache
This commit is contained in:
parent
d3358943fa
commit
2f534a44ce
@ -6,6 +6,7 @@
|
||||
|
||||
var mailHops =
|
||||
{
|
||||
msgURI: null,
|
||||
resultTextDataPane: null,
|
||||
resultTextDataPane2: null,
|
||||
resultContainerDataPane: null,
|
||||
@ -25,8 +26,9 @@ var mailHops =
|
||||
|
||||
isLoaded: false,
|
||||
options: {'map':'goog','unit':'mi','api_url':'http://api.mailhops.com'},
|
||||
appVersion: 'MailHops Postbox 0.7.1',
|
||||
appVersion: 'MailHops Postbox 0.8',
|
||||
message: {secure:[]},
|
||||
client_location: null
|
||||
}
|
||||
|
||||
mailHops.init = function()
|
||||
@ -114,11 +116,17 @@ mailHops.loadPref = function()
|
||||
mailHops.options.use_private = mailHops.getCharPref('mail.mailHops.use_private','false')=='true'?true:false;
|
||||
mailHops.options.hosting = mailHops.getCharPref('mail.mailHops.hosting','personal');
|
||||
|
||||
mailHops.options.client_location = mailHops.getCharPref('mail.mailHops.client_location','');
|
||||
|
||||
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';
|
||||
|
||||
if(mailHops.options.client_location == ''){
|
||||
mailHops.setClientLocation();
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
mailHops.StreamListener =
|
||||
@ -177,7 +185,7 @@ mailHops.loadHeaderData = function()
|
||||
{
|
||||
return ;
|
||||
}
|
||||
|
||||
mailHops.msgURI = msgURI;
|
||||
var messenger = Components.classes["@mozilla.org/messenger;1"].createInstance ( Components.interfaces.nsIMessenger ) ;
|
||||
var msgService = messenger.messageServiceFromURI ( msgURI ) ;
|
||||
msgService.CopyMessage ( msgURI , mailHops.StreamListener , false , null , msgWindow , {} ) ;
|
||||
@ -250,7 +258,7 @@ var regexAllIp = /(1\d{0,2}|2(?:[0-4]\d{0,1}|[6789]|5[0-5]?)?|[3-9]\d?|0)\.(1\d{
|
||||
all_ips.unshift( ip[0] );
|
||||
}
|
||||
if ( all_ips.length != 0 ){
|
||||
mailHops.lookup ( all_ips ) ;
|
||||
mailHops.lookupRoute ( all_ips ) ;
|
||||
} else {
|
||||
mailHops.displayResult();
|
||||
}
|
||||
@ -279,9 +287,9 @@ mailHops.testIP = function(ip,header){
|
||||
//check if this IP was part of a secure transmission
|
||||
if(retval){
|
||||
if(header.indexOf('using SSL') != -1)
|
||||
mailHops.message.secure.push(ip+':'+header.substring(header.indexOf('using SSL'),11));
|
||||
mailHops.message.secure.push(ip+':'+header.substring(header.indexOf('using SSL'),header.indexOf('using TLS')+11));
|
||||
else if(header.indexOf('using TLS') != -1)
|
||||
mailHops.message.secure.push(ip+':'+header.substring(header.indexOf('using TLS'),11));
|
||||
mailHops.message.secure.push(ip+':'+header.substring(header.indexOf('using TLS'),header.indexOf('using TLS')+11));
|
||||
else if(header.indexOf('version=TLSv1/SSLv3') != -1)
|
||||
mailHops.message.secure.push(ip+':'+'using TLSv1/SSLv3');
|
||||
}
|
||||
@ -576,7 +584,12 @@ mailHops.displayResult = function ( header_route, response, meta, lookup_url ){
|
||||
document.getElementById('dataPaneMailHopsMetaContainer').style.display='none';
|
||||
}
|
||||
|
||||
if(response){
|
||||
if(response && response.route && response.route.length > 0){
|
||||
|
||||
if(mailHops.options.client_location){
|
||||
var client_location = JSON.parse(mailHops.options.client_location);
|
||||
response.route.push(client_location.route[0]);
|
||||
}
|
||||
|
||||
for(var i=0; i<response.route.length;i++){
|
||||
//get the first hop location
|
||||
@ -634,7 +647,7 @@ mailHops.displayResult = function ( header_route, response, meta, lookup_url ){
|
||||
if(secureToolTipText){
|
||||
var secure = document.createElement('label');
|
||||
secure.setAttribute('class','dataPaneAddressitem mailhopsSecure');
|
||||
secure.setAttribute('value','secured using '+secureToolTipText);
|
||||
secure.setAttribute('value','secured '+secureToolTipText);
|
||||
mailHops.resultDetails.appendChild(secure);
|
||||
}
|
||||
}
|
||||
@ -856,8 +869,35 @@ mailHops.getCharPref = function ( strName , strDefault ){
|
||||
return ( value ) ;
|
||||
};
|
||||
|
||||
mailHops.setClientLocation = function(){
|
||||
|
||||
var xmlhttp = new XMLHttpRequest();
|
||||
if (!pref){
|
||||
var pref = Components.classes["@mozilla.org/preferences-service;1"].getService ( Components.interfaces.nsIPrefBranch ) ;
|
||||
}
|
||||
|
||||
xmlhttp.open("GET", mailHops.options.api_url+'/v1/lookup/?tb&app='+mailHops.appVersion+'&r=&c=1',true);
|
||||
xmlhttp.onreadystatechange=function() {
|
||||
if (xmlhttp.readyState==4) {
|
||||
try{
|
||||
var data = JSON.parse(xmlhttp.responseText);
|
||||
if(data && data.meta.code==200){
|
||||
//display the result
|
||||
pref.setCharPref("mail.mailHops.client_location", JSON.stringify(data.response)) ;
|
||||
} else {
|
||||
pref.setCharPref("mail.mailHops.client_location", '') ;
|
||||
}
|
||||
}
|
||||
catch (e){
|
||||
pref.setCharPref("mail.mailHops.client_location", '') ;
|
||||
}
|
||||
}
|
||||
};
|
||||
xmlhttp.send(null);
|
||||
};
|
||||
|
||||
//mailhops lookup
|
||||
mailHops.lookup = function(header_route){
|
||||
mailHops.lookupRoute = function(header_route){
|
||||
|
||||
//setup loading
|
||||
mailHops.clearRoute();
|
||||
@ -865,13 +905,23 @@ mailHops.lookup = function(header_route){
|
||||
//import nativeJSON
|
||||
var nativeJSON = Components.classes["@mozilla.org/dom/json;1"].createInstance(Components.interfaces.nsIJSON);
|
||||
|
||||
//check for cache
|
||||
var cached_results=mailHops.getResults();
|
||||
|
||||
if(cached_results){
|
||||
cached_results = JSON.parse(cached_results);
|
||||
mailHops.displayResult(header_route,cached_results.response);
|
||||
return;
|
||||
}
|
||||
|
||||
//call mailhops api for lookup
|
||||
var xmlhttp = new XMLHttpRequest();
|
||||
|
||||
var lookupURL=mailHops.options.api_url+'/v1/lookup/?pb&app='+mailHops.appVersion+'&r='+String(header_route);
|
||||
|
||||
if(mailHops.options.show_weather)
|
||||
lookupURL+='&w=1';
|
||||
if(mailHops.options.client_location != '')
|
||||
lookupURL+='&c=0';
|
||||
|
||||
xmlhttp.open("GET", lookupURL ,true);
|
||||
xmlhttp.onreadystatechange=function() {
|
||||
@ -879,6 +929,8 @@ mailHops.lookup = function(header_route){
|
||||
try{
|
||||
var data = JSON.parse(xmlhttp.responseText);
|
||||
if(data && data.meta.code==200){
|
||||
//save the result
|
||||
mailHops.saveResults(JSON.stringify(data));
|
||||
//display the result
|
||||
mailHops.displayResult(header_route,data.response,data.meta, lookupURL);
|
||||
} else {
|
||||
@ -906,13 +958,11 @@ mailHops.addCommas = function(nStr){
|
||||
return x1 + x2;
|
||||
};
|
||||
mailHops.launchWhoIs = function(ip){
|
||||
var messenger = Components.classes["@mozilla.org/messenger;1"].createInstance();
|
||||
messenger = messenger.QueryInterface(Components.interfaces.nsIMessenger);
|
||||
var messenger = Components.classes["@mozilla.org/messenger;1"].createInstance().QueryInterface(Components.interfaces.nsIMessenger);
|
||||
messenger.launchExternalURL('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);
|
||||
var messenger = Components.classes["@mozilla.org/messenger;1"].createInstance().QueryInterface(Components.interfaces.nsIMessenger);
|
||||
messenger.launchExternalURL('http://www.spamhaus.org/query/bl?ip='+ip);
|
||||
};
|
||||
|
||||
@ -927,4 +977,33 @@ mailHops.launchMap = function(route){
|
||||
}
|
||||
};
|
||||
|
||||
mailHops.saveResults = function(results){
|
||||
|
||||
if(!mailHops.msgURI)
|
||||
return false;
|
||||
|
||||
var messenger = Components.classes["@mozilla.org/messenger;1"].createInstance().QueryInterface(Components.interfaces.nsIMessenger);
|
||||
var msgHdr = messenger.messageServiceFromURI(mailHops.msgURI).messageURIToMsgHdr(mailHops.msgURI);
|
||||
|
||||
if(!msgHdr)
|
||||
return false;
|
||||
|
||||
msgHdr.setStringProperty( "MH-Route", results );
|
||||
|
||||
};
|
||||
|
||||
mailHops.getResults = function(){
|
||||
|
||||
if(!mailHops.msgURI)
|
||||
return false;
|
||||
|
||||
var messenger = Components.classes["@mozilla.org/messenger;1"].createInstance().QueryInterface(Components.interfaces.nsIMessenger);
|
||||
var msgHdr = messenger.messageServiceFromURI(mailHops.msgURI).messageURIToMsgHdr(mailHops.msgURI);
|
||||
|
||||
if(!msgHdr)
|
||||
return false;
|
||||
|
||||
return msgHdr.getStringProperty( "MH-Route" );
|
||||
};
|
||||
|
||||
addEventListener ( "messagepane-loaded" , mailHops.setupEventListener , true ) ;
|
||||
|
@ -104,6 +104,8 @@ var mailHopPreferences =
|
||||
|
||||
this.api_url.value = pref.getCharPref("mail.mailHops.api_url",'http://api.mailhops.com');
|
||||
|
||||
ResetLocation(document.getElementById("mailhop.refresh_location"));
|
||||
|
||||
} ,
|
||||
savePreferences: function()
|
||||
{
|
||||
@ -137,7 +139,9 @@ function ChangePrivate(item){
|
||||
}
|
||||
}
|
||||
|
||||
function TestConnection(){
|
||||
function TestConnection(e){
|
||||
e.style.backgroundImage = 'url(chrome://mailhops/content/images/loader.gif)';
|
||||
|
||||
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';
|
||||
@ -147,13 +151,16 @@ function TestConnection(){
|
||||
try{
|
||||
var data = JSON.parse(xmlhttp.responseText);
|
||||
if(data && data.meta.code==200){
|
||||
e.style.backgroundImage='';
|
||||
alert('Connection Succeeded to '+mailHopPreferences.api_url.value+'!');
|
||||
} else {
|
||||
//display the error
|
||||
e.style.backgroundImage='';
|
||||
alert('Connection Failed to '+mailHopPreferences.api_url.value+'!');
|
||||
}
|
||||
}
|
||||
catch (ex){
|
||||
e.style.backgroundImage='';
|
||||
alert('Connection Failed to '+mailHopPreferences.api_url.value+'!');
|
||||
}
|
||||
}
|
||||
@ -161,6 +168,28 @@ function TestConnection(){
|
||||
xmlhttp.send(null);
|
||||
}
|
||||
|
||||
function ResetLocation(e){
|
||||
e.style.backgroundImage = 'url(chrome://mailhops/content/images/loader.gif)';
|
||||
document.getElementById("mailhop.client_location").value='Getting your location...';
|
||||
mailHops.setClientLocation();
|
||||
if(pref.getCharPref("mail.mailHops.client_location", '') != ''){
|
||||
var response = JSON.parse(pref.getCharPref("mail.mailHops.client_location", ''));
|
||||
var location = '';
|
||||
if(response.route[0].city)
|
||||
location+=response.route[0].city;
|
||||
if(response.route[0].state)
|
||||
location+=', '+response.route[0].state;
|
||||
if(response.route[0].countryName)
|
||||
location+=' ( '+response.route[0].countryName+' )';
|
||||
//set location
|
||||
document.getElementById("mailhop.client_location").value=location;
|
||||
//set country flag
|
||||
if(response.route[0].countryCode)
|
||||
document.getElementById("mailhop.client_location").style.backgroundImage='url(chrome://mailhops/content/images/flags/'+response.route[0].countryCode.toLowerCase()+'.png)';
|
||||
}
|
||||
e.style.backgroundImage='';
|
||||
}
|
||||
|
||||
function ResetConnection(){
|
||||
mailHopPreferences.api_url.value='http://api.mailhops.com';
|
||||
}
|
@ -19,6 +19,7 @@
|
||||
<tab label="Defaults"/>
|
||||
<tab label="Display"/>
|
||||
<tab label="Hosting"/>
|
||||
<tab label="My Location"/>
|
||||
</tabs>
|
||||
<tabpanels>
|
||||
<tabpanel>
|
||||
@ -75,9 +76,22 @@
|
||||
<checkbox id="mailhop.use_private" label="Yes, I Agree to MailHops terms of use for hosting my own MailHops API." checked="false" oncommand="ChangePrivate(this);"/>
|
||||
<label class="text-link" value="MailHops Terms of Use" 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" />
|
||||
<label class="text-link act" onclick="TestConnection(this);" value="Test Connection" />
|
||||
<label class="text-link act" onclick="ResetConnection();" value="Reset Connection" />
|
||||
</groupbox>
|
||||
</tabpanel>
|
||||
|
||||
<tabpanel>
|
||||
<groupbox>
|
||||
<caption label="My Location"/>
|
||||
<description>
|
||||
Your location is cached to reduce the number of lookups by one.
|
||||
</description>
|
||||
<label id="mailhop.client_location" class="act" value="Not Set" />
|
||||
<label id="mailhop.refresh_location" class="text-link act" onclick="ResetLocation(this);" value="Refresh your location" />
|
||||
</groupbox>
|
||||
</tabpanel>
|
||||
|
||||
</tabpanels>
|
||||
</tabbox>
|
||||
</vbox>
|
||||
|
@ -86,3 +86,5 @@
|
||||
#mailhopsDataPaneMeta label{
|
||||
padding-left: 20px;
|
||||
}
|
||||
|
||||
#mhTabs .act { padding-left: 20px; background-repeat: no-repeat; outline : none;}
|
@ -7,7 +7,7 @@
|
||||
<em:id>postbox@mailhops.com</em:id>
|
||||
<em:type>2</em:type>
|
||||
<em:name>MailHops</em:name>
|
||||
<em:version>0.7.1</em:version>
|
||||
<em:version>0.8</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>
|
||||
|
Binary file not shown.
BIN
mailhops-0.8-pb.xpi
Normal file
BIN
mailhops-0.8-pb.xpi
Normal file
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user