Skip to content

Commit

Permalink
Release 1.0.1 (#13)
Browse files Browse the repository at this point in the history
- synced from Haraka/plugins/aliases
- dep(eslint): 3 -> 8
- chore(ci): add github workflows, codeql, ci, publish
- chore(ci): delete travis and appveyor configs
- chore: ignore package-lock.json
- chore(test): replaced nodeunit with mocha
- chore(codeclimate): updated config
- chore(test): cleaned up
- lint: use shorthand in tests
- ignore package-lock.json
- style: remove trailing ;
- delete cover script
  • Loading branch information
msimerson authored May 27, 2022
1 parent 60db05b commit 8dea17a
Show file tree
Hide file tree
Showing 16 changed files with 347 additions and 465 deletions.
13 changes: 10 additions & 3 deletions .codeclimate.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
engines:
engines:
eslint:
enabled: true
channel: "eslint-3"
channel: "eslint-8"
config:
config: ".eslintrc.json"
config: ".eslintrc.yaml"

checks:
similar-code:
enabled: false
method-complexity:
config:
threshold: 10

ratings:
paths:
Expand Down
1 change: 1 addition & 0 deletions .eslintrc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ env:
node: true
es6: true
mocha: true
es2020: true

plugins: [ haraka ]

Expand Down
1 change: 0 additions & 1 deletion .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,3 @@ Checklist:
- [ ] tests updated
- [ ] Changes.md updated
- [ ] package.json.version bumped
- [ ] published to NPM (will be done by @core)
37 changes: 37 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: CI

on: [ push ]

env:
CI: true

jobs:

lint:
uses: haraka/.github/.github/workflows/lint.yml@master

# coverage:
# uses: haraka/.github/.github/workflows/coverage.yml@master
# secrets: inherit

test:
needs: lint
runs-on: ${{ matrix.os }}

strategy:
matrix:
os: [ ubuntu-latest, 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
13 changes: 13 additions & 0 deletions .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
name: "CodeQL"

on:
push:
branches: [ master ]
pull_request:
branches: [ master ]
schedule:
- cron: '18 7 * * 4'

jobs:
codeql:
uses: haraka/.github/.github/workflows/codeql.yml@master
14 changes: 14 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
name: publish

on:
push:
branches:
- master

env:
CI: true

jobs:
publish:
uses: haraka/.github/.github/workflows/publish.yml@master
secrets: inherit
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,5 @@ jspm_packages

# Optional REPL history
.node_repl_history

package-lock.json
28 changes: 0 additions & 28 deletions .travis.yml

This file was deleted.

13 changes: 12 additions & 1 deletion Changes.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,15 @@

# 1.0.0 - 2017-09-01
### 1.0.1 - 2022-05-26

- synced from Haraka/plugins/aliases
- dep(eslint): 3 -> 8
- chore(ci): add github workflows, codeql, ci, publish
- chore(ci): delete travis and appveyor configs
- chore: ignore package-lock.json
- chore(test): replaced nodeunit with mocha
- lint: use shorthand in tests


### 1.0.0 - 2017-09-01

- imported from haraka
7 changes: 0 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
[![Build Status][ci-img]][ci-url]
[![Code Climate][clim-img]][clim-url]
[![Greenkeeper badge][gk-img]][gk-url]
[![NPM][npm-img]][npm-url]
<!-- requires URL update [![Windows Build Status][ci-win-img]][ci-win-url] -->
<!-- doesn't work in haraka plugins... yet. [![Code Coverage][cov-img]][cov-url]-->

# haraka-plugin-aliases

Expand Down Expand Up @@ -134,13 +131,9 @@ The following is a list of supported actions and their options.
<!-- leave these buried at the bottom of the document -->
[ci-img]: https://travis-ci.org/haraka/haraka-plugin-aliases.svg
[ci-url]: https://travis-ci.org/haraka/haraka-plugin-aliases
[ci-win-img]: https://ci.appveyor.com/api/projects/status/CHANGETHIS?svg=true
[ci-win-url]: https://ci.appveyor.com/project/haraka/haraka-CHANGETHIS
[cov-img]: https://codecov.io/github/haraka/haraka-plugin-aliases/coverage.svg
[cov-url]: https://codecov.io/github/haraka/haraka-plugin-aliases
[clim-img]: https://codeclimate.com/github/haraka/haraka-plugin-aliases/badges/gpa.svg
[clim-url]: https://codeclimate.com/github/haraka/haraka-plugin-aliases
[gk-img]: https://badges.greenkeeper.io/haraka/haraka-plugin-aliases.svg
[gk-url]: https://greenkeeper.io/
[npm-img]: https://nodei.co/npm/haraka-plugin-aliases.png
[npm-url]: https://www.npmjs.com/package/haraka-plugin-aliases
20 changes: 0 additions & 20 deletions appveyor.yml

This file was deleted.

120 changes: 57 additions & 63 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,108 +3,102 @@
const Address = require('address-rfc2821').Address;

exports.register = function () {
this.inherits('queue/discard');
this.inherits('queue/discard')

this.load_aliases();
this.load_aliases()

this.register_hook('rcpt', 'aliases');
this.register_hook('rcpt', 'aliases')
};

exports.load_aliases = function () {
const plugin = this;
const plugin = this
plugin.cfg = plugin.config.get('aliases', 'json', function () {
plugin.load_aliases();
}) || {};
plugin.load_aliases()
})
if (plugin.cfg === undefined) plugin.cfg = {}
}

exports.aliases = function (next, connection, params) {
const plugin = this;
const cfg = plugin.cfg;
const rcpt = params[0].address();
const user = params[0].user;
const host = params[0].host;
const plugin = this
const cfg = plugin.cfg
const rcpt = params[0].address()
const user = params[0].user
const host = params[0].host

let match = user.split(/[+-]/, 1);
let action = "<missing>";
let match = user.split(/[+-]/, 1)
let action = '<missing>'

function onMatch (match1, action1) {
function onMatch (alias1, action1, drop1) {
switch (action.toLowerCase()) {
case 'drop':
_drop(plugin, connection, match1);
_drop(plugin, connection, drop1)
break;
case 'alias':
_alias(plugin, connection, match1, cfg[match1], host);
_alias(plugin, connection, alias1, cfg[alias1], host)
break;
default:
connection.loginfo(plugin, "unknown action: " + action1);
connection.loginfo(plugin, `unknown action: ${action1}`)
}
next();
}

// full email address match
if (cfg[rcpt]) {
if (cfg[rcpt].action) action = cfg[rcpt].action;
return onMatch(rcpt, action);
if (cfg[rcpt]) { // full email address match
match = rcpt
if (cfg[match].action) action = cfg[match].action
onMatch(match, action, rcpt)
}

// @domain match
const dom_match = `@${host}`;
if (cfg[`@${host}`]) {
if (cfg[dom_match].action) action = cfg[dom_match].action;
match = dom_match;
return onMatch(dom_match, action);
if (cfg[`@${host}`]) { // @domain match
match = `@${host}`
if (cfg[match].action) action = cfg[match].action
onMatch(match, action, match)
}

// user only match
if (cfg[user]) {
if (cfg[user].action) action = cfg[user].action;
return onMatch(user, action);
if (cfg[user]) { // user only match
match = user
if (cfg[user].action) action = cfg[user].action
onMatch(match, action, rcpt)
}

// user prefix match
if (cfg[match[0]]) {
if (cfg[match[0]].action) action = cfg[match[0]].action;
return onMatch(match[0], action);
else if (cfg[match[0]]) {
match = match[0]
if (cfg[match].action) action = cfg[match].action
onMatch(match, action, rcpt)
}

// user prefix + domain match
const prefix_dom = `${match[0]}@${host}`;
if (cfg[prefix_dom]) {
if (cfg[prefix_dom].action) action = cfg[prefix_dom].action;
return onMatch(prefix_dom, action);
else if (cfg[`${match[0]}@${host}`]) { // user prefix + domain match
match = `${match[0]}@${host}`
if (cfg[match].action) action = cfg[match].action
onMatch(match, action, rcpt)
}

next();
};
next()
}

function _drop (plugin, connection, rcpt) {
connection.logdebug(plugin, "marking " + rcpt + " for drop");
connection.transaction.notes.discard = true;
connection.logdebug(plugin, `marking ${rcpt} for drop`)
if (!connection?.transaction?.notes) return
connection.transaction.notes.discard = true
}

function _alias (plugin, connection, key, config, host) {
const txn = connection.transaction;

if (!connection?.transaction) return
if (!config.to) {
connection.loginfo(plugin, `alias failed for ${key}, no "to" field in alias config`);
return;
connection.loginfo(plugin, `alias failed for ${key}, no "to" field in alias config`)
return
}

const txn = connection.transaction
if (Array.isArray(config.to)) {
connection.logdebug(plugin, `aliasing ${txn.rcpt_to} to ${config.to}`);
txn.rcpt_to.pop();
config.to.forEach((addr) => {
txn.rcpt_to.push(new Address(`<${addr}>`));
connection.logdebug(plugin, `aliasing ${txn.rcpt_to} to ${config.to}`)
txn.rcpt_to.pop()
config.to.forEach(addr => {
txn.rcpt_to.push(new Address(`<${addr}>`))
})
return;
}

let to = config.to;
if (to.search("@") === -1) {
to = config.to + '@' + host;
else {
const to = config.to.search('@') === -1 ? `${config.to}@${host}` : config.to
connection.logdebug(plugin, `aliasing ${txn.rcpt_to} to ${to}`)
txn.rcpt_to.pop()
txn.rcpt_to.push(new Address(`<${to}>`))
}

connection.logdebug(plugin, "aliasing " + txn.rcpt_to + " to " + to);
txn.rcpt_to.pop();
txn.rcpt_to.push(new Address(`<${to}>`));
txn.notes.forward = true
}
Loading

0 comments on commit 8dea17a

Please sign in to comment.