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" />
|
<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>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<div class="popup-page">
|
<div class="popup-page" style="max-width: 400px;">
|
||||||
<div id="hop-message" class="ui message">
|
<div id="hop-message" class="ui message">
|
||||||
<div id="hop-message-header" class="header" style="text-align: center;"></div>
|
<div id="hop-message-header" class="header" style="text-align: center;"></div>
|
||||||
</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) => {
|
messenger.messages.getFull(message.id).then((messagePart) => {
|
||||||
// get route
|
// get route
|
||||||
MailHops.init();
|
MailHops.init(message.id, messagePart.headers);
|
||||||
MailHops.message.id = message.id;
|
|
||||||
MailHops.message.headers = messagePart.headers;
|
|
||||||
MailHops.message.display = true;
|
|
||||||
MailHops.getRoute();
|
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
@ -7,6 +7,8 @@
|
|||||||
const MailHops = {
|
const MailHops = {
|
||||||
msgURI: null,
|
msgURI: null,
|
||||||
isLoaded: false,
|
isLoaded: false,
|
||||||
|
loading: false,
|
||||||
|
previousId: null,
|
||||||
options: {
|
options: {
|
||||||
version: 'MailHops Plugin 4.0.0',
|
version: 'MailHops Plugin 4.0.0',
|
||||||
api_key: '',
|
api_key: '',
|
||||||
@ -15,7 +17,7 @@ const MailHops = {
|
|||||||
unit: 'mi',
|
unit: 'mi',
|
||||||
api_http: 'https://',
|
api_http: 'https://',
|
||||||
api_host: 'api.Mailhops.com',
|
api_host: 'api.Mailhops.com',
|
||||||
debug: false,
|
debug: true,
|
||||||
country_tag: false,
|
country_tag: false,
|
||||||
travel_time_junk: true,
|
travel_time_junk: true,
|
||||||
country_filter: []
|
country_filter: []
|
||||||
@ -31,7 +33,8 @@ const MailHops = {
|
|||||||
icon: '/images/refresh.png'
|
icon: '/images/refresh.png'
|
||||||
, title: 'Loading...'
|
, title: 'Loading...'
|
||||||
, description: ''
|
, description: ''
|
||||||
}
|
},
|
||||||
|
error: ''
|
||||||
},
|
},
|
||||||
response: {},
|
response: {},
|
||||||
meta: {}
|
meta: {}
|
||||||
@ -39,12 +42,15 @@ const MailHops = {
|
|||||||
|
|
||||||
MailHops.LOG = function(msg) {
|
MailHops.LOG = function(msg) {
|
||||||
if(!MailHops.options.debug)
|
if(!MailHops.options.debug)
|
||||||
return;
|
return;
|
||||||
console.log('MailHops', msg);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
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();
|
var getting = browser.storage.local.get();
|
||||||
getting.then(data => {
|
getting.then(data => {
|
||||||
if (data.api_key) {
|
if (data.api_key) {
|
||||||
@ -62,13 +68,34 @@ MailHops.init = function(reload)
|
|||||||
if (typeof data.travel_time_junk != 'undefined') {
|
if (typeof data.travel_time_junk != 'undefined') {
|
||||||
MailHops.options.travel_time_junk = data.travel_time_junk == 'on' ? true : false;
|
MailHops.options.travel_time_junk = data.travel_time_junk == 'on' ? true : false;
|
||||||
}
|
}
|
||||||
MailHops.LOG('load MailHops prefs');
|
MailHops.LOG('load MailHops prefs');
|
||||||
}, error => {
|
// reset message
|
||||||
MailHops.LOG('Error loading MailHops prefs');
|
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 () {
|
MailHops.getRoute = function () {
|
||||||
|
if (MailHops.loading) return;
|
||||||
|
|
||||||
|
MailHops.loading = true;
|
||||||
// set loading icon
|
// set loading icon
|
||||||
browser.messageDisplayAction.setPopup({ popup: '' });
|
browser.messageDisplayAction.setPopup({ popup: '' });
|
||||||
browser.messageDisplayAction.setIcon({ path: '/images/refresh.png' });
|
browser.messageDisplayAction.setIcon({ path: '/images/refresh.png' });
|
||||||
@ -228,11 +255,15 @@ MailHops.clear = function () {
|
|||||||
};
|
};
|
||||||
browser.messageDisplayAction.setIcon({ path: MailHops.message.sender.icon });
|
browser.messageDisplayAction.setIcon({ path: MailHops.message.sender.icon });
|
||||||
browser.messageDisplayAction.setTitle({ title: MailHops.message.sender.title });
|
browser.messageDisplayAction.setTitle({ title: MailHops.message.sender.title });
|
||||||
if (browser.mailHopsUI)
|
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.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 = {
|
MailHops.message.sender = {
|
||||||
title: (data && data.error && data.error.message) ? data && data.error.message : 'Service Unavailable',
|
title: (data && data.error && data.error.message) ? data && data.error.message : 'Service Unavailable',
|
||||||
countryCode: '',
|
countryCode: '',
|
||||||
@ -241,7 +272,7 @@ MailHops.error = function(status, data){
|
|||||||
browser.messageDisplayAction.setIcon({ path: MailHops.message.sender.icon });
|
browser.messageDisplayAction.setIcon({ path: MailHops.message.sender.icon });
|
||||||
browser.messageDisplayAction.setTitle({ title: MailHops.message.sender.title });
|
browser.messageDisplayAction.setTitle({ title: MailHops.message.sender.title });
|
||||||
if (browser.mailHopsUI)
|
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) {
|
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
|
//SPF
|
||||||
if(header_spf){
|
if(header_spf){
|
||||||
header_spf = header_spf.replace(/^\s+/, "");
|
header_spf = header_spf.replace(/^\s+/, "");
|
||||||
|
var headerSPFArr=header_spf.split(' ');
|
||||||
auth.push({
|
auth.push({
|
||||||
type: 'SPF',
|
type: 'SPF',
|
||||||
color: 'green',
|
color: 'green',
|
||||||
icon: '/images/auth/' + headerSPFArr[0] + '.png',
|
icon: '/images/auth/' + headerSPFArr[0] + '.png',
|
||||||
copy: header_spf + '\n' + mailHopsUtils.spf(headerSPFArr[0])
|
copy: header_spf + '\n' + MailHopsUtils.spf(headerSPFArr[0])
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
//Authentication-Results
|
//Authentication-Results
|
||||||
@ -281,7 +313,7 @@ MailHops.auth = function (header_xmailer, header_useragent, header_xmimeole, hea
|
|||||||
type: 'DKIM',
|
type: 'DKIM',
|
||||||
color: 'green',
|
color: 'green',
|
||||||
icon: '/images/auth/' + dkimArr[0].replace('dkim=','') + '.png',
|
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){
|
if(spf_result){
|
||||||
@ -291,7 +323,7 @@ MailHops.auth = function (header_xmailer, header_useragent, header_xmimeole, hea
|
|||||||
type: 'SPF',
|
type: 'SPF',
|
||||||
color: 'green',
|
color: 'green',
|
||||||
icon: '/images/auth/' + spfArr[0].replace('spf=','') + '.png',
|
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',
|
color: 'grey',
|
||||||
link: header_unsubscribe.replace('<','').replace('>','')
|
link: header_unsubscribe.replace('<','').replace('>','')
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
console.log(auth);
|
|
||||||
return auth;
|
return auth;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -342,8 +373,7 @@ var xmlhttp = new XMLHttpRequest();
|
|||||||
browser.mailHopsUI.insertBefore("", '/images/local.png', 'Local', "countryIcon", "expandedHeaders2");
|
browser.mailHopsUI.insertBefore("", '/images/local.png', 'Local', "countryIcon", "expandedHeaders2");
|
||||||
}
|
}
|
||||||
//tag the result
|
//tag the result
|
||||||
MailHops.tagResults(data, data.response.route);
|
MailHops.tagResults(data, data.response.route);
|
||||||
MailHops.isLoaded = true;
|
|
||||||
} else if(data.error){
|
} else if(data.error){
|
||||||
MailHops.LOG(JSON.stringify(data.error));
|
MailHops.LOG(JSON.stringify(data.error));
|
||||||
//display the error
|
//display the error
|
||||||
@ -352,8 +382,10 @@ var xmlhttp = new XMLHttpRequest();
|
|||||||
} catch(e){
|
} catch(e){
|
||||||
MailHops.LOG(e);
|
MailHops.LOG(e);
|
||||||
MailHops.error();
|
MailHops.error();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
MailHops.isLoaded = true;
|
||||||
|
MailHops.loading = false;
|
||||||
};
|
};
|
||||||
xmlhttp.send(null);
|
xmlhttp.send(null);
|
||||||
};
|
};
|
||||||
@ -371,6 +403,6 @@ MailHops.tagResults = function(results, route){
|
|||||||
MailHops.LOG( "Junk: Travel time match" );
|
MailHops.LOG( "Junk: Travel time match" );
|
||||||
}
|
}
|
||||||
} catch(e){
|
} 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) {
|
port.onMessage.addListener(function(msg) {
|
||||||
updateContent(msg);
|
updateContent(msg);
|
||||||
console.log(msg.message.map_url)
|
|
||||||
document.getElementById("mh-map-button").addEventListener("click", function () {
|
document.getElementById("mh-map-button").addEventListener("click", function () {
|
||||||
browser.tabs.create({ url: msg.message.map_url });
|
browser.tabs.create({ url: msg.message.map_url });
|
||||||
});
|
});
|
||||||
@ -15,6 +14,15 @@ document.getElementById("mh-options-button").addEventListener("click", function
|
|||||||
|
|
||||||
function updateContent(msg) {
|
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 route = msg.response.route || [];
|
||||||
const sender = msg.message.sender || null;
|
const sender = msg.message.sender || null;
|
||||||
const unit = msg.unit || "mi";
|
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/>';
|
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) {
|
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)
|
if (route[i].host)
|
||||||
description += route[i].host;
|
description += route[i].host;
|
||||||
if (route[i].whois && route[i].whois.descr)
|
if (route[i].whois && route[i].whois.descr)
|
||||||
description += route[i].whois.descr;
|
description += route[i].whois.descr;
|
||||||
if (route[i].whois && route[i].whois.netname)
|
if (route[i].whois && route[i].whois.netname)
|
||||||
@ -93,11 +101,9 @@ function updateContent(msg) {
|
|||||||
}
|
}
|
||||||
// hop list
|
// hop list
|
||||||
document.getElementById('hop-list').innerHTML = items.join('');
|
document.getElementById('hop-list').innerHTML = items.join('');
|
||||||
document.getElementById('mh-auth').innerHTML = auth;
|
try {
|
||||||
}
|
document.getElementById('mh-auth').innerHTML = auth;
|
||||||
|
} catch (error) {
|
||||||
function doOpenURL(url) {
|
console.error('MailHops', error);
|
||||||
if (url) {
|
|
||||||
browser.tabs.create({ url: url });
|
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -54,8 +54,7 @@ var mailHopPreferences = {
|
|||||||
document.getElementById("unit_km").setAttribute('checked', 'checked');
|
document.getElementById("unit_km").setAttribute('checked', 'checked');
|
||||||
} else {
|
} else {
|
||||||
document.getElementById("unit_mi").setAttribute('checked', 'checked');
|
document.getElementById("unit_mi").setAttribute('checked', 'checked');
|
||||||
}
|
}
|
||||||
console.log(data.travel_time_junk)
|
|
||||||
if (typeof data.travel_time_junk != 'undefined') {
|
if (typeof data.travel_time_junk != 'undefined') {
|
||||||
if (data.travel_time_junk == 'on')
|
if (data.travel_time_junk == 'on')
|
||||||
document.getElementById("travel_time_junk_on").setAttribute('checked', 'checked');
|
document.getElementById("travel_time_junk_on").setAttribute('checked', 'checked');
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
"manifest_version": 2,
|
"manifest_version": 2,
|
||||||
"name": "__MSG_appName__",
|
"name": "__MSG_appName__",
|
||||||
"description": "__MSG_appDesc__",
|
"description": "__MSG_appDesc__",
|
||||||
"version": "4.0.1",
|
"version": "4.0.2",
|
||||||
"author": "Hopsware LLC",
|
"author": "Hopsware LLC",
|
||||||
"developer": {
|
"developer": {
|
||||||
"name": "Andrew Van Tassel",
|
"name": "Andrew Van Tassel",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user