From 2b75f5c496c7d3f6b05ea1c4da8f6146fa04a084 Mon Sep 17 00:00:00 2001 From: Matt Simerson Date: Wed, 3 Apr 2024 10:19:46 -0700 Subject: [PATCH] Release v1.1.0 (#62) - index: turn off watchForUpdates - index.received_header: refactor with es6 - deps: bump and pin versions - ci: add trigger to run tests on PR #60 - test: add received_header #61 - test: use async where possible - test: remove done when superfluous --- Changes.md | 12 ++++++++++++ index.js | 25 ++++++++++++------------- package.json | 2 +- test/geoip.js | 9 +++------ 4 files changed, 28 insertions(+), 20 deletions(-) diff --git a/Changes.md b/Changes.md index 267d4ea..5e45b56 100644 --- a/Changes.md +++ b/Changes.md @@ -1,6 +1,17 @@ ### Unreleased +### [1.1.0] - 2024-04-02 + +- index: turn off watchForUpdates +- index: reset regex index to zero after each call to exec #58 +- deps: bump and pin versions +- ci: add trigger to run tests on PR #60 +- test: add received_header #61 +- test: use async where possible +- test: remove done when superfluous + + ### [1.0.17] - 2022-11-14 - dep(node-maxmind): bump to 4.3.8 @@ -89,3 +100,4 @@ - README link cleanups [1.0.17]: https://github.com/haraka/haraka-plugin-geoip/releases/tag/1.0.17 +[1.1.0]: https://github.com/haraka/haraka-plugin-geoip/releases/tag/1.1.0 diff --git a/index.js b/index.js index 26f0dae..7b1a8e0 100644 --- a/index.js +++ b/index.js @@ -372,20 +372,19 @@ exports.received_headers = function (connection) { const ipany_re = net_utils.get_ipany_re('[\\[\\(](?:IPv6:)?', '[\\]\\)]') // Try and parse each received header - for (let i=0; i < received.length; i++) { - const match = ipany_re.exec(received[i]) - ipany_re.lastIndex = 0 - if (!match) continue - if (net_utils.is_private_ip(match[1])) continue // exclude private IP - - const gi = this.get_geoip(match[1]) - const country = get_country(gi) - let logmsg = `received=${match[1]}` - if (country) { - logmsg += ` country=${country}` - results.push(`${match[1]}:${country}`) + for (const header of received) { + for (const match of [...header.matchAll(ipany_re)]) { + if (net_utils.is_private_ip(match[1])) continue // exclude private IP + + const gi = this.get_geoip(match[1]) + const country = get_country(gi) + let logmsg = `received=${match[1]}` + if (country) { + logmsg += ` country=${country}` + results.push(`${match[1]}:${country}`) + } + connection.loginfo(this, logmsg) } - connection.loginfo(this, logmsg) } return results } diff --git a/package.json b/package.json index 8402fa0..75040c6 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "haraka-plugin-geoip", - "version": "1.0.17", + "version": "1.1.0", "description": "provide geographic information about mail senders.", "main": "index.js", "directories": { diff --git a/test/geoip.js b/test/geoip.js index 1140207..bad17a2 100644 --- a/test/geoip.js +++ b/test/geoip.js @@ -130,23 +130,20 @@ describe('database lookups', function () { describe('haversine', function () { - beforeEach(function (done) { + beforeEach(function () { this.plugin = new fixtures.plugin('geoip') - done() }) - it('WA to MI is 2000-2500km', function (done) { + it('WA to MI is 2000-2500km', function () { const r = this.plugin.haversine(47.673, -122.3419, 38, -97) assert.equal((r > 2000), true, r) assert.equal((r < 2500), true, r) - done() }) - it('DRC to China is 7,000-15,000km', function (done) { + it('DRC to China is 7,000-15,000km', function () { const r = this.plugin.haversine(0, 25, 32, 117) assert.equal((r > 10000), true, r) assert.equal((r < 15000), true, r) - done() }) })