diff --git a/chrome/content/mailhops.js b/chrome/content/mailhops.js index 903d126..91c8863 100644 --- a/chrome/content/mailhops.js +++ b/chrome/content/mailhops.js @@ -188,12 +188,15 @@ mailHops.getRoute = function(){ if (!!headReceived){ var received_ips = new Array(); var headReceivedArr = headReceived.split('\n'); - for( var h=0; h < headReceivedArr.length; h++ ) { - //build the received line by concat until semi-colon ; date/time + for( var h=0; h < headReceivedArr.length; h++ ) { + //build the received line by concat until semi-colon ; date/time rline += headReceivedArr[h]; if(headReceivedArr[h].indexOf(';')==-1) 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 received_ips = received_ips.filter(function(item, pos) { return received_ips.indexOf(item) == pos; @@ -221,6 +224,7 @@ mailHops.getRoute = function(){ all_ips.unshift( ip[0] ); } } + if ( all_ips.length ){ mailHops.lookupRoute ( all_ips ) ; } else { @@ -344,33 +348,32 @@ mailHops.lookupRoute = function(header_route){ } } -mailHops.LOG("Calling MailHops API: "+lookupURL); +mailHops.LOG(lookupURL); //call mailhops api for lookup var xmlhttp = new XMLHttpRequest(); xmlhttp.open("GET", lookupURL ,true); xmlhttp.onreadystatechange=function() { - if (xmlhttp.readyState==4) { + if (xmlhttp.readyState===4){ try { + mailHops.LOG(xmlhttp.status); var data = JSON.parse(xmlhttp.responseText); - if(data && data.meta.code==200){ + if(xmlhttp.status===200){ var d = new Date(); data.meta.cached = d.toISOString(); - //save the result mailHops.saveResults(JSON.stringify(data),data.response.route); - //display the result mailHopsDisplay.route(header_route, mailHops.message, data.response, data.meta, lookupURL); - } else { - mailHops.LOG("lookupRoute: "+JSON.stringify(data)); + } else if(data.error){ + mailHops.LOG(JSON.stringify(data)); //display the error - mailHopsDisplay.error(data); + mailHopsDisplay.error(xmlhttp.status,data); } } catch(e){ - mailHops.LOG("lookupRoute: Error "+JSON.stringify(e)); - mailHopsDisplay.error(); + mailHops.LOG(e); + mailHopsDisplay.error(); } } }; @@ -398,8 +401,7 @@ mailHops.saveResults = function(results,route){ msg.clear(); 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); if(!tagService) return; diff --git a/chrome/content/pb-overlay.js b/chrome/content/pb-overlay.js index 527615f..caafdaa 100644 --- a/chrome/content/pb-overlay.js +++ b/chrome/content/pb-overlay.js @@ -200,15 +200,12 @@ var mailHopsDisplay = } }, - error: function(data){ + error: function(status,data){ 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){ - this.resultTextDataPane.value = mailHopsUtils.error(data.meta.code); + this.resultTextDataPane.value = status+': '+data.error.message; this.resultTextDataPane.setAttribute('tooltiptext',data.error.message); } else { 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){ var client_location = JSON.parse(this.options.client_location); diff --git a/chrome/content/preferences.js b/chrome/content/preferences.js index 4414e38..370acd6 100644 --- a/chrome/content/preferences.js +++ b/chrome/content/preferences.js @@ -101,11 +101,22 @@ var mailHopPreferences = { 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') document.getElementById("mailhop.country_tag").checked = false; else 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() { 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)); //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_http", this.api_http.value); pref.setCharPref("mail.mailHops.api_host", this.api_host.value); @@ -149,33 +162,40 @@ var mailHopPreferences = { saveAPIKey: function() { - if(!!this.api_key && this.api_key != ''){ + if(!!this.api_key && this.api_key.value != ''){ var xmlhttp = new XMLHttpRequest(); var nativeJSON = Components.classes["@mozilla.org/dom/json;1"].createInstance(Components.interfaces.nsIJSON); 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.onreadystatechange=function() { - if (xmlhttp.readyState==4) { + if (xmlhttp.readyState===4) { try{ 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'); - } else if(!!data.meta.message){ - document.getElementById("key_details").innerHTML = data.meta.message; - } else { - document.getElementById("key_details").innerHTML = 'Invalid API Key'; + document.getElementById("key_details").setAttribute("valid","true"); + } else if(!!data.error){ + document.getElementById("mailhops-membership-link").value='Join MailHops'; + 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){ document.getElementById("key_details").innerHTML = 'Connection Failed to\n '+apiBase+'!'; + document.getElementById("key_details").setAttribute("valid","false"); } } }; xmlhttp.send(null); } else { 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.onreadystatechange=function() { - if (xmlhttp.readyState==4) { + if (xmlhttp.readyState===4) { try{ var data = JSON.parse(xmlhttp.responseText); - if(!!data && data.meta.code==200){ + if(xmlhttp.status===200){ alert('Connection Succeeded to\n '+apiBase+'!'); } else { //display the error @@ -208,6 +228,6 @@ var mailHopPreferences = { ResetConnection: function(){ this.api_http.value=="https://"; this.api_http.selectedIndex = 0; - this.api_host.value='api.mailhops.com'; + this.api_host.value='api.mailhops.com'; } }; diff --git a/chrome/content/preferences.xul b/chrome/content/preferences.xul index f5a2982..4937f33 100644 --- a/chrome/content/preferences.xul +++ b/chrome/content/preferences.xul @@ -30,7 +30,7 @@ - API Key @@ -514,7 +514,7 @@ - MailHops API uses diff --git a/chrome/content/tb-overlay.js b/chrome/content/tb-overlay.js index 22ce6de..e2ce590 100644 --- a/chrome/content/tb-overlay.js +++ b/chrome/content/tb-overlay.js @@ -136,15 +136,12 @@ var mailHopsDisplay = } }, - error: function(data){ + error: function(status,data){ 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){ - this.resultText.setAttribute('value', mailHopsUtils.error(data.meta.code)); + this.resultText.setAttribute('value', status+': '+data.error.message); this.resultText.setAttribute('tooltiptext',data.error.message); } else { this.resultText.setAttribute('value', ' Service Unavailable.'); @@ -181,7 +178,7 @@ var mailHopsDisplay = 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){ var client_location = JSON.parse(this.options.client_location); diff --git a/chrome/content/utils.js b/chrome/content/utils.js index d53ef90..a95741f 100644 --- a/chrome/content/utils.js +++ b/chrome/content/utils.js @@ -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){ nStr += ''; var x = nStr.split('.'); diff --git a/chrome/skin/classic/pb-styles.css b/chrome/skin/classic/pb-styles.css index f2217a1..521e830 100644 --- a/chrome/skin/classic/pb-styles.css +++ b/chrome/skin/classic/pb-styles.css @@ -134,3 +134,20 @@ button { text-align: center; 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" +}