mirror of
https://github.com/MailHops/mailhops-plugin.git
synced 2025-05-17 23:00:10 -07:00
Cleaned up error codes
Changed API response to look at http statusCode
This commit is contained in:
parent
2ba08ecd9f
commit
2711c33cb9
@ -194,6 +194,9 @@ mailHops.getRoute = function(){
|
|||||||
if(headReceivedArr[h].indexOf(';')==-1)
|
if(headReceivedArr[h].indexOf(';')==-1)
|
||||||
continue;
|
continue;
|
||||||
received_ips = rline.match(regexAllIp);
|
received_ips = rline.match(regexAllIp);
|
||||||
|
//continue if no IPs found
|
||||||
|
if(!received_ips)
|
||||||
|
continue;
|
||||||
//get unique IPs for each Received header
|
//get unique IPs for each Received header
|
||||||
received_ips = received_ips.filter(function(item, pos) {
|
received_ips = received_ips.filter(function(item, pos) {
|
||||||
return received_ips.indexOf(item) == pos;
|
return received_ips.indexOf(item) == pos;
|
||||||
@ -221,6 +224,7 @@ mailHops.getRoute = function(){
|
|||||||
all_ips.unshift( ip[0] );
|
all_ips.unshift( ip[0] );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( all_ips.length ){
|
if ( all_ips.length ){
|
||||||
mailHops.lookupRoute ( all_ips ) ;
|
mailHops.lookupRoute ( all_ips ) ;
|
||||||
} else {
|
} else {
|
||||||
@ -344,32 +348,31 @@ mailHops.lookupRoute = function(header_route){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
mailHops.LOG("Calling MailHops API: "+lookupURL);
|
mailHops.LOG(lookupURL);
|
||||||
|
|
||||||
//call mailhops api for lookup
|
//call mailhops api for lookup
|
||||||
var xmlhttp = new XMLHttpRequest();
|
var xmlhttp = new XMLHttpRequest();
|
||||||
|
|
||||||
xmlhttp.open("GET", lookupURL ,true);
|
xmlhttp.open("GET", lookupURL ,true);
|
||||||
xmlhttp.onreadystatechange=function() {
|
xmlhttp.onreadystatechange=function() {
|
||||||
if (xmlhttp.readyState==4) {
|
if (xmlhttp.readyState===4){
|
||||||
try {
|
try {
|
||||||
|
mailHops.LOG(xmlhttp.status);
|
||||||
var data = JSON.parse(xmlhttp.responseText);
|
var data = JSON.parse(xmlhttp.responseText);
|
||||||
if(data && data.meta.code==200){
|
if(xmlhttp.status===200){
|
||||||
var d = new Date();
|
var d = new Date();
|
||||||
data.meta.cached = d.toISOString();
|
data.meta.cached = d.toISOString();
|
||||||
|
|
||||||
//save the result
|
//save the result
|
||||||
mailHops.saveResults(JSON.stringify(data),data.response.route);
|
mailHops.saveResults(JSON.stringify(data),data.response.route);
|
||||||
|
|
||||||
//display the result
|
//display the result
|
||||||
mailHopsDisplay.route(header_route, mailHops.message, data.response, data.meta, lookupURL);
|
mailHopsDisplay.route(header_route, mailHops.message, data.response, data.meta, lookupURL);
|
||||||
} else {
|
} else if(data.error){
|
||||||
mailHops.LOG("lookupRoute: "+JSON.stringify(data));
|
mailHops.LOG(JSON.stringify(data));
|
||||||
//display the error
|
//display the error
|
||||||
mailHopsDisplay.error(data);
|
mailHopsDisplay.error(xmlhttp.status,data);
|
||||||
}
|
}
|
||||||
} catch(e){
|
} catch(e){
|
||||||
mailHops.LOG("lookupRoute: Error "+JSON.stringify(e));
|
mailHops.LOG(e);
|
||||||
mailHopsDisplay.error();
|
mailHopsDisplay.error();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -398,8 +401,7 @@ mailHops.saveResults = function(results,route){
|
|||||||
msg.clear();
|
msg.clear();
|
||||||
msg.appendElement(msgHdr, false);
|
msg.appendElement(msgHdr, false);
|
||||||
|
|
||||||
if(!!mailHops.options.country_tag)
|
if(!!mailHops.options.country_tag){
|
||||||
{
|
|
||||||
var tagService = Components.classes["@mozilla.org/messenger/tagservice;1"].getService(Components.interfaces.nsIMsgTagService);
|
var tagService = Components.classes["@mozilla.org/messenger/tagservice;1"].getService(Components.interfaces.nsIMsgTagService);
|
||||||
if(!tagService)
|
if(!tagService)
|
||||||
return;
|
return;
|
||||||
|
@ -200,15 +200,12 @@ var mailHopsDisplay =
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
error: function(data){
|
error: function(status,data){
|
||||||
this.resultMapLink.removeAttribute("route");
|
this.resultMapLink.removeAttribute("route");
|
||||||
if(data && data.meta.code==410)
|
|
||||||
this.resultTextDataPane.style.backgroundImage = 'url(chrome://mailhops/content/images/info.png)';
|
|
||||||
else
|
|
||||||
this.resultTextDataPane.style.backgroundImage = 'url(chrome://mailhops/content/images/auth/error.png)';
|
this.resultTextDataPane.style.backgroundImage = 'url(chrome://mailhops/content/images/auth/error.png)';
|
||||||
|
|
||||||
if(data && data.error){
|
if(data && data.error){
|
||||||
this.resultTextDataPane.value = mailHopsUtils.error(data.meta.code);
|
this.resultTextDataPane.value = status+': '+data.error.message;
|
||||||
this.resultTextDataPane.setAttribute('tooltiptext',data.error.message);
|
this.resultTextDataPane.setAttribute('tooltiptext',data.error.message);
|
||||||
} else {
|
} else {
|
||||||
this.resultTextDataPane.value = ' Service Unavailable.';
|
this.resultTextDataPane.value = ' Service Unavailable.';
|
||||||
@ -286,7 +283,7 @@ var mailHopsDisplay =
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if(response && response.route && response.route.length > 0){
|
if(response && response.route && response.route.length){
|
||||||
|
|
||||||
if(this.options.client_location){
|
if(this.options.client_location){
|
||||||
var client_location = JSON.parse(this.options.client_location);
|
var client_location = JSON.parse(this.options.client_location);
|
||||||
|
@ -101,11 +101,22 @@ var mailHopPreferences = {
|
|||||||
document.getElementById("country_"+this.country_filter[c]).checked=true;
|
document.getElementById("country_"+this.country_filter[c]).checked=true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if(!!this.api_key.value){
|
||||||
|
document.getElementById("mailhops-membership-link").value='My Account';
|
||||||
|
document.getElementById("mailhops-membership-link").setAttribute('data-account-url','https://mailhops.com/account/'+this.api_key.value);
|
||||||
|
}
|
||||||
if(pref.getCharPref("mail.mailHops.country_tag",'false')=='false')
|
if(pref.getCharPref("mail.mailHops.country_tag",'false')=='false')
|
||||||
document.getElementById("mailhop.country_tag").checked = false;
|
document.getElementById("mailhop.country_tag").checked = false;
|
||||||
else
|
else
|
||||||
document.getElementById("mailhop.country_tag").checked = true;
|
document.getElementById("mailhop.country_tag").checked = true;
|
||||||
|
|
||||||
|
document.getElementById("mailhops-membership-link").addEventListener("click", function () {
|
||||||
|
mailHopsUtils.launchExternalURL(this.getAttribute('data-account-url'));
|
||||||
|
});
|
||||||
|
document.getElementById("forecastio").addEventListener("click", function () {
|
||||||
|
mailHopsUtils.launchExternalURL('https://developer.forecast.io/');
|
||||||
|
});
|
||||||
|
this.saveAPIKey();
|
||||||
},
|
},
|
||||||
savePreferences: function() {
|
savePreferences: function() {
|
||||||
pref.setCharPref("mail.mailHops.lang", document.getElementById("mailhop.lang").selectedItem.value);
|
pref.setCharPref("mail.mailHops.lang", document.getElementById("mailhop.lang").selectedItem.value);
|
||||||
@ -123,6 +134,8 @@ var mailHopPreferences = {
|
|||||||
pref.setCharPref("mail.mailHops.debug", String(document.getElementById("mailhop.debug").checked));
|
pref.setCharPref("mail.mailHops.debug", String(document.getElementById("mailhop.debug").checked));
|
||||||
|
|
||||||
//API vars
|
//API vars
|
||||||
|
if(document.getElementById("key_details").getAttribute("valid") == "false")
|
||||||
|
this.api_key.value='';
|
||||||
pref.setCharPref("mail.mailHops.api_key", this.api_key.value);
|
pref.setCharPref("mail.mailHops.api_key", this.api_key.value);
|
||||||
pref.setCharPref("mail.mailHops.api_http", this.api_http.value);
|
pref.setCharPref("mail.mailHops.api_http", this.api_http.value);
|
||||||
pref.setCharPref("mail.mailHops.api_host", this.api_host.value);
|
pref.setCharPref("mail.mailHops.api_host", this.api_host.value);
|
||||||
@ -149,33 +162,40 @@ var mailHopPreferences = {
|
|||||||
|
|
||||||
saveAPIKey: function() {
|
saveAPIKey: function() {
|
||||||
|
|
||||||
if(!!this.api_key && this.api_key != ''){
|
if(!!this.api_key && this.api_key.value != ''){
|
||||||
var xmlhttp = new XMLHttpRequest();
|
var xmlhttp = new XMLHttpRequest();
|
||||||
var nativeJSON = Components.classes["@mozilla.org/dom/json;1"].createInstance(Components.interfaces.nsIJSON);
|
var nativeJSON = Components.classes["@mozilla.org/dom/json;1"].createInstance(Components.interfaces.nsIJSON);
|
||||||
var apiBase = this.api_http.value+this.api_host.value,
|
var apiBase = this.api_http.value+this.api_host.value,
|
||||||
accountURL = '/v2/accounts/?api_key='+this.api_key.value;
|
accountURL = '/v2/accounts/?api_key='+this.api_key.value,
|
||||||
|
api_key = this.api_key.value;
|
||||||
|
|
||||||
xmlhttp.open("GET", apiBase+accountURL,true);
|
xmlhttp.open("GET", apiBase+accountURL,true);
|
||||||
xmlhttp.onreadystatechange=function() {
|
xmlhttp.onreadystatechange=function() {
|
||||||
if (xmlhttp.readyState==4) {
|
if (xmlhttp.readyState===4) {
|
||||||
try{
|
try{
|
||||||
var data = JSON.parse(xmlhttp.responseText);
|
var data = JSON.parse(xmlhttp.responseText);
|
||||||
if(!!data && data.meta.code==200){
|
if(xmlhttp.status===200){
|
||||||
|
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").innerHTML = JSON.stringify(data.account).replace(/\,/g,'\n');
|
||||||
} else if(!!data.meta.message){
|
document.getElementById("key_details").setAttribute("valid","true");
|
||||||
document.getElementById("key_details").innerHTML = data.meta.message;
|
} else if(!!data.error){
|
||||||
} else {
|
document.getElementById("mailhops-membership-link").value='Join MailHops';
|
||||||
document.getElementById("key_details").innerHTML = 'Invalid API Key';
|
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");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (ex){
|
catch (ex){
|
||||||
document.getElementById("key_details").innerHTML = 'Connection Failed to\n '+apiBase+'!';
|
document.getElementById("key_details").innerHTML = 'Connection Failed to\n '+apiBase+'!';
|
||||||
|
document.getElementById("key_details").setAttribute("valid","false");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
xmlhttp.send(null);
|
xmlhttp.send(null);
|
||||||
} else {
|
} else {
|
||||||
document.getElementById("key_details").innerHTML = 'Enter a valid API key above.';
|
document.getElementById("key_details").innerHTML = 'Enter a valid API key above.';
|
||||||
|
document.getElementById("key_details").setAttribute("valid","false");
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -187,10 +207,10 @@ var mailHopPreferences = {
|
|||||||
|
|
||||||
xmlhttp.open("GET", apiBase+lookupURL,true);
|
xmlhttp.open("GET", apiBase+lookupURL,true);
|
||||||
xmlhttp.onreadystatechange=function() {
|
xmlhttp.onreadystatechange=function() {
|
||||||
if (xmlhttp.readyState==4) {
|
if (xmlhttp.readyState===4) {
|
||||||
try{
|
try{
|
||||||
var data = JSON.parse(xmlhttp.responseText);
|
var data = JSON.parse(xmlhttp.responseText);
|
||||||
if(!!data && data.meta.code==200){
|
if(xmlhttp.status===200){
|
||||||
alert('Connection Succeeded to\n '+apiBase+'!');
|
alert('Connection Succeeded to\n '+apiBase+'!');
|
||||||
} else {
|
} else {
|
||||||
//display the error
|
//display the error
|
||||||
|
@ -30,7 +30,7 @@
|
|||||||
<groupbox flex="1">
|
<groupbox flex="1">
|
||||||
<caption label="MailHops Membership"/>
|
<caption label="MailHops Membership"/>
|
||||||
<description>
|
<description>
|
||||||
API Key <label class="text-link plain" value="Get a membership" href="https://mailhops.com"/>
|
API Key <label id="mailhops-membership-link" class="text-link plain" value="Join MailHops" data-account-url="https://mailhops.com"/>
|
||||||
</description>
|
</description>
|
||||||
|
|
||||||
<grid flex="1">
|
<grid flex="1">
|
||||||
@ -514,7 +514,7 @@
|
|||||||
</grid>
|
</grid>
|
||||||
|
|
||||||
<description>
|
<description>
|
||||||
MailHops API uses <label class="text-link plain" value="Forecast.IO" href="https://developer.forecast.io/"/> to get the weather of the sender, register for an API Key to enable this feature.
|
MailHops API uses <label id="forecastio" class="text-link plain" value="Forecast.IO"/> to get the weather of the sender, register for an API Key to enable this feature.
|
||||||
</description>
|
</description>
|
||||||
|
|
||||||
<textbox id="mailhop.fkey" value=""/>
|
<textbox id="mailhop.fkey" value=""/>
|
||||||
|
@ -136,15 +136,12 @@ var mailHopsDisplay =
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
error: function(data){
|
error: function(status,data){
|
||||||
this.container.removeAttribute("route");
|
this.container.removeAttribute("route");
|
||||||
if(data && data.meta.code==410)
|
|
||||||
this.resultText.style.backgroundImage = 'url(chrome://mailhops/content/images/info.png)';
|
|
||||||
else
|
|
||||||
this.resultText.style.backgroundImage = 'url(chrome://mailhops/content/images/auth/error.png)';
|
this.resultText.style.backgroundImage = 'url(chrome://mailhops/content/images/auth/error.png)';
|
||||||
|
|
||||||
if(data && data.error){
|
if(data && data.error){
|
||||||
this.resultText.setAttribute('value', mailHopsUtils.error(data.meta.code));
|
this.resultText.setAttribute('value', status+': '+data.error.message);
|
||||||
this.resultText.setAttribute('tooltiptext',data.error.message);
|
this.resultText.setAttribute('tooltiptext',data.error.message);
|
||||||
} else {
|
} else {
|
||||||
this.resultText.setAttribute('value', ' Service Unavailable.');
|
this.resultText.setAttribute('value', ' Service Unavailable.');
|
||||||
@ -181,7 +178,7 @@ var mailHopsDisplay =
|
|||||||
this.resultDetails.removeChild(this.resultDetails.firstChild);
|
this.resultDetails.removeChild(this.resultDetails.firstChild);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(response && response.route && response.route.length > 0){
|
if(response && response.route && response.route.length){
|
||||||
|
|
||||||
if(this.options.client_location){
|
if(this.options.client_location){
|
||||||
var client_location = JSON.parse(this.options.client_location);
|
var client_location = JSON.parse(this.options.client_location);
|
||||||
|
@ -99,19 +99,6 @@ dnsbl: function(result,abbr){
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
error: function(error_code){
|
|
||||||
switch(error_code){
|
|
||||||
case 400:
|
|
||||||
return 'Missing route parameter';
|
|
||||||
case 410:
|
|
||||||
return 'Down for Maintenance';
|
|
||||||
case 500:
|
|
||||||
return 'Server Error';
|
|
||||||
default:
|
|
||||||
return 'Service Unavailable';
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
addCommas: function(nStr){
|
addCommas: function(nStr){
|
||||||
nStr += '';
|
nStr += '';
|
||||||
var x = nStr.split('.');
|
var x = nStr.split('.');
|
||||||
|
@ -134,3 +134,20 @@ button {
|
|||||||
text-align: center;
|
text-align: center;
|
||||||
color: #333;
|
color: #333;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@-webkit-keyframes pulsate{0%{-moz-transform:scale(.3);opacity:.2}100%{-moz-transform:scale(1.1);opacity:1}}@-webkit-keyframes pulsate{0%{-webkit-transform:scale(.3);opacity:.2}100%{-webkit-transform:scale(1.1);opacity:1}}@keyframes pulsate{0%{-webkit-transform:scale(.3);transform:scale(.3);opacity:.2}100%{-webkit-transform:scale(1.1);transform:scale(1.1);opacity:1}}.SmartStatus-container{max-width:165px;display:flex}.SmartStatus-iconContainer{padding:2px;flex:0 1 auto}.SmartStatus--success{color:#5CB85C;margin-bottom:20px;padding:0}.SmartStatus--failed{color:#D9534F;margin-top:20px;padding:0}.SmartStatus--running{color:#848992;margin-top:10px;padding:0;-webkit-animation:pulsate 1.5s linear infinite alternate;-moz-animation:pulsate 1.5s linear infinite alternate;animation:pulsate 1.5s linear infinite alternate}.SmartStatus-tooltip{text-align:left;max-width:250px;padding:10px;line-height:22px}.SmartStatus-tooltip--successful,.SmartStatus-tooltip--success{color:#5CB85C;padding-left:5px;padding-right:0;text-shadow:-1px -1px 0 #FFFFFF,1px -1px 0 #FFFFFF,-1px 1px 0 #FFFFFF,1px 1px 0 #FFFFFF}.SmartStatus-tooltip--failed{color:#D9534F;padding-left:5px;padding-right:0;text-shadow:-1px -1px 0 #FFFFFF,1px -1px 0 #FFFFFF,-1px 1px 0 #FFFFFF,1px 1px 0 #FFFFFF}.SmartStatus-tooltip--running{color:#161B1F;padding-left:5px;padding-right:0;text-shadow:-1px -1px 0 #FFFFFF,1px -1px 0 #FFFFFF,-1px 1px 0 #FFFFFF,1px 1px 0 #FFFFFF;-webkit-animation:pulsate 1.5s linear infinite alternate;-moz-animation:pulsate 1.5s linear infinite alternate;animation:pulsate 1.5s linear infinite alternate}
|
||||||
|
.running {
|
||||||
|
font-size: 13px;
|
||||||
|
animation: pulsate 1.5s linear infinite alternate;
|
||||||
|
color: #5CB85C;
|
||||||
|
}
|
||||||
|
.running:before {
|
||||||
|
content: "\f111"
|
||||||
|
}
|
||||||
|
.error {
|
||||||
|
font-size: 13px;
|
||||||
|
color: rgba(255,0,0,.6);
|
||||||
|
}
|
||||||
|
.error:before {
|
||||||
|
content: "\f111"
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user