1
0
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:
Andrew Van Tassel 2020-11-11 15:25:33 -07:00
parent e15efff0b6
commit 1d1c88ce27
6 changed files with 73 additions and 40 deletions

View File

@ -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
View File

@ -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);
});
});

View File

@ -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: {}
@ -40,11 +43,14 @@ const MailHops = {
MailHops.LOG = function(msg) {
if(!MailHops.options.debug)
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();
getting.then(data => {
if (data.api_key) {
@ -63,12 +69,33 @@ MailHops.init = function(reload)
MailHops.options.travel_time_junk = data.travel_time_junk == 'on' ? true : false;
}
MailHops.LOG('load MailHops prefs');
}, error => {
// 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)
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: '',
@ -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=', ''))
});
}
}
@ -302,7 +334,6 @@ MailHops.auth = function (header_xmailer, header_useragent, header_xmimeole, hea
link: header_unsubscribe.replace('<','').replace('>','')
});
}
console.log(auth);
return auth;
}
@ -343,7 +374,6 @@ var xmlhttp = new XMLHttpRequest();
}
//tag the result
MailHops.tagResults(data, data.response.route);
MailHops.isLoaded = true;
} else if(data.error){
MailHops.LOG(JSON.stringify(data.error));
//display the error
@ -354,6 +384,8 @@ var xmlhttp = new XMLHttpRequest();
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);
}
};

View File

@ -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,7 +54,7 @@ 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)
@ -93,11 +101,9 @@ function updateContent(msg) {
}
// hop list
document.getElementById('hop-list').innerHTML = items.join('');
try {
document.getElementById('mh-auth').innerHTML = auth;
}
function doOpenURL(url) {
if (url) {
browser.tabs.create({ url: url });
} catch (error) {
console.error('MailHops', error);
}
}

View File

@ -55,7 +55,6 @@ var mailHopPreferences = {
} 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');

View File

@ -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",