-
-
Notifications
You must be signed in to change notification settings - Fork 661
Write a Plugin
Matt Simerson edited this page Apr 23, 2024
·
23 revisions
Before writing a new plugin, first check the Plugin Registry to see if that plugin exists.
Use the haraka-plugin-[UNIQUE]
naming style.
- the Plugins section of the manual
Clone the haraka-plugin-template and follow the instructions within.
Or set up the plugin directory yourself:
mkdir haraka-plugin-example && cd haraka-plugin-example
touch index.js // plugin code goes here
mkdir config test
echo '[main]' > config/example.ini
echo "const fixtures = require('haraka-test-fixtures');" > test/main.js
echo '# haraka-plugin-example' > README.md
echo "# 1.0.0 - $(date +%Y-%m-%d)" > Changes.md
npm init
npm install --save <npm modules your plugin requires>
npm install --save-dev haraka-test-fixtures eslint @haraka/eslint-config
Use this standard method for config loading:
exports.register = function () {
this.load_example_cfg()
}
exports.load_example_cfg = function () {
this.cfg = this.config.get('example.ini', () => {
this.load_example_cfg()
})
}
- the callback added to
config.get()
lets your plugins config get updated immediately when the config changes. No Haraka restart required. - storing the config contents at plugin.cfg lets the active configuration be accessed and manipulated by external processes. This is used heavily when adding test coverage.
If you have true/false booleans in your config, declare them and optionally, their defaults as well:
exports.load_example_cfg = function () {
this.cfg = this.config.get('example.ini', {
booleans: [
'+enabled', // this.cfg.main.enabled=true
'-disabled', // this.cfg.main.disabled=false
'+feature_section.yes' // this.cfg.feature_section.yes=true
]
},
() => {
this.load_example_cfg()
})
}
We ask that you use the coding style in @haraka/eslint-config. We've made it easy by publishing an eslint plugin that imports our rules automatically.
If you want a codeclimate badge to display in your README, you'll need to specify eslint version 8 in a .codeclimate.yml file.
engines:
eslint:
enabled: true
channel: "eslint-8"
config:
config: ".eslintrc.yaml"
ratings:
paths:
- "**.js"
Install Guides
How To
- Upgrade Haraka
- Google Safe Browsing
- Require TLS
- Configure my Editor
- Contribute
- Roll a Release
- Test Email
- Write a Plugin
Future Plans / TODO
Support RFC3464 in bounce messages- Decode Short URLs in data.uribl.js and test the destination URL instead
DKIM verifier
Additional Resources