1
0
mirror of https://github.com/MailHops/mailhops-plugin.git synced 2025-05-21 08:30:23 -07:00

Added message travel time

This commit is contained in:
Andrew Van Tassel 2016-09-21 23:16:36 -06:00
parent 2711c33cb9
commit 2b16798252
6 changed files with 132 additions and 72 deletions

View File

@ -1,24 +1,38 @@
# Change Log # Change Log
## [1.0.8] - 2016-5-25 ## 2.0.0 - 2016-9-10
### Added
- MailHops API v2
- MailHops API key for v2
- Security section in preferences
- Tag and mark as junk by CountryCode
- Time Traveled, total time it took for the email to reach you
### Fixed
- Bug if multiple IPs exist in one Received header
- Check for API response HTTP status code
## 1.0.8 - 2016-5-25
### Added ### Added
- Styles Updates - Styles Updates
- SSL Default - SSL Default
## [1.0.7] - 2015-11-13 ## 1.0.7 - 2015-11-13
### Fixed ### Fixed
- Check that IP address starts with digit less than 240 (IANA-RESERVED) - Check that IP address starts with digit less than 240 (IANA-RESERVED)
## [1.0.6] - 2015-11-12 ## 1.0.6 - 2015-11-12
### Fixed ### Fixed
- Missing try/catch around JSON.parse - Missing try/catch around JSON.parse
## [1.0.3] - 2015-09-18 ## 1.0.3 - 2015-09-18
### Added ### Added
- Map provider in preferences - Map provider in preferences
@ -28,7 +42,7 @@
- Display if only city in response - Display if only city in response
## [1.0.1] - 2015-06-10 ## 1.0.1 - 2015-06-10
### Added ### Added
- Context.IO sponsored message, build something awesome with their API! - Context.IO sponsored message, build something awesome with their API!
@ -37,7 +51,7 @@
- Secure message parsing - Secure message parsing
## [1.0.0] - 2015-05-31 ## 1.0.0 - 2015-05-31
### Changed ### Changed
- Combined Thunderbird and Postbox code into one plugin - Combined Thunderbird and Postbox code into one plugin
@ -45,7 +59,7 @@
- Fix mismatch IP from Microsoft SMTP id in received header - Fix mismatch IP from Microsoft SMTP id in received header
## [0.9.0] - 2015-05-30 ## 0.9.0 - 2015-05-30
### Changed ### Changed
- Update map style and size - Update map style and size
- Update logo - Update logo
@ -57,4 +71,4 @@
- Forecast.IO, gets the weather from the sender, API key needs to be added in preferences - Forecast.IO, gets the weather from the sender, API key needs to be added in preferences
### Fixed ### Fixed
- Fix mismatch IP from Microsoft SMTP id in received header - Fix mismatch IP from Microsoft SMTP id in Received header

View File

@ -3,26 +3,26 @@
<img src="https://www.mailhops.com/images/logos/logo.png" alt="MailHops logo" title="MailHops" align="right" /> <img src="https://www.mailhops.com/images/logos/logo.png" alt="MailHops logo" title="MailHops" align="right" />
MailHops is an email route API. It does two things: MailHops is an email route API. It does a few things:
1. Returns a route an email took based on the Received header IP addresses 1. Returns a route an email took based on the Received header IP addresses
2. Returns a map an email took based on the Received header IP addresses 1. Returns a map an email took based on the Received header IP addresses
1. Shows the weather of the sender when you provide a Forecastio API key
1. Will tag and mark messages as Junk if from a Country you don't like
1. Performs DNSBL check on messages
The route will contain DNSBL lookup results, hostname lookup results and What3Words geo locations. ### Editing the code
1. After you make changes you can run the [build.sh](build.sh) script
1. Edit files 1. Open Postbox or Thunderbird and goto Tools->Add-ons and "Install Add-on From File..."
2. Run [build.sh](build.sh) script 1. Choose mailhops.xpi from build script
3. Open Postbox and goto Tools->Add-ons and "Install Add-on From File..."
4. Choose mailhops.xpi from build script
```sh ```sh
$ chmod +x build.sh $ chmod +x build.sh
$ ./build.sh $ ./build.sh
``` ```
## API ### MailHops API
Host your own API - [https://github.com/mailhops](https://github.com/mailhops)
- [API](https://github.com/avantassel/mailhops-api)
## Plugins ### Download
- [Download](https://addons.mozilla.org/en-US/thunderbird/addon/mailhops/) - [Download this plugin from Mozilla](https://addons.mozilla.org/en-US/thunderbird/addon/mailhops/)

View File

@ -20,6 +20,7 @@ var mailHops =
}, },
message: { message: {
secure:[] secure:[]
,time: 0
} }
}; };
@ -161,6 +162,7 @@ mailHops.getRoute = function(){
var regexIPV6 = /(::|(([a-fA-F0-9]{1,4}):){7}(([a-fA-F0-9]{1,4}))|(:(:([a-fA-F0-9]{1,4})){1,6})|((([a-fA-F0-9]{1,4}):){1,6}:)|((([a-fA-F0-9]{1,4}):)(:([a-fA-F0-9]{1,4})){1,6})|((([a-fA-F0-9]{1,4}):){2}(:([a-fA-F0-9]{1,4})){1,5})|((([a-fA-F0-9]{1,4}):){3}(:([a-fA-F0-9]{1,4})){1,4})|((([a-fA-F0-9]{1,4}):){4}(:([a-fA-F0-9]{1,4})){1,3})|((([a-fA-F0-9]{1,4}):){5}(:([a-fA-F0-9]{1,4})){1,2}))/; var regexIPV6 = /(::|(([a-fA-F0-9]{1,4}):){7}(([a-fA-F0-9]{1,4}))|(:(:([a-fA-F0-9]{1,4})){1,6})|((([a-fA-F0-9]{1,4}):){1,6}:)|((([a-fA-F0-9]{1,4}):)(:([a-fA-F0-9]{1,4})){1,6})|((([a-fA-F0-9]{1,4}):){2}(:([a-fA-F0-9]{1,4})){1,5})|((([a-fA-F0-9]{1,4}):){3}(:([a-fA-F0-9]{1,4})){1,4})|((([a-fA-F0-9]{1,4}):){4}(:([a-fA-F0-9]{1,4})){1,3})|((([a-fA-F0-9]{1,4}):){5}(:([a-fA-F0-9]{1,4})){1,2}))/;
var headReceived = mailHops.headers.extractHeader ( "Received" , true ); var headReceived = mailHops.headers.extractHeader ( "Received" , true );
var headXReceived = mailHops.headers.extractHeader ( "X-Received" , false );
var headXOrigIP = mailHops.headers.extractHeader ( "X-Originating-IP" , false ); var headXOrigIP = mailHops.headers.extractHeader ( "X-Originating-IP" , false );
//auth box //auth box
var headXMailer = (mailHops.options.show_auth && mailHops.options.show_mailer) ? mailHops.headers.extractHeader ( "X-Mailer" , false ) : null; var headXMailer = (mailHops.options.show_auth && mailHops.options.show_mailer) ? mailHops.headers.extractHeader ( "X-Mailer" , false ) : null;
@ -172,9 +174,10 @@ mailHops.getRoute = function(){
var headListUnsubscribe = mailHops.options.show_lists ? mailHops.headers.extractHeader ( "List-Unsubscribe" , false ) : null; var headListUnsubscribe = mailHops.options.show_lists ? mailHops.headers.extractHeader ( "List-Unsubscribe" , false ) : null;
var all_ips = new Array(); var all_ips = new Array();
var rline = ''; var rline = '',firstDate,lastDate;
//empty secure //empty secure and time
mailHops.message.secure = []; mailHops.message.secure = [];
mailHops.message.time = 0;
if(mailHops.options.show_lists){ if(mailHops.options.show_lists){
mailHopsDisplay.lists( headListUnsubscribe ); mailHopsDisplay.lists( headListUnsubscribe );
@ -193,6 +196,15 @@ mailHops.getRoute = function(){
rline += headReceivedArr[h]; rline += headReceivedArr[h];
if(headReceivedArr[h].indexOf(';')==-1) if(headReceivedArr[h].indexOf(';')==-1)
continue; continue;
// first and last dates are used to calculate time Traveled
if(rline.indexOf(';')!==-1){
if(!lastDate)
lastDate = rline.substring(rline.indexOf(';')+1).trim();
firstDate = rline.substring(rline.indexOf(';')+1).trim();
}
// parse IPs out of Received line
received_ips = rline.match(regexAllIp); received_ips = rline.match(regexAllIp);
//continue if no IPs found //continue if no IPs found
if(!received_ips) if(!received_ips)
@ -211,6 +223,20 @@ mailHops.getRoute = function(){
} }
} }
// parse dates
if(firstDate.indexOf('(')!==-1)
firstDate = firstDate.substring(0,firstDate.indexOf('(')).trim();
if(lastDate.indexOf('(')!==-1)
lastDate = lastDate.substring(0,lastDate.indexOf('(')).trim();
try {
firstDate = new Date(firstDate);
lastDate = new Date(lastDate);
mailHops.message.time = lastDate-firstDate;
} catch(e){
mailHops.LOG('parse time traveled dates Error: '+JSON.stringify(e));
}
//get the originating IP address //get the originating IP address
if(!!headXOrigIP){ if(!!headXOrigIP){
//remove brackets //remove brackets
@ -333,6 +359,8 @@ mailHops.lookupRoute = function(header_route){
if(mailHops.options.fkey != '') if(mailHops.options.fkey != '')
lookupURL += '&fkey='+mailHops.options.fkey; lookupURL += '&fkey='+mailHops.options.fkey;
if(mailHops.message.time > 0)
lookupURL += '&t='+mailHops.message.time;
//check for cache //check for cache
var cached_results = mailHops.getResults(); var cached_results = mailHops.getResults();

View File

@ -430,14 +430,24 @@ var mailHopsDisplay =
if(response.distance){ if(response.distance){
if(this.options.unit=='km' && response.distance.kilometers > 0) if(this.options.unit=='km' && response.distance.kilometers > 0)
distanceText =' ( '+mailHopsUtils.addCommas(Math.round(response.distance.kilometers))+' km traveled )'; distanceText = mailHopsUtils.addCommas(Math.round(response.distance.kilometers))+' km traveled';
else if(response.distance.miles > 0) else if(response.distance.miles > 0)
distanceText =' ( '+mailHopsUtils.addCommas(Math.round(response.distance.miles))+' mi traveled )'; distanceText = mailHopsUtils.addCommas(Math.round(response.distance.miles))+' mi traveled';
} }
else if(displayText=='') else if(displayText=='')
displayText = ' Local message.'; displayText = ' Local message.';
} }
if(message.time>0){
message.time = message.time/1000;
if(message.time<60)
distanceText += ' in '+message.time+' sec.';
else if(message.time<3600) //something is wrong if it takes this long
distanceText += ' in '+Math.round(message.time/60)+' min.';
else //something is wrong if it takes this long
distanceText += ' in '+Math.round(message.time/60/60)+' hrs.';
}
if(header_route) if(header_route)
this.resultMapLink.setAttribute("data-route", header_route); this.resultMapLink.setAttribute("data-route", header_route);
else else
@ -445,12 +455,10 @@ var mailHopsDisplay =
this.resultTextDataPane.style.backgroundImage = 'url('+image+')'; this.resultTextDataPane.style.backgroundImage = 'url('+image+')';
this.resultTextDataPane.value = displayText; this.resultTextDataPane.value = displayText;
this.resultTextDataPane.setAttribute('tooltiptext',displayText+' '+distanceText);
if(distanceText){ if(distanceText){
this.resultTextDataPane2.style.display = 'block'; this.resultTextDataPane2.style.display = 'block';
this.resultTextDataPane2.value = distanceText; this.resultTextDataPane2.value = ' ( '+distanceText+' )';
this.resultTextDataPane2.setAttribute('tooltiptext',displayText+' '+distanceText);
} else { } else {
this.resultTextDataPane2.style.display = 'none'; this.resultTextDataPane2.style.display = 'none';
} }

View File

@ -294,19 +294,29 @@ var mailHopsDisplay =
if(response.distance){ if(response.distance){
if(this.options.unit=='km' && response.distance.kilometers > 0) if(this.options.unit=='km' && response.distance.kilometers > 0)
distanceText =' ( '+mailHopsUtils.addCommas(Math.round(response.distance.kilometers))+' km traveled )'; distanceText = mailHopsUtils.addCommas(Math.round(response.distance.kilometers))+' km traveled';
else if(response.distance.miles > 0) else if(response.distance.miles > 0)
distanceText =' ( '+mailHopsUtils.addCommas(Math.round(response.distance.miles))+' mi traveled )'; distanceText = mailHopsUtils.addCommas(Math.round(response.distance.miles))+' mi traveled';
} else if(displayText=='') } else if(displayText=='')
displayText = ' Local message.'; displayText = ' Local message.';
} }
if(message.time>0){
message.time = message.time/1000;
if(message.time<60)
distanceText += ' in '+message.time+' sec.';
else if(message.time<3600) //something is wrong if it takes this long
distanceText += ' in '+Math.round(message.time/60)+' min.';
else //something is wrong if it takes this long
distanceText += ' in '+Math.round(message.time/60/60)+' hrs.';
}
if(header_route) if(header_route)
this.mapLink.setAttribute("data-route", header_route); this.mapLink.setAttribute("data-route", header_route);
else else
this.mapLink.removeAttribute("data-route"); this.mapLink.removeAttribute("data-route");
this.resultText.setAttribute('value', displayText+' '+distanceText); this.resultText.setAttribute('value', displayText+' ( '+distanceText+' )');
this.resultText.style.backgroundImage = 'url('+image+')'; this.resultText.style.backgroundImage = 'url('+image+')';
}//end route }//end route
}; };