mirror of
https://github.com/MailHops/mailhops-plugin.git
synced 2025-05-21 08:30:23 -07:00
refactor message init, fixed spf dkim auth issue
This commit is contained in:
parent
e15efff0b6
commit
1d1c88ce27
@ -7,7 +7,7 @@
|
||||
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/fomantic-ui/2.8.7/semantic.min.css" integrity="sha512-g/MzOGVPy3OQ4ej1U+qe4D/xhLwUn5l5xL0Fa7gdC258ZWVJQGwsbIR47SWMpRxSPjD0tfu/xkilTy+Lhrl3xg==" crossorigin="anonymous" />
|
||||
</head>
|
||||
<body>
|
||||
<div class="popup-page">
|
||||
<div class="popup-page" style="max-width: 400px;">
|
||||
<div id="hop-message" class="ui message">
|
||||
<div id="hop-message-header" class="header" style="text-align: center;"></div>
|
||||
</div>
|
||||
|
6
js/bootstrap.js
vendored
6
js/bootstrap.js
vendored
@ -19,11 +19,7 @@ messenger.messageDisplay.onMessageDisplayed.addListener((tabId, message) => {
|
||||
|
||||
messenger.messages.getFull(message.id).then((messagePart) => {
|
||||
// get route
|
||||
MailHops.init();
|
||||
MailHops.message.id = message.id;
|
||||
MailHops.message.headers = messagePart.headers;
|
||||
MailHops.message.display = true;
|
||||
MailHops.getRoute();
|
||||
MailHops.init(message.id, messagePart.headers);
|
||||
});
|
||||
|
||||
});
|
||||
|
@ -7,6 +7,8 @@
|
||||
const MailHops = {
|
||||
msgURI: null,
|
||||
isLoaded: false,
|
||||
loading: false,
|
||||
previousId: null,
|
||||
options: {
|
||||
version: 'MailHops Plugin 4.0.0',
|
||||
api_key: '',
|
||||
@ -15,7 +17,7 @@ const MailHops = {
|
||||
unit: 'mi',
|
||||
api_http: 'https://',
|
||||
api_host: 'api.Mailhops.com',
|
||||
debug: false,
|
||||
debug: true,
|
||||
country_tag: false,
|
||||
travel_time_junk: true,
|
||||
country_filter: []
|
||||
@ -31,7 +33,8 @@ const MailHops = {
|
||||
icon: '/images/refresh.png'
|
||||
, title: 'Loading...'
|
||||
, description: ''
|
||||
}
|
||||
},
|
||||
error: ''
|
||||
},
|
||||
response: {},
|
||||
meta: {}
|
||||
@ -39,12 +42,15 @@ const MailHops = {
|
||||
|
||||
MailHops.LOG = function(msg) {
|
||||
if(!MailHops.options.debug)
|
||||
return;
|
||||
console.log('MailHops', msg);
|
||||
return;
|
||||
};
|
||||
|
||||
MailHops.init = function(reload)
|
||||
MailHops.init = function(id, headers)
|
||||
{
|
||||
// prevent multiple loading
|
||||
if (id == MailHops.previousId) return;
|
||||
previousId = id;
|
||||
|
||||
var getting = browser.storage.local.get();
|
||||
getting.then(data => {
|
||||
if (data.api_key) {
|
||||
@ -62,13 +68,34 @@ MailHops.init = function(reload)
|
||||
if (typeof data.travel_time_junk != 'undefined') {
|
||||
MailHops.options.travel_time_junk = data.travel_time_junk == 'on' ? true : false;
|
||||
}
|
||||
MailHops.LOG('load MailHops prefs');
|
||||
}, error => {
|
||||
MailHops.LOG('Error loading MailHops prefs');
|
||||
MailHops.LOG('load MailHops prefs');
|
||||
// reset message
|
||||
MailHops.message = {
|
||||
id: id
|
||||
, map_url: ''
|
||||
, time: null
|
||||
, secure: []
|
||||
, headers: headers
|
||||
, auth: []
|
||||
, sender: {
|
||||
icon: '/images/refresh.png'
|
||||
, title: 'Loading...'
|
||||
, description: ''
|
||||
},
|
||||
error: ''
|
||||
};
|
||||
MailHops.getRoute();
|
||||
}, (error) => {
|
||||
MailHops.LOG('Error loading MailHops prefs');
|
||||
MailHops.loading = false;
|
||||
});
|
||||
|
||||
};
|
||||
|
||||
MailHops.getRoute = function () {
|
||||
if (MailHops.loading) return;
|
||||
|
||||
MailHops.loading = true;
|
||||
// set loading icon
|
||||
browser.messageDisplayAction.setPopup({ popup: '' });
|
||||
browser.messageDisplayAction.setIcon({ path: '/images/refresh.png' });
|
||||
@ -228,11 +255,15 @@ MailHops.clear = function () {
|
||||
};
|
||||
browser.messageDisplayAction.setIcon({ path: MailHops.message.sender.icon });
|
||||
browser.messageDisplayAction.setTitle({ title: MailHops.message.sender.title });
|
||||
if (browser.mailHopsUI)
|
||||
browser.mailHopsUI.insertBefore("", MailHops.message.sender.icon, MailHops.message.sender.title, "countryIcon", "expandedHeaders2");
|
||||
if (browser.mailHopsUI) {
|
||||
browser.mailHopsUI.insertBefore("", MailHops.message.sender.icon, MailHops.message.sender.title, "countryIcon", "expandedHeaders2");
|
||||
}
|
||||
MailHops.isLoaded = true;
|
||||
MailHops.loading = false;
|
||||
}
|
||||
|
||||
MailHops.error = function(status, data){
|
||||
MailHops.error = function (status, data) {
|
||||
MailHops.message.error = (data && data.error && data.error.message) ? data && data.error.message : 'Service Unavailable';
|
||||
MailHops.message.sender = {
|
||||
title: (data && data.error && data.error.message) ? data && data.error.message : 'Service Unavailable',
|
||||
countryCode: '',
|
||||
@ -241,7 +272,7 @@ MailHops.error = function(status, data){
|
||||
browser.messageDisplayAction.setIcon({ path: MailHops.message.sender.icon });
|
||||
browser.messageDisplayAction.setTitle({ title: MailHops.message.sender.title });
|
||||
if (browser.mailHopsUI)
|
||||
browser.mailHopsUI.insertBefore("", MailHops.message.sender.icon, MailHops.message.sender.title, "countryIcon", "expandedHeaders2");
|
||||
browser.mailHopsUI.insertBefore("", MailHops.message.sender.icon, MailHops.message.sender.title, "countryIcon", "expandedHeaders2");
|
||||
}
|
||||
|
||||
MailHops.auth = function (header_xmailer, header_useragent, header_xmimeole, header_auth, header_spf, header_unsubscribe) {
|
||||
@ -249,11 +280,12 @@ MailHops.auth = function (header_xmailer, header_useragent, header_xmimeole, hea
|
||||
//SPF
|
||||
if(header_spf){
|
||||
header_spf = header_spf.replace(/^\s+/, "");
|
||||
var headerSPFArr=header_spf.split(' ');
|
||||
auth.push({
|
||||
type: 'SPF',
|
||||
color: 'green',
|
||||
icon: '/images/auth/' + headerSPFArr[0] + '.png',
|
||||
copy: header_spf + '\n' + mailHopsUtils.spf(headerSPFArr[0])
|
||||
copy: header_spf + '\n' + MailHopsUtils.spf(headerSPFArr[0])
|
||||
});
|
||||
}
|
||||
//Authentication-Results
|
||||
@ -281,7 +313,7 @@ MailHops.auth = function (header_xmailer, header_useragent, header_xmimeole, hea
|
||||
type: 'DKIM',
|
||||
color: 'green',
|
||||
icon: '/images/auth/' + dkimArr[0].replace('dkim=','') + '.png',
|
||||
copy: dkim_result + '\n' + mailHopsUtils.dkim(dkimArr[0].replace('dkim=', ''))
|
||||
copy: dkim_result + '\n' + MailHopsUtils.dkim(dkimArr[0].replace('dkim=', ''))
|
||||
});
|
||||
}
|
||||
if(spf_result){
|
||||
@ -291,7 +323,7 @@ MailHops.auth = function (header_xmailer, header_useragent, header_xmimeole, hea
|
||||
type: 'SPF',
|
||||
color: 'green',
|
||||
icon: '/images/auth/' + spfArr[0].replace('spf=','') + '.png',
|
||||
copy: spf_result + '\n' + mailHopsUtils.spf(spfArr[0].replace('spf=', ''))
|
||||
copy: spf_result + '\n' + MailHopsUtils.spf(spfArr[0].replace('spf=', ''))
|
||||
});
|
||||
}
|
||||
}
|
||||
@ -301,8 +333,7 @@ MailHops.auth = function (header_xmailer, header_useragent, header_xmimeole, hea
|
||||
color: 'grey',
|
||||
link: header_unsubscribe.replace('<','').replace('>','')
|
||||
});
|
||||
}
|
||||
console.log(auth);
|
||||
}
|
||||
return auth;
|
||||
}
|
||||
|
||||
@ -342,8 +373,7 @@ var xmlhttp = new XMLHttpRequest();
|
||||
browser.mailHopsUI.insertBefore("", '/images/local.png', 'Local', "countryIcon", "expandedHeaders2");
|
||||
}
|
||||
//tag the result
|
||||
MailHops.tagResults(data, data.response.route);
|
||||
MailHops.isLoaded = true;
|
||||
MailHops.tagResults(data, data.response.route);
|
||||
} else if(data.error){
|
||||
MailHops.LOG(JSON.stringify(data.error));
|
||||
//display the error
|
||||
@ -352,8 +382,10 @@ var xmlhttp = new XMLHttpRequest();
|
||||
} catch(e){
|
||||
MailHops.LOG(e);
|
||||
MailHops.error();
|
||||
}
|
||||
}
|
||||
}
|
||||
MailHops.isLoaded = true;
|
||||
MailHops.loading = false;
|
||||
};
|
||||
xmlhttp.send(null);
|
||||
};
|
||||
@ -371,6 +403,6 @@ MailHops.tagResults = function(results, route){
|
||||
MailHops.LOG( "Junk: Travel time match" );
|
||||
}
|
||||
} catch(e){
|
||||
MailHops.LOG("Error adding CountryCode tag: " + e);
|
||||
MailHops.LOG("Error tagging travel_time_junk: " + e);
|
||||
}
|
||||
};
|
@ -3,7 +3,6 @@ port.postMessage({ command: "details" });
|
||||
|
||||
port.onMessage.addListener(function(msg) {
|
||||
updateContent(msg);
|
||||
console.log(msg.message.map_url)
|
||||
document.getElementById("mh-map-button").addEventListener("click", function () {
|
||||
browser.tabs.create({ url: msg.message.map_url });
|
||||
});
|
||||
@ -15,6 +14,15 @@ document.getElementById("mh-options-button").addEventListener("click", function
|
||||
|
||||
function updateContent(msg) {
|
||||
|
||||
if (msg.message.error) {
|
||||
document.getElementById('hop-message').classList.add('warning');
|
||||
document.getElementById('mh-map-button').style.display = 'none';
|
||||
document.getElementById('hop-message-header').innerHTML = msg.message.error;
|
||||
return;
|
||||
}
|
||||
document.getElementById('hop-message').classList.remove('warning');
|
||||
document.getElementById('mh-map-button').style.display = 'inline-block';
|
||||
|
||||
const route = msg.response.route || [];
|
||||
const sender = msg.message.sender || null;
|
||||
const unit = msg.unit || "mi";
|
||||
@ -46,11 +54,11 @@ function updateContent(msg) {
|
||||
var description = '<a href="https://mailhops.com/whois/' + route[i].ip + '" target="_blank" title="Who Is?">' + route[i].ip + '</a><br/>';
|
||||
|
||||
if (msg.message.secure.indexOf(route[i].ip) !== -1) {
|
||||
description += '<img src="/images/auth/lock.png" title="Used TLS or SSL" />';
|
||||
description += '<img src="/images/auth/lock.png" title="Used TLS or SSL" /> ';
|
||||
}
|
||||
|
||||
if (route[i].host)
|
||||
description += route[i].host;
|
||||
description += route[i].host;
|
||||
if (route[i].whois && route[i].whois.descr)
|
||||
description += route[i].whois.descr;
|
||||
if (route[i].whois && route[i].whois.netname)
|
||||
@ -93,11 +101,9 @@ function updateContent(msg) {
|
||||
}
|
||||
// hop list
|
||||
document.getElementById('hop-list').innerHTML = items.join('');
|
||||
document.getElementById('mh-auth').innerHTML = auth;
|
||||
}
|
||||
|
||||
function doOpenURL(url) {
|
||||
if (url) {
|
||||
browser.tabs.create({ url: url });
|
||||
try {
|
||||
document.getElementById('mh-auth').innerHTML = auth;
|
||||
} catch (error) {
|
||||
console.error('MailHops', error);
|
||||
}
|
||||
}
|
||||
}
|
@ -54,8 +54,7 @@ var mailHopPreferences = {
|
||||
document.getElementById("unit_km").setAttribute('checked', 'checked');
|
||||
} else {
|
||||
document.getElementById("unit_mi").setAttribute('checked', 'checked');
|
||||
}
|
||||
console.log(data.travel_time_junk)
|
||||
}
|
||||
if (typeof data.travel_time_junk != 'undefined') {
|
||||
if (data.travel_time_junk == 'on')
|
||||
document.getElementById("travel_time_junk_on").setAttribute('checked', 'checked');
|
||||
|
@ -2,7 +2,7 @@
|
||||
"manifest_version": 2,
|
||||
"name": "__MSG_appName__",
|
||||
"description": "__MSG_appDesc__",
|
||||
"version": "4.0.1",
|
||||
"version": "4.0.2",
|
||||
"author": "Hopsware LLC",
|
||||
"developer": {
|
||||
"name": "Andrew Van Tassel",
|
||||
|
Loading…
x
Reference in New Issue
Block a user