diff --git a/Changes.md b/Changes.md index 23cd765..01c8cf4 100644 --- a/Changes.md +++ b/Changes.md @@ -1,6 +1,16 @@ +### Unreleased -## 1.0.0 - 2022-07-23 +### [1.0.1] - 2022-07-23 + +- add bin/spf +- move spf.js to lib/spf.js + + +### 1.0.0 - 2022-07-23 - Import from Haraka + + +[1.0.1]: https://github.com/haraka/haraka-plugin-spf/releases/tag/1.0.1 diff --git a/README.md b/README.md index 8bc9c9c..f7f9a03 100644 --- a/README.md +++ b/README.md @@ -4,8 +4,6 @@ # haraka-plugin-spf -=== - This plugin implements RFC 4408 Sender Policy Framework (SPF) See the [Wikipedia article on SPF](http://en.wikipedia.org/wiki/Sender_Policy_Framework) for details. diff --git a/bin/spf b/bin/spf new file mode 100755 index 0000000..9e718f0 --- /dev/null +++ b/bin/spf @@ -0,0 +1,48 @@ +#!/usr/bin/env node + +// SPF test tool + +const nopt = require('nopt'); +const path = require('path'); +const base_path = path.join(__dirname, '..'); +const SPF = require(`${base_path}/lib/spf`).SPF; +const spf = new SPF(); + +const parsed = nopt({ 'debug': Boolean, 'ip': String, 'helo': String, 'domain': String }); + +function print_usage () { + console.log('Usage: spf [--debug] --ip --helo --domain '); + process.exit(1); +} + +if (!parsed.ip || (parsed.ip && (!parsed.domain && !parsed.helo))) { + print_usage(); +} + +if (!parsed.debug) { + SPF.prototype.log_debug = function (str) {} +} + +let domain; +if (parsed.domain) { + domain = /@(.+)$/.exec(parsed.domain); + if (domain) { + domain = domain[1]; + } + else { + domain = parsed.domain; + } +} + +spf.check_host(parsed.ip, (domain ? domain : parsed.helo), null, function (err, result) { + if (err) { + console.log(`Error: ${err.message}`); + process.exit(1); + } + console.log([ + `ip=${parsed.ip}`, + `helo="${(parsed.helo ? parsed.helo : '')}"`, + `domain="${(domain ? domain : '')}"`, + `result=${spf.result(result)}` + ].join(' ')); +}) diff --git a/index.js b/index.js index 58ff4c1..769864f 100644 --- a/index.js +++ b/index.js @@ -1,6 +1,6 @@ // spf -const SPF = require('./spf').SPF; +const SPF = require('./lib/spf').SPF; const net_utils = require('haraka-net-utils'); const DSN = require('haraka-dsn'); diff --git a/spf.js b/lib/spf.js similarity index 99% rename from spf.js rename to lib/spf.js index ff92bae..cf68ecc 100644 --- a/spf.js +++ b/lib/spf.js @@ -134,10 +134,10 @@ class SPF { } } // Process any other expansions - str = str.replace(/%%/g, '%'); - str = str.replace(/%_/g, ' '); - str = str.replace(/%-/g, '%20'); - return str; + return str + .replace(/%%/g, '%') + .replace(/%_/g, ' ') + .replace(/%-/g, '%20'); } log_debug (str) { diff --git a/package.json b/package.json index 15f9f3f..488e140 100644 --- a/package.json +++ b/package.json @@ -1,11 +1,11 @@ { "name": "haraka-plugin-spf", - "version": "1.0.0", + "version": "1.0.1", "description": "Sender Policy Framework (SPF) plugin for Haraka", "main": "index.js", "scripts": { - "lint": "npx eslint *.js test", - "lintfix": "npx eslint --fix *.js test", + "lint": "npx eslint *.js bin/spf lib test", + "lintfix": "npx eslint --fix *.js bin/spf lib test", "versions": "npx dependency-version-checker check", "test": "npx mocha" }, @@ -30,9 +30,13 @@ "haraka-test-fixtures": "*", "mocha": "9" }, + "bin": { + "spf": "./bin/spf" + }, "dependencies": { "haraka-dsn": "^1.0.4", "haraka-net-utils": "^1.4.1", - "ipaddr.js": "^2.0.1" + "ipaddr.js": "^2.0.1", + "nopt": "^6.0.0" } } diff --git a/test/index.js b/test/index.js index e47c58e..45d5ab7 100644 --- a/test/index.js +++ b/test/index.js @@ -7,7 +7,7 @@ const Address = require('address-rfc2821').Address; const constants = require('haraka-constants'); const fixtures = require('haraka-test-fixtures') -const SPF = require('../spf').SPF; +const SPF = require('../lib/spf').SPF; const spf = new SPF(); beforeEach(function () { diff --git a/test/spf.js b/test/spf.js index 37364fb..ae26520 100644 --- a/test/spf.js +++ b/test/spf.js @@ -1,6 +1,6 @@ const assert = require('assert') -const SPF = require('../spf').SPF; +const SPF = require('../lib/spf').SPF; SPF.prototype.log_debug = () => {}; // noop, hush debug output @@ -35,6 +35,7 @@ describe('SPF', function () { }) it('mod_redirect, false', function (done) { + this.timeout=4000 this.SPF.count=0; this.SPF.ip='212.70.129.94'; this.SPF.mail_from='fraud@aexp.com';