Skip to content

Commit

Permalink
Merge branch 'master' into release-3.0.3
Browse files Browse the repository at this point in the history
  • Loading branch information
msimerson authored Feb 8, 2024
2 parents 216dbc4 + 9b3521a commit 5d946b2
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 44 deletions.
6 changes: 3 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
# DOCKER-VERSION 0.5.3

# See http://phusion.github.io/baseimage-docker/
FROM phusion/baseimage:master
FROM phusion/baseimage:focal-1.2.0

MAINTAINER Justin Plock <[email protected]>

Expand All @@ -23,8 +23,8 @@ RUN /etc/my_init.d/00_regen_ssh_host_keys.sh

RUN sed 's/main$/main universe/' -i /etc/apt/sources.list
RUN DEBIAN_FRONTEND=noninteractive apt-get -y -q update
RUN DEBIAN_FRONTEND=noninteractive apt-get -y -q install python-software-properties g++ make git curl
RUN curl -sL https://deb.nodesource.com/setup_10.x | setuser root bash -
RUN DEBIAN_FRONTEND=noninteractive apt-get -y -q install software-properties-common g++ make git curl
RUN curl -sL https://deb.nodesource.com/setup_18.x | setuser root bash -
RUN DEBIAN_FRONTEND=noninteractive apt-get -y -q install nodejs && \
apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*

Expand Down
85 changes: 46 additions & 39 deletions docs/Plugins.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ Display the help text for a plugin by running:
## Overview



## Anatomy of a Plugin

Plugins in Haraka are JS files in the `plugins` directory (legacy) and npm
Expand All @@ -42,37 +41,43 @@ There are two ways for plugins to register hooks. Both examples register a funct

1. The `register_hook` function in register():

exports.register = function() {
this.register_hook('rcpt', 'my_rcpt_validate');
};
```js
exports.register = function () {
this.register_hook('rcpt', 'my_rcpt_validate')
};

exports.my_rcpt_validate = function (next, connection, params) {
// do processing
next();
};
exports.my_rcpt_validate = function (next, connection, params) {
// do processing
next()
};
```

2. The hook_[$name] syntax:

exports.hook_rcpt = function (next, connection, params) {
// do processing
next();
};
```js
exports.hook_rcpt = function (next, connection, params) {
// do processing
next()
}
```

The register_hook function within `register()` offers a few advantages:

1. register a hook multiple times (see below)
2. a unique function name in stack traces
3. [a better function name](https://google.com/search?q=programming%20good%20function%20names)
4. hooks can be registered conditionally (ie, based on a config setting)
1. register a hook multiple times (see below)
2. a unique function name in stack traces
3. [a better function name](https://google.com/search?q=programming%20good%20function%20names)
4. hooks can be registered conditionally (ie, based on a config setting)

### Register a Hook Multiple Times

To register the same hook more than once, call `register_hook()` multiple times with the same hook name:

exports.register = function() {
this.register_hook('queue', 'try_queue_my_way');
this.register_hook('queue', 'try_queue_highway');
};
```js
exports.register = function () {
this.register_hook('queue', 'try_queue_my_way')
this.register_hook('queue', 'try_queue_highway')
};
```

When `try_queue_my_way()` calls `next()`, the next function registered on hook *queue* will be called, in this case, `try_queue_highway()`.

Expand All @@ -81,17 +86,18 @@ When `try_queue_my_way()` calls `next()`, the next function registered on hook *
When a single function runs on multiple hooks, the function can check the
*hook* property of the *connection* or *hmail* argument to determine which hook it is running on:

exports.register = function() {
this.register_hook('rcpt', 'my_rcpt');
this.register_hook('rcpt_ok', 'my_rcpt');
};
exports.my_rcpt = function (next, connection, params) {
var hook_name = connection.hook; // rcpt or rcpt_ok
// email address is in params[0]
// do processing
}

```js
exports.register = function () {
this.register_hook('rcpt', 'my_rcpt')
this.register_hook('rcpt_ok', 'my_rcpt')
};

exports.my_rcpt = function (next, connection, params) {
const hook_name = connection.hook; // rcpt or rcpt_ok
// email address is in params[0]
// do processing
}
```

### Next()

Expand Down Expand Up @@ -252,12 +258,11 @@ This is important as some plugins might rely on `results` or `notes` that have b

If you are writing a complex plugin, you may have to split it into multiple plugins to run in a specific order e.g. you want hook_deny to run last after all other plugins and hook_lookup_rdns to run first, then you can explicitly register your hooks and provide a `priority` value which is an integer between -100 (highest priority) to 100 (lowest priority) which defaults to 0 (zero) if not supplied. You can apply a priority to your hook in the following way:

````
exports.register = function() {
var plugin = this;
plugin.register_hook('connect', 'hook_connect', -100);
```js
exports.register = function () {
this.register_hook('connect', 'hook_connect', -100);
}
````
```

This would ensure that your hook_connect function will run before any other
plugins registered on the `connect` hook, regardless of the order it was
Expand Down Expand Up @@ -370,9 +375,11 @@ to remote servers. See [Issue 2024](https://github.com/haraka/Haraka/issues/2024

e.g.

exports.shutdown = function () {
clearInterval(this._interval);
}
```js
exports.shutdown = function () {
clearInterval(this._interval);
}
```

If you don't implement this in your plugin and have a connection open or a
timer running then Haraka will take 30 seconds to shut down and have to
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"node-gyp": "^10.0.1",
"nopt": "~7.2.0",
"npid": "~0.4.0",
"semver": "~7.5.4",
"semver": "~7.6.0",
"sprintf-js": "~1.1.3",
"haraka-config": "^1.1.0",
"haraka-constants": "^1.0.6",
Expand All @@ -38,7 +38,7 @@
"haraka-net-utils": "^1.5.2",
"haraka-notes": "^1.0.6",
"haraka-plugin-attachment": "^1.0.7",
"haraka-plugin-spf": "1.2.3",
"haraka-plugin-spf": "1.2.4",
"haraka-plugin-redis": "^2.0.5",
"haraka-results": "^2.2.3",
"haraka-tld": "^1.1.2",
Expand Down

0 comments on commit 5d946b2

Please sign in to comment.