Skip to content

Commit

Permalink
Release v1.1.0 (#62)
Browse files Browse the repository at this point in the history
- 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
  • Loading branch information
msimerson authored Apr 3, 2024
1 parent db9c60a commit 2b75f5c
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 20 deletions.
12 changes: 12 additions & 0 deletions Changes.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
25 changes: 12 additions & 13 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down
9 changes: 3 additions & 6 deletions test/geoip.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()
})
})

Expand Down

0 comments on commit 2b75f5c

Please sign in to comment.