Skip to content

Commit

Permalink
style: plugin -> this
Browse files Browse the repository at this point in the history
  • Loading branch information
msimerson committed May 24, 2022
1 parent 546dfb1 commit 429f760
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 19 deletions.
7 changes: 7 additions & 0 deletions .codeclimate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@ engines:
config:
config: ".eslintrc.yaml"

checks:
return-statements:
enabled: false
method-complexity:
config:
threshold: 10

ratings:
paths:
- "**.js"
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ jobs:

test-win:
needs: lint
if: ${{ false }} # disabled, until Redis for GHA Windows exists
runs-on: ${{ matrix.os }}
strategy:
matrix:
Expand All @@ -49,3 +48,4 @@ jobs:
node-version: ${{ matrix.node-version }}
- run: npm install
- run: npm test
if: ${{ false }} # disabled, until Redis for GHA Windows exists
34 changes: 16 additions & 18 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -179,15 +179,14 @@ exports.already_matched = function (connection) {
}

exports.check_recipient = async function (next, connection, rcpt) {
const plugin = this;
// rcpt is a valid local email address. Some rcpt_to.* plugin has
// accepted it.

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

function errNext (err) {
connection.logerror(plugin, `check_recipient: ${err}`);
connection.logerror(this, `check_recipient: ${err}`);
next();
}

Expand All @@ -197,61 +196,60 @@ exports.check_recipient = async function (next, connection, rcpt) {
const rcpt_od = tlds.get_organizational_domain(rcpt.host);
if (!rcpt_od) return errNext(`no rcpt od for ${rcpt.host}`);

connection.transaction.results.push(plugin, { rcpt_ods: rcpt_od });
connection.transaction.results.push(this, { rcpt_ods: rcpt_od });

// if no validated sender domain, there's nothing to do...yet
const sender_od = plugin.get_validated_sender_od(connection);
const sender_od = this.get_validated_sender_od(connection);
if (!sender_od) return next();

// The sender OD is validated, check Redis for a match
try {
const reply = await plugin.db.hGet(rcpt_od, sender_od)
connection.logdebug(plugin, `${rcpt_od} : ${sender_od} : ${reply}`);
const reply = await this.db.hGet(rcpt_od, sender_od)
connection.logdebug(this, `${rcpt_od} : ${sender_od} : ${reply}`);
if (reply) {
connection.transaction.results.add(plugin, { pass: rcpt_od, count: reply });
connection.transaction.results.add(this, { pass: rcpt_od, count: reply });
}
next(null, null, rcpt_od);
}
catch (err) {
plugin.logerror(err);
this.logerror(err);
next();
}
}

exports.is_dkim_authenticated = async function (next, connection) {
const plugin = this;
if (connection.relaying) return next();

let rcpt_ods = [];

function errNext (err) {
connection.logerror(plugin, `is_dkim_authenticated: ${err}`);
connection.logerror(this, `is_dkim_authenticated: ${err}`);
next(null, null, rcpt_ods);
}
function infoNext (msg) {
connection.loginfo(plugin, `is_dkim_authenticated: ${msg}`);
connection.loginfo(this, `is_dkim_authenticated: ${msg}`);
next(null, null, rcpt_ods);
}

if (plugin.already_matched(connection)) return infoNext('already matched');
if (this.already_matched(connection)) return infoNext('already matched');

const sender_od = plugin.get_validated_sender_od(connection);
const sender_od = this.get_validated_sender_od(connection);
if (!sender_od) return errNext('no sender_od');

rcpt_ods = plugin.get_rcpt_ods(connection);
rcpt_ods = this.get_rcpt_ods(connection);
if (!rcpt_ods || ! rcpt_ods.length) return errNext('no rcpt_ods');

const dkim = connection.transaction.results.get('dkim_verify');
if (!dkim) return infoNext('no dkim_verify results');
if (!dkim.pass || !dkim.pass.length) return infoNext('no dkim pass')

try {
const multi = plugin.db.multi();
const multi = this.db.multi();

for (let i = 0; i < dkim.pass.length; i++) {
const dkim_od = tlds.get_organizational_domain(dkim.pass[i]);
if (dkim_od === sender_od) {
connection.transaction.results.add(plugin, { sender: sender_od, auth: 'dkim' });
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);
}
Expand All @@ -261,7 +259,7 @@ exports.is_dkim_authenticated = async function (next, connection) {
const replies = await multi.exec()
for (let j = 0; j < rcpt_ods.length; j++) {
if (!replies[j]) continue
connection.transaction.results.add(plugin, {
connection.transaction.results.add(this, {
pass: rcpt_ods[j],
count: replies[j],
emit: true
Expand All @@ -270,7 +268,7 @@ exports.is_dkim_authenticated = async function (next, connection) {
next(null, null, rcpt_ods);
}
catch (err) {
connection.logerror(plugin, err)
connection.logerror(this, err)
errNext(err)
}
}
Expand Down

0 comments on commit 429f760

Please sign in to comment.