Skip to content

Commit

Permalink
Release v1.1.2 (#5)
Browse files Browse the repository at this point in the history
* dep: depend on net-utils 1.5.0 (with async get_public_ip)
* refactor: convert loop to for…of
  • Loading branch information
msimerson authored Dec 21, 2022
1 parent 820f63b commit c7861c1
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 21 deletions.
8 changes: 8 additions & 0 deletions Changes.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@

### Unreleased


### [1.1.2] - 2022-12-21

- dep: depend on net-utils 1.5.0
- refactor: convert loop to for...of


### [1.1.0] - 2022-12-17

- spf: use async/await dns
Expand All @@ -23,3 +30,4 @@


[1.0.1]: https://github.com/haraka/haraka-plugin-spf/releases/tag/1.0.1
[1.1.2]: https://github.com/haraka/haraka-plugin-spf/releases/tag/1.1.2
35 changes: 17 additions & 18 deletions lib/spf.js
Original file line number Diff line number Diff line change
Expand Up @@ -413,24 +413,24 @@ class SPF {
}
}

for (let a=0; a<addrs.length; a++) {
for (const addr of addrs) {
if (cidr) {
// CIDR
const range = ipaddr.parse(addrs[a]);
const range = ipaddr.parse(addr);
if (self.ipaddr.match(range, cidr)) {
self.log_debug(`mech_a: ${self.ip} => ${addrs[a]}/${cidr}: MATCH!`);
self.log_debug(`mech_a: ${self.ip} => ${addr}/${cidr}: MATCH!`);
return self.return_const(qualifier)
}
else {
self.log_debug(`mech_a: ${self.ip} => ${addrs[a]}/${cidr}: NO MATCH`);
self.log_debug(`mech_a: ${self.ip} => ${addr}/${cidr}: NO MATCH`);
}
}
else {
if (addrs[a] === self.ip) {
if (addr === self.ip) {
return self.return_const(qualifier)
}
else {
self.log_debug(`mech_a: ${self.ip} => ${addrs[a]}: NO MATCH`);
self.log_debug(`mech_a: ${self.ip} => ${addr}: NO MATCH`);
}
}
}
Expand Down Expand Up @@ -472,9 +472,9 @@ class SPF {
// RFC 4408 Section 10.1
if (mxes.length > self.LIMIT) return self.SPF_PERMERROR

for (let a=0; a<mxes.length; a++) {
for (const element of mxes) {
pending++;
const mx = mxes[a].exchange;
const mx = element.exchange;
// Calculate which IP method to use
let resolve_method;
let cidr;
Expand Down Expand Up @@ -508,14 +508,14 @@ class SPF {
// All queries run; see if our IP matches
if (cidr) {
// CIDR match type
for (let i=0; i<addresses.length; i++) {
const range = ipaddr.parse(addresses[i]);
for (const address of addresses) {
const range = ipaddr.parse(address);
if (self.ipaddr.match(range, cidr)) {
self.log_debug(`mech_mx: ${self.ip} => ${addresses[i]}/${cidr}: MATCH!`);
self.log_debug(`mech_mx: ${self.ip} => ${address}/${cidr}: MATCH!`);
return self.return_const(qualifier)
}
else {
self.log_debug(`mech_mx: ${self.ip} => ${addresses[i]}/${cidr}: NO MATCH`);
self.log_debug(`mech_mx: ${self.ip} => ${address}/${cidr}: NO MATCH`);
}
}
// No matches
Expand Down Expand Up @@ -563,8 +563,7 @@ class SPF {
// RFC 4408 Section 10.1
if (ptrs.length > self.LIMIT) return self.SPF_PERMERROR

for (let i=0; i<ptrs.length; i++) {
const ptr = ptrs[i];
for (const ptr of ptrs) {

try {
const addrs = await dns[resolve_method](ptr)
Expand All @@ -590,13 +589,13 @@ class SPF {
// These will cause a regexp error, so we can catch them.
try {
const re = new RegExp(`${domain.replace('.','\\.')}$`, 'i');
for (let t=0; t<names.length; t++) {
if (re.test(names[t])) {
self.log_debug(`mech_ptr: ${names[t]} => ${domain}: MATCH!`);
for (const name of names) {
if (re.test(name)) {
self.log_debug(`mech_ptr: ${name} => ${domain}: MATCH!`);
return self.return_const(qualifier)
}
else {
self.log_debug(`mech_ptr: ${names[t]} => ${domain}: NO MATCH`);
self.log_debug(`mech_ptr: ${name} => ${domain}: NO MATCH`);
}
}
return self.SPF_NONE
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "haraka-plugin-spf",
"version": "1.1.0",
"version": "1.1.2",
"description": "Sender Policy Framework (SPF) plugin for Haraka",
"main": "index.js",
"scripts": {
Expand Down Expand Up @@ -35,7 +35,7 @@
},
"dependencies": {
"haraka-dsn": "^1.0.4",
"haraka-net-utils": "^1.4.1",
"haraka-net-utils": "^1.5.0",
"ipaddr.js": "^2.0.1",
"nopt": "^7.0.0"
}
Expand Down
2 changes: 1 addition & 1 deletion test/spf.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ describe('SPF', function () {
this.SPF.count=0;
this.SPF.ip='212.70.129.94';
this.SPF.mail_from='[email protected]';

const rc = await this.SPF.mod_redirect('aexp.com')
// assert.equal(null, err);
switch (rc) {
case 7:
// from time to time (this is the third time we've seen it,
Expand Down

0 comments on commit c7861c1

Please sign in to comment.