Skip to content

Commit

Permalink
feat: update for compat with redis 4
Browse files Browse the repository at this point in the history
  • Loading branch information
msimerson committed May 25, 2022
1 parent 45a5c48 commit 479d78e
Show file tree
Hide file tree
Showing 10 changed files with 50 additions and 115 deletions.
4 changes: 2 additions & 2 deletions .codeclimate.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
plugins:
plugins:
eslint:
enabled: true
channel: "eslint-4"
channel: "eslint-8"
config:
config: ".eslintrc.yaml"
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
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.

9 changes: 9 additions & 0 deletions Changes.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,27 @@

### 1.0.4 - 2022-05-24

- dep(eslint): 4 -> 8
- dep(pi-redis): * -> 2


### 1.0.3 - 2019-04-11

- test fix for unitialized redis config block


### 1.0.2 - 2018-03-05

- for MX entries, previously only full email address matches in the file were parsed for LMTP/SMTP routes. Now all MX entries are parsed (email file, email domain, email redis, and domain redis) for URIs.
- use es6 arrow functions
- refactored the functions in rcpt() into separate functions (simplify, more testable)


### 1.0.1 - 2017-08-19

- enable Redis install on AppVeyor CI testing


### 1.0.0 - 2017-07-28

- imported from haraka/plugins/rcpt_to.routes
22 changes: 0 additions & 22 deletions appveyor.yml

This file was deleted.

46 changes: 19 additions & 27 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,18 +49,18 @@ exports.do_file_search = function (txn, address, domain, next) {
const plugin = this;

if (plugin.route_list[address]) {
txn.results.add(plugin, {pass: 'file.email'});
txn.results.add(plugin, { pass: 'file.email' });
return next(OK);
}

if (plugin.route_list[domain]) {
txn.results.add(plugin, {pass: 'file.domain'});
txn.results.add(plugin, { pass: 'file.domain' });
return next(OK);
}

// not permitted (by this rcpt_to plugin)
txn.results.add(plugin, {fail: 'file'});
return next();
txn.results.add(plugin, { fail: 'file' });
next();
}

exports.get_rcpt_address = function (rcpt) {
Expand All @@ -76,12 +76,8 @@ exports.do_redis_search = function (connection, address, domain, next) {
plugin.db.multi()
.get(address)
.get(domain)
.exec((err, replies) => {
if (err) {
connection.results.add(plugin, {err: err});
return next();
}

.exec()
.then(replies => {
// got replies from Redis, any with an MX?
if (replies[0]) {
connection.transaction.results.add(plugin, {pass: 'redis.email'});
Expand All @@ -96,6 +92,10 @@ exports.do_redis_search = function (connection, address, domain, next) {
plugin.do_file_search(connection.transaction, address, domain, next);
}
})
.catch(err => {
connection.results.add(plugin, { err: err });
next();
})
}

exports.rcpt = function (next, connection, params) {
Expand Down Expand Up @@ -180,19 +180,19 @@ exports.get_mx = function (next, hmail, domain) {
plugin.db.multi()
.get(address)
.get(domain)
.exec((err, replies) => {
if (err) {
plugin.logerror(err);
return next();
}

.exec()
.then(replies => {
// got replies from Redis, any with an MX?
if (replies[0]) return next(OK, plugin.parse_mx(replies[0]));
if (replies[1]) return next(OK, plugin.parse_mx(replies[1]));

// no redis record, try files
plugin.get_mx_file(address, domain, next);
})
.catch(err => {
plugin.logerror(err);
next();
})
}

exports.insert_route = function (email, route) {
Expand All @@ -202,16 +202,8 @@ exports.insert_route = function (email, route) {
this.db.set(email, route);
}

exports.delete_route = function (email, cb) {
if (!this.redis_pings) {
if (cb) cb();
return false;
}
exports.delete_route = function (email) {
if (!this.redis_pings) return false;

if (cb) {
this.db.del(email, cb);
}
else {
this.db.del(email);
}
this.db.del(email);
}
9 changes: 5 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
"description": "Haraka plugin that validates and routes mail based on recipient domain or address",
"main": "index.js",
"scripts": {
"lint": "node node_modules/.bin/eslint *.js test/**/*.js",
"lintfix": "node node_modules/.bin/eslint --fix *.js test/**/*.js",
"lint": "npx eslint *.js test",
"lintfix": "npx eslint --fix *.js test",
"test": "node run_tests"
},
"repository": {
Expand All @@ -24,13 +24,14 @@
},
"homepage": "https://github.com/haraka/haraka-plugin-recipient-routes#readme",
"devDependencies": {
"eslint": ">=3",
"eslint": "8",
"eslint-plugin-haraka": "*",
"haraka-test-fixtures": "*",
"nodeunit": "*"
},
"dependencies": {
"haraka-plugin-redis": "*",
"haraka-plugin-redis": "2",
"redis": "4",
"url": "^0.11.0"
}
}
15 changes: 0 additions & 15 deletions test/.eslintrc.json

This file was deleted.

29 changes: 12 additions & 17 deletions test/recipient-routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,44 +33,41 @@ function _set_up_file (done) {

function _set_up_redis (done) {

this.server = {};
this.server = { notes: { } };

this.plugin = new fixtures.plugin('index');
this.plugin.register()

this.connection = fixtures.connection.createConnection();
this.connection.transaction = fixtures.transaction.createTransaction();
this.connection.transaction.results = new fixtures.results(this.connection);

this.plugin.register();
this.plugin.server = { notes: { } };
if (this.plugin.redisCfg.opts === undefined) this.plugin.redisCfg.opts = {}
this.plugin.redisCfg.opts.retry_strategy = function (options) {
return;
};

const t = this;
this.plugin.init_redis_shared(function (err) {
this.plugin.init_redis_shared(err => {
if (err) {
console.error(err.message);
return done();
}

t.plugin.db = t.plugin.server.notes.redis;
t.plugin.redis_ping(function (err2, result) {
if (err2) {
console.error(err2.message);
return done();
}
done(err2, result);
});
}, this.plugin.server);
this.plugin.db = this.server.notes.redis;
this.plugin.redis_ping().then(() => {
done()
}).catch(done)
}, this.server);
}

function _tear_down_redis (done) {
this.plugin.delete_route('matt@example.com', done);
this.plugin.delete_route('matt@example.com');
done()
}

exports.rcpt_file = {
setUp : _set_up_file,
tearDown : _tear_down_redis,
'miss' : function (test) {
test.expect(2);
function cb (rc, msg) {
Expand Down Expand Up @@ -107,8 +104,6 @@ exports.rcpt_file = {
}




exports.rcpt_redis = {
setUp : _set_up_redis,
tearDown : _tear_down_redis,
Expand Down

0 comments on commit 479d78e

Please sign in to comment.