Skip to content

Commit

Permalink
fix(checkSpf): Merge pull request postalsys#3 from haraka/release-1.1.1
Browse files Browse the repository at this point in the history
fix(checkSpf): use modern paths to connection attributes
  • Loading branch information
andris9 authored Oct 2, 2024
2 parents 739fb27 + bbf0067 commit 5b92485
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 17 deletions.
28 changes: 11 additions & 17 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,16 @@ const { dkimVerify } = require('mailauth/lib/dkim/verify');
const { bimi } = require('mailauth/lib/bimi');

exports.register = function () {
const plugin = this;

plugin.load_config();
this.load_config();

plugin.resolver = async (name, rr) => await dns.promises.resolve(name, rr);
this.resolver = async (name, rr) => await dns.promises.resolve(name, rr);

plugin.register_hook('helo', 'mailauth_helo');
plugin.register_hook('ehlo', 'mailauth_helo');
this.register_hook('helo', 'mailauth_helo');
this.register_hook('ehlo', 'mailauth_helo');
};

exports.load_config = function () {
const plugin = this;

plugin.cfg = plugin.config.get('mailauth.yaml', {}, () => this.load_config());
this.cfg = this.config.get('mailauth.yaml', {}, () => this.load_config());
};

exports.mailauth_helo = function (next, connection, helo) {
Expand All @@ -32,24 +28,22 @@ exports.mailauth_helo = function (next, connection, helo) {
};

exports.mailauth_add_result = function (txn, key, domain, result) {
const plugin = this;

const resultName = `${key}[${domain}]`;

switch (result) {
case 'pass':
txn.results.add(plugin, { pass: resultName });
txn.results.add(this, { pass: resultName });
break;
case 'fail':
txn.results.add(plugin, { fail: resultName });
txn.results.add(this, { fail: resultName });
break;
case 'neutral':
case 'policy':
txn.results.add(plugin, { skip: resultName });
txn.results.add(this, { skip: resultName });
break;
case 'permerror':
case 'temperror':
txn.results.add(plugin, { fail: resultName });
txn.results.add(this, { fail: resultName });
break;
case 'none':
default:
Expand All @@ -75,8 +69,8 @@ exports.hook_mail = function (next, connection, params) {

checkSpf({
resolver: plugin.resolver,
ip: connection.remote_ip, // SMTP client IP
helo: connection.notes.mailauth_helo, // EHLO/HELO hostname
ip: connection.remote.ip, // SMTP client IP
helo: connection.hello.host, // EHLO/HELO hostname
sender, // MAIL FROM address
mta: connection.local.host, // MX hostname
maxResolveCount: plugin.cfg.dns?.maxLookups
Expand Down
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
"version": "1.1.0",
"description": "SPF, DKIM, DMARC, ARC, BIMI validator for Haraka",
"main": "index.js",
"files": [
"config"
],
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"update": "rm -rf node_modules package-lock.json && ncu -u && npm install"
Expand Down

0 comments on commit 5b92485

Please sign in to comment.