haraka / haraka-plugin-aliases

Email aliases for Haraka
https://www.npmjs.com/package/haraka-plugin-aliases
MIT License
1 stars 8 forks source link
aliases email haraka haraka-plugin

Build Status Code Climate NPM

haraka-plugin-aliases

This plugin allows the configuration of aliases that perform an action or change the RCPT address. Aliases are specified in a JSON formatted config file, and must have an action. Syntax errors found in the JSON config will stop the server.

IMPORTANT: this plugin must appear in config/plugins before other plugins that run on hook_rcpt

WARNING: DO NOT USE THIS PLUGIN WITH queue/smtp_proxy.

Configuration

aliases

JSON formatted config file that contains keys to match against RCPT addresses, and values that are objects with an "action" : "" property. Example:

{ "test1": { "action": "drop" } }

In the above example the "test1" alias will drop any message that matches test1, test1-, or test1+ (wildcard '-' or '+', see below). Actions may have 0 or more options listed like so:

{ "test3": { "action": "alias", "to": "test3-works" } }

In the above example the "test3" alias has an action of "alias" and a mandatory "to" field. If "to" were missing the alias would fail and an error would be emitted.

Aliases of 'user', '@host' and 'user@host' possible:

{ "demo" : { "action" : "drop" } }
    or
{ "@example.com" : { "action" : "drop" } }
    or
{ "demo@example.com" : { "action" : "drop" } }

Aliases may be expanded to multiple recipients:

{
  "sales@example.com": {
    "action": "alias",
    "to": ["alice@example.com", "bob@example.com"]
  }
}

wildcard notation

This plugin supports wildcard matching of aliases against the right most string of a RCPT address. The characters '-' and '+' are commonly used for subaddressing and this plugin can alias the "user" part of the address.

If the address were test2-testing@example.com (or test2+testing@example.com), the below alias would match:

{ "test2": { "action": "drop" } }

Larger and more specific aliases match first when using wildcard '-' notation. If the above RCPT was evaluated with this alias config, it would alias:

{
  "test2": { "action": "drop" },
  "test2-testing": { "action": "alias", "to": "test@foo.com" }
}

It also allows you to route all emails to a certain domain:

{
  "*": { "action": "alias", "to": "test15-works@success.com" }
}

chaining and circuits

Alias chaining is not supported. As a side-effect, we enjoy protections against alias circuits.

Any valid JSON will due. Please consider keeping each alias on its own line so that others that wish to grep the aliases file have an easier time finding the full configuration for an alias.

This plugin was written with speed in mind. That means every lookup hashes into the alias file for its match. While the act of doing so is fast, it does mean that any duplicate alias entries will match nondeterministically. That is, we cannot predict what will happen here:

{
  "coinflip": { "action": "alias", "to": "heads@coin.com" },
  "coinflip": { "action": "alias", "to": "tails@coin.com" }
}

Due to node.js implementation, one result will likely always be chosen over the other, so this is not exactly a coinflip. We simply cannot say what the language implementation will do and it could change.

action (required)

The following is a list of supported actions and their options.

Example Configuration

{
  "test1": { "action": "drop" },
  "test2": { "action": "drop" },
  "test3": { "action": "alias", "to": "test3-works" },
  "test4": { "action": "alias", "to": "test4" },
  "test5": { "action": "alias", "to": "test5-works@success.com" },
  "test6": { "action": "alias", "to": "test6-works@success.com" }
}