Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release v1.1.0 #33

Merged
merged 13 commits into from
Dec 13, 2023
47 changes: 8 additions & 39 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: CI

on: [ push ]
on: [ push, pull_request ]

env:
CI: true
Expand All @@ -10,42 +10,11 @@ jobs:
lint:
uses: haraka/.github/.github/workflows/lint.yml@master

test:
needs: lint
runs-on: ${{ matrix.os }}
services:
redis:
image: redis
ports:
- 6379:6379
strategy:
matrix:
os: [ ubuntu-latest ]
node-version: [ 14, 16, 18 ]
fail-fast: false
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
name: Node ${{ matrix.node-version }} on ${{ matrix.os }}
with:
node-version: ${{ matrix.node-version }}
- run: npm install
- run: npm test
ubuntu:
needs: [ lint ]
uses: haraka/.github/.github/workflows/ubuntu.yml@master

test-win:
needs: lint
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ windows-latest ]
node-version: [ 14, 16, 18 ]
fail-fast: false
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
name: Node ${{ matrix.node-version }} on ${{ matrix.os }}
with:
node-version: ${{ matrix.node-version }}
- run: npm install
- run: npm test
if: ${{ false }} # disabled, until Redis for GHA Windows exists
windows:
needs: [ lint ]
uses: haraka/.github/.github/workflows/windows.yml@master
if: ${{ false }} # disabled, until Redis for GHA Windows exists
44 changes: 5 additions & 39 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,48 +4,14 @@ on:
push:
branches:
- master
paths:
- package.json

env:
CI: true
node-version: 16

jobs:
build:
runs-on: ubuntu-latest
services:
redis:
image: redis
ports:
- 6379:6379
steps:
- uses: actions/setup-node@v3
name: Node ${{ env.node-version }}
with:
node-version: ${{ env.node-version }}
- uses: actions/checkout@v3
- run: npm install
- run: npm test
publish:
uses: haraka/.github/.github/workflows/publish.yml@master
secrets: inherit

publish-npm:
needs: build
runs-on: ubuntu-latest
steps:
- uses: actions/setup-node@v3
name: Node ${{ env.node-version }}
with:
node-version: ${{ env.node-version }}
registry-url: https://registry.npmjs.org/

- uses: actions/checkout@v3
with:
fetch-depth: 0
# fetch-depth 0 needed by GitHub Release

- name: publish to NPM
run: npm publish
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_AUTH_TOKEN }}

- name: GitHub Release
uses: justincy/github-action-npm-release@2.0.1
id: release
2 changes: 1 addition & 1 deletion .release
Submodule .release updated 10 files
+29 −0 CHANGELOG.md
+37 −23 README.md
+15 −2 base.sh
+0 −10 cleanup.sh
+0 −51 do.sh
+22 −0 finish.sh
+16 −0 npm/prepend-scope.cjs
+0 −23 push.sh
+124 −0 start.sh
+28 −0 submit.sh
10 changes: 10 additions & 0 deletions Changes.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@
#### N.N.N - YYYY-MM-DD


### [1.1.0] - 2023-12-12

- feat(ignored_ods): ignore specified org domains
- style(es6): replace for i with for...of
- ci(publish): only when package.json modified
- ci: use shared workflows


#### 1.0.9 - 2022-05-28

- restore a plugin = this, context demands it
Expand Down Expand Up @@ -51,3 +59,5 @@
### 1.0.2 - 2016-02-06

- inherit from haraka-plugin-redis (vs redis)

[1.1.0]: https://github.com/haraka/haraka-plugin-known-senders/releases/tag/1.1.0
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
[![Build Status][ci-img]][ci-url]
[![Code Climate][clim-img]][clim-url]

[![NPM][npm-img]][npm-url]

# haraka-plugin-known-senders
Expand Down Expand Up @@ -50,8 +51,8 @@ This plugin can boost the reputation of most marginally deliverable ham. Where i



[ci-img]: https://travis-ci.org/haraka/haraka-plugin-known-senders.svg?branch=master
[ci-url]: https://travis-ci.org/haraka/haraka-plugin-known-senders
[ci-img]: https://github.com/haraka/haraka-plugin-known-senders/actions/workflows/ci.yml/badge.svg
[ci-url]: https://github.com/haraka/haraka-plugin-known-senders/actions/workflows/ci.yml
[clim-img]: https://codeclimate.com/github/haraka/haraka-plugin-known-senders/badges/gpa.svg
[clim-url]: https://codeclimate.com/github/haraka/haraka-plugin-known-senders
[npm-img]: https://nodei.co/npm/haraka-plugin-known-senders.png
Expand Down
9 changes: 9 additions & 0 deletions config/known-senders.ini
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,12 @@
; port = 6379
; db = 3

[ignored_ods]
gmail.com
hotmail.com
outlook.com
aol.com
yahoo.com
icloud.com
me.com
mac.com
62 changes: 31 additions & 31 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ exports.load_sender_ini = function () {
plugin.load_sender_ini();
});

if (plugin.cfg.ignored_ods === undefined) plugin.cfg.ignored_ods = {}

plugin.merge_redis_ini();
}

Expand All @@ -36,14 +38,15 @@ exports.load_sender_ini = function () {
*/

exports.update_sender = async function (next, connection, params) {
const plugin = this;
// queue_ok arguments: next, connection, msg
// ok 1390590369 qp 634 (F82E2DD5-9238-41DC-BC95-9C3A02716AD2.1)

let sender_od;
let rcpt_domains;

function errNext (err) {
connection.logerror(this, `update_sender: ${err}`);
connection.logerror(plugin, `update_sender: ${err}`);
next(null, null, sender_od, rcpt_domains);
}

Expand All @@ -55,6 +58,7 @@ exports.update_sender = async function (next, connection, params) {

sender_od = this.get_sender_domain_by_txn(txn);
if (!sender_od) return errNext('no sender domain');
if (sender_od in plugin.cfg.ignored_ods) return errNext(`ignored(${sender_od})`);

rcpt_domains = this.get_recipient_domains_by_txn(txn);
if (rcpt_domains.length === 0) {
Expand All @@ -65,8 +69,8 @@ exports.update_sender = async function (next, connection, params) {
// and the recipient is an external domain
try {
const multi = this.db.multi();
for (let i = 0; i < rcpt_domains.length; i++) {
multi.hIncrBy(sender_od, rcpt_domains[i], 1);
for (const rcptDomain of rcpt_domains) {
multi.hIncrBy(sender_od, rcptDomain, 1);
}

const replies = await multi.exec()
Expand All @@ -82,13 +86,10 @@ exports.update_sender = async function (next, connection, params) {
}

exports.get_sender_domain_by_txn = function (txn) {
const plugin = this;

if (!txn.mail_from) return;
if (!txn.mail_from.host) return;
if (!txn.mail_from || !txn.mail_from.host) return;
const sender_od = tlds.get_organizational_domain(txn.mail_from.host);
if (txn.mail_from.host !== sender_od) {
plugin.logdebug(`sender: ${txn.mail_from.host} -> ${sender_od}`);
this.logdebug(`sender: ${txn.mail_from.host} -> ${sender_od}`);
}
return sender_od;
}
Expand All @@ -99,11 +100,11 @@ exports.get_recipient_domains_by_txn = function (txn) {
const rcpt_domains = [];
if (!txn.rcpt_to) return rcpt_domains;

for (let i=0; i < txn.rcpt_to.length; i++) {
if (!txn.rcpt_to[i].host) continue;
const rcpt_od = tlds.get_organizational_domain(txn.rcpt_to[i].host);
if (txn.rcpt_to[i].host !== rcpt_od) {
plugin.loginfo(`rcpt: ${txn.rcpt_to[i].host} -> ${rcpt_od}`);
for (const element of txn.rcpt_to) {
if (!element.host) continue;
const rcpt_od = tlds.get_organizational_domain(element.host);
if (element.host !== rcpt_od) {
plugin.loginfo(`rcpt: ${element.host} -> ${rcpt_od}`);
}
if (rcpt_domains.indexOf(rcpt_od) === -1) {
// not a duplicate, add to the list
Expand All @@ -125,48 +126,45 @@ exports.get_recipient_domains_by_txn = function (txn) {

// early checks, on the mail hook
exports.is_authenticated = function (next, connection, params) {
const plugin = this;

// only validate inbound messages
if (connection.relaying) return next();

const sender_od = plugin.get_sender_domain_by_txn(connection.transaction);
const sender_od = this.get_sender_domain_by_txn(connection.transaction);
if (sender_od in this.cfg.ignored_ods) return next()

if (plugin.has_fcrdns_match(sender_od, connection)) {
connection.logdebug(plugin, `+fcrdns: ${sender_od}`);
if (this.has_fcrdns_match(sender_od, connection)) {
connection.logdebug(this, `+fcrdns: ${sender_od}`);
return next(null, null, sender_od);
}
if (plugin.has_spf_match(sender_od, connection)) {
connection.logdebug(plugin, `+spf: ${sender_od}`);
if (this.has_spf_match(sender_od, connection)) {
connection.logdebug(this, `+spf: ${sender_od}`);
return next(null, null, sender_od);
}

// Maybe: TLS verified domain?
if (connection.tls.verified) {
// TODO: get the CN and Subject Alternative Names of the cert
// then look for match with sender_od
connection.logdebug(plugin, `+tls: ${sender_od}`);
connection.logdebug(this, `+tls: ${sender_od}`);
// return next(null, null, sender_od);
}

return next();
next();
}

exports.get_validated_sender_od = function (connection) {
const plugin = this;
if (!connection) return;
if (!connection.transaction) return;
const txn_res = connection.transaction.results.get(plugin.name);
if (!connection || !connection.transaction) return;
const txn_res = connection.transaction.results.get(this.name);
if (!txn_res) return;
return txn_res.sender;
}

exports.get_rcpt_ods = function (connection) {
const plugin = this;
if (!connection) return [];
if (!connection.transaction) return [];

const txn_r = connection.transaction.results.get(plugin.name);
const txn_r = connection.transaction.results.get(this.name);
if (!txn_r) return [];

return txn_r.rcpt_ods;
Expand Down Expand Up @@ -201,6 +199,7 @@ exports.check_recipient = async function (next, connection, rcpt) {
// if no validated sender domain, there's nothing to do...yet
const sender_od = this.get_validated_sender_od(connection);
if (!sender_od) return next();
if (sender_od in this.cfg.ignored_ods) return errNext(`ignored(${sender_od})`)

// The sender OD is validated, check Redis for a match
try {
Expand Down Expand Up @@ -236,6 +235,7 @@ exports.is_dkim_authenticated = async function (next, connection) {

const sender_od = this.get_validated_sender_od(connection);
if (!sender_od) return errNext('no sender_od');
if (sender_od in this.cfg.ignored_ods) return infoNext(`ignored(${sender_od})`)

rcpt_ods = this.get_rcpt_ods(connection);
if (!rcpt_ods || ! rcpt_ods.length) return errNext('no rcpt_ods');
Expand All @@ -247,12 +247,12 @@ exports.is_dkim_authenticated = async function (next, connection) {
try {
const multi = this.db.multi();

for (let i = 0; i < dkim.pass.length; i++) {
const dkim_od = tlds.get_organizational_domain(dkim.pass[i]);
for (const pas of dkim.pass) {
const dkim_od = tlds.get_organizational_domain(pas);
if (dkim_od === sender_od) {
connection.transaction.results.add(this, { sender: sender_od, auth: 'dkim' });
for (let j = 0; j < rcpt_ods.length; j++) {
multi.hGet(rcpt_ods[j], sender_od);
for (const rcptOd of rcpt_ods) {
multi.hGet(rcptOd, sender_od);
}
}
}
Expand Down
19 changes: 10 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
{
"name": "haraka-plugin-known-senders",
"version": "1.0.9",
"version": "1.1.0",
"description": "Increase the reputation of recognized sender domains.",
"main": "index.js",
"scripts": {
"cover": "npx nyc --reporter=lcov --hook-run-in-context npm run test",
"lint": "npx eslint *.js test/*.js",
"lintfix": "npx eslint --fix *.js test/*.js",
"test": "npx mocha --exit"
"test": "npx mocha --exit",
"versions": "npx dependency-version-checker check"
},
"repository": {
"type": "git",
Expand All @@ -28,14 +29,14 @@
},
"homepage": "https://github.com/haraka/haraka-plugin-known-senders#readme",
"devDependencies": {
"address-rfc2821": "*",
"eslint": ">=8",
"eslint-plugin-haraka": "*",
"haraka-test-fixtures": "*",
"mocha": ">=9"
"address-rfc2821": "^2.1.1",
"eslint": "^8.55.0",
"eslint-plugin-haraka": "^1.0.15",
"haraka-test-fixtures": "^1.3.3",
"mocha": "^10.2.0"
},
"dependencies": {
"haraka-plugin-redis": "^2.0.3",
"haraka-tld": "*"
"haraka-plugin-redis": "^2.0.6",
"haraka-tld": "^1.2.0"
}
}
Loading