haraka / Haraka

A fast, highly extensible, and event driven SMTP server
https://haraka.github.io
MIT License
5.04k stars 662 forks source link

fix: get plugin hooks from doc/Plugins #3306

Closed msimerson closed 6 months ago

msimerson commented 6 months ago

Fixes #3272, Fixes #3212

Changes proposed in this pull request:

Checklist:

msimerson commented 6 months ago

Natively:

fs.readFileSync('docs/Plugins.md').toString()
  .split('## Available Hooks')[1]    // discard everything before this string
  .split('### rcpt')[0]              // discard everything after this string
  .match(/\*\s(\S+)/gm)              // grab the first word of lines starting with '* '
  .map(a => a.replace(/^\* /, '').replace(/\\/g, ''))  // strip off list prefix and escapes

awk

    child.spawnSync('awk', ['/## Available/,/## rcpt/{ if (/^\\*/) print $2 }', 'docs/Plugins.md'])
        .stdout.toString()
        .replace(/\\/g, '')
        .split('\n')

Clumsily

This is clumsy because it doesn't always preserve hook firing order. See haraka/Haraka#3212

const hooks = Object.keys(plugins.registered_hooks);