From df6ad59b6970ebd7edabeee555e5ca47ef24971f Mon Sep 17 00:00:00 2001 From: Andrew Van Tassel Date: Tue, 4 Oct 2016 09:58:07 -0600 Subject: [PATCH] Fixed date logic --- README.md | 6 +++--- lib/api.js | 10 +++++++--- test/header-test.eml | 6 +++--- 3 files changed, 13 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 5630a9c..a98468b 100644 --- a/README.md +++ b/README.md @@ -1,11 +1,11 @@ # MailHops API node [www.MailHops.com](http://www.mailhops.com) +MailHops logo + [![Build Status](https://travis-ci.org/avantassel/mailhops-node.svg)](https://travis-ci.org/avantassel/mailhops-node) [![NPM version](https://img.shields.io/npm/v/mailhops.svg)](https://www.npmjs.com/package/mailhops) -MailHops logo - A nodejs module for interacting with the MailHops API. ## Getting Started @@ -32,7 +32,7 @@ var mailhops = new MailHops({ }); ``` -MailHops objects can also be configured via the `.configure(options)` method. Here is an exmaple: +MailHops objects can also be configured via the `.configure(options)` method. Here is an example: ```javascript var MailHops = require("mailhops"); diff --git a/lib/api.js b/lib/api.js index f2ac341..23c2bb3 100644 --- a/lib/api.js +++ b/lib/api.js @@ -107,7 +107,10 @@ module.exports = { _.each(headers,function(line){ //if the header line begins with Received, X-Received or X-Originating-IP then push that to our array - if(line.indexOf('Received:')===0 || line.indexOf('X-Received:')===0){ + if(line.indexOf('Date:')===0){ + firstDate = line.substring(line.indexOf('Date:')+5).trim(); + } + else if(line.indexOf('Received:')===0 || line.indexOf('X-Received:')===0){ if(rline != ''){ receivedHeaders.push(rline); rline = ''; @@ -129,9 +132,10 @@ module.exports = { // first and last dates are used to calculate time_traveled Traveled if(rline.indexOf(';')!==-1){ + if(!firstDate) + firstDate = rline.substring(rline.indexOf(';')+1).trim(); if(!lastDate) lastDate = rline.substring(rline.indexOf(';')+1).trim(); - firstDate = rline.substring(rline.indexOf(';')+1).trim(); } rline = ''; @@ -152,7 +156,7 @@ module.exports = { try { firstDate = new Date(firstDate); lastDate = new Date(lastDate); - this.time_traveled = parseInt(lastDate-firstDate); + this.time_traveled = lastDate - firstDate; } catch(e){ this.time_traveled = null; } diff --git a/test/header-test.eml b/test/header-test.eml index 6049d07..6e262ff 100644 --- a/test/header-test.eml +++ b/test/header-test.eml @@ -6,7 +6,7 @@ Received: from 198.21.5.108.o2.delivery2.klaviyomail.com (o2.delivery2.klaviyoma (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by homiemail-mx32.g.dreamhost.com (Postfix) with ESMTPS id 4BE0510190916 - for ; Thu, 3 Sep 2014 16:38:38 -0700 (PDT) + for ; Thu, 3 Sep 2014 16:38:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=delivery.klaviyomail.com; h=content-type:mime-version:from:to:subject; s=smtpapi; @@ -31,14 +31,14 @@ Received: from muon.isy.liu.se (130.236.48.25) by edge01.net.lu.se Received: from ip227-36.wireless.lu.se (ip227-36.wireless.lu.se [130.235.227.36]) (using TLSv1 with cipher AES128-SHA (128/128 bits)) (No client certificate requested) by muon.isy.liu.se (Postfix) with ESMTPSA id - D4B3D802; Thu, 4 Sep 2014 1:38:28 +0200 (MEST) + D4B3D802; Thu, 3 Sep 2014 16:38:38 -0700 (PDT) Content-Type: multipart/alternative; boundary="===============2767014682564602329==" MIME-Version: 1.0 From: ProgrammableWeb Today To: Andrew Van Tassel Subject: Is It Time to Move On from .NET? -Date: Thu, 4 Sep 2014 1:38:28 GMT +Date: Thu, 3 Sep 2014 16:38:38 -0700 (PDT) X-Kmail-Relay: [gmh6f2.krelaymail.com]:587 Message-Id: <20150615173758.E2343271B8@queue-worker-166.servers.clovesoftware.com> X-SG-EID: z/7dFXGDBkx/fUP8kk8C2xB01JCsbu4AgSgValkgiTccFIBxI9L4Y1qe6fbe+Uf2YVSIXGTcm+Mu+n