Skip to content
This repository has been archived by the owner on Jun 25, 2022. It is now read-only.

Commit

Permalink
release-1.0.0
Browse files Browse the repository at this point in the history
- import from Haraka
- test: add 3 tests
  • Loading branch information
msimerson authored Jun 24, 2022
2 parents c6e4da5 + 8f92b65 commit c6088fb
Show file tree
Hide file tree
Showing 15 changed files with 1,924 additions and 214 deletions.
2 changes: 1 addition & 1 deletion .eslintrc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ extends:
- plugin:haraka/recommended

rules:
indent: [2, 2, {"SwitchCase": 1}]
indent: [warn, 4, {"SwitchCase": 1}]

root: true

Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ jobs:
lint:
uses: haraka/.github/.github/workflows/lint.yml@master

# coverage:
# uses: haraka/.github/.github/workflows/coverage.yml@master
# secrets: inherit
coverage:
uses: haraka/.github/.github/workflows/coverage.yml@master
secrets: inherit

test:
needs: [ lint, get-lts ]
Expand Down
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,10 @@ jspm_packages
.node_repl_history

package-lock.json
bower_components
# Optional npm cache directory
.npmrc
.idea
.DS_Store
.release
haraka-update.sh
3 changes: 0 additions & 3 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +0,0 @@
[submodule ".release"]
path = .release
url = git@github.com:msimerson/.release.git
54 changes: 49 additions & 5 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -1,14 +1,58 @@
.github
# Logs
logs
*.log
npm-debug.log*

# Runtime data
pids
*.pid
*.seed

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage

# nyc test coverage
.nyc_output

# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# node-waf configuration
.lock-wscript

# Compiled binary addons (http://nodejs.org/api/addons.html)
build/Release

# Dependency directories
node_modules
jspm_packages

# Optional npm cache directory
.npm

# Optional REPL history
.node_repl_history

package-lock.json
bower_components
# Optional npm cache directory
.npmrc
.idea
.DS_Store
haraka-update.sh

.github
.release
.codeclimate.yml
.editorconfig
.gitignore
.gitmodules
.lgtm.yml
appveyor.yml
codecov.yml
.travis.yml
.eslintrc.yaml
.eslintrc.json
.nyc_output
coverage
.codeclimate.yml
codecov.yml
1 change: 0 additions & 1 deletion .release
Submodule .release deleted from 20e8e5
24 changes: 4 additions & 20 deletions Changes.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,10 @@
### Unreleased


### [1.0.3] - 2022-06-05
### [1.0.0] - 2022-06-17

- ci: replace hard coded vers with node-lts-versions
- * ci(publish): add secrets: inherit
- ci: use reusable workflows (#18)
- Imported from [Haraka](https://github.com/haraka/Haraka)
-


### 1.0.2 - 2022-05-23

- packaging updates


### 1.0.1 - 2021-02-04

- added example tests that set up conn/txn
- add automated package publishing
- GH actions: consolidate \*nix & win tests


### 1.0.0 - 2017-02-02

- initial release
[1.0.3]: https://github.com/haraka/haraka-plugin-template/releases/tag/1.0.3
[1.0.0]: https://github.com/haraka/chunk-emitter/releases/tag/1.0.0
76 changes: 11 additions & 65 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,75 +2,21 @@
[![Code Climate][clim-img]][clim-url]
[![NPM][npm-img]][npm-url]

# haraka-plugin-template
# haraka-chunk-emitter

Clone me, to create a new Haraka plugin!

# Template Instructions

These instructions will not self-destruct after use. Use and destroy.

See also, [How to Write a Plugin](https://github.com/haraka/Haraka/wiki/Write-a-Plugin) and [Plugins.md](https://github.com/haraka/Haraka/blob/master/docs/Plugins.md) for additional plugin writing information.

## Create a new repo for your plugin

Haraka plugins are named like `haraka-plugin-something`. All the namespace after `haraka-plugin-` is yours for the taking. Please check the [Plugins](https://github.com/haraka/Haraka/blob/master/Plugins.md) page and a Google search to see what plugins already exist.

Once you've settled on a name, create the GitHub repo. On the repo's main page, click the _Clone or download_ button and copy the URL. Then paste that URL into a local ENV variable with a command like this:

```sh
export MY_GITHUB_ORG=haraka
export MY_PLUGIN_NAME=haraka-plugin-SOMETHING
```

Clone and rename the template repo:

```sh
git clone git@github.com:haraka/haraka-plugin-template.git
mv haraka-plugin-template $MY_PLUGIN_NAME
cd $MY_PLUGIN_NAME
git remote rm origin
git remote add origin "git@github.com:$MY_GITHUB_ORG/$MY_PLUGIN_NAME.git"
```

Now you'll have a local git repo to begin authoring your plugin

## rename boilerplate

Replaces all uses of the word `template` with your plugin's name.

./redress.sh [something]

You'll then be prompted to update package.json and then force push this repo onto the GitHub repo you've created earlier.


# Add your content here

## INSTALL

```sh
cd /path/to/local/haraka
npm install haraka-plugin-template
echo "template" >> config/plugins
service haraka restart
```

### Configuration

If the default configuration is not sufficient, copy the config file from the distribution into your haraka config dir and then modify it:
## USAGE

```sh
cp node_modules/haraka-plugin-template/config/template.ini config/template.ini
$EDITOR config/template.ini
```js
const chunk_emitter = require('haraka-chunk-emitter')
messagestream.write_ce = new ChunkEmitter();
```

## USAGE


<!-- leave these buried at the bottom of the document -->
[ci-img]: https://github.com/haraka/haraka-plugin-template/actions/workflows/ci.yml/badge.svg
[ci-url]: https://github.com/haraka/haraka-plugin-template/actions/workflows/ci.yml
[clim-img]: https://codeclimate.com/github/haraka/haraka-plugin-template/badges/gpa.svg
[clim-url]: https://codeclimate.com/github/haraka/haraka-plugin-template
[npm-img]: https://nodei.co/npm/haraka-plugin-template.png
[npm-url]: https://www.npmjs.com/package/haraka-plugin-template
[ci-img]: https://github.com/haraka/chunk-emitter/actions/workflows/ci.yml/badge.svg
[ci-url]: https://github.com/haraka/chunk-emitter/actions/workflows/ci.yml
[clim-img]: https://codeclimate.com/github/haraka/chunk-emitter/badges/gpa.svg
[clim-url]: https://codeclimate.com/github/haraka/chunk-emitter
[npm-img]: https://nodei.co/npm/chunk-emitter.png
[npm-url]: https://www.npmjs.com/package/chunk-emitter
2 changes: 0 additions & 2 deletions config/template.ini

This file was deleted.

86 changes: 70 additions & 16 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,74 @@
'use strict'
'use strict';

exports.register = function () {
this.load_template_ini()
}
const EventEmitter = require('events').EventEmitter;

class ChunkEmitter extends EventEmitter {
constructor (buffer_size) {
super();
this.buffer_size = parseInt(buffer_size) || (64 * 1024);
this.buf = null;
this.pos = 0;
this.bufs = [];
this.bufs_size = 0;
}

fill (input) {
if (typeof input === 'string') {
input = Buffer.from(input);
}

exports.load_template_ini = function () {
const plugin = this
// Optimization: don't allocate a new buffer until the input we've
// had so far is bigger than our buffer size.
if (!this.buf) {
// We haven't allocated a buffer yet
this.bufs.push(input);
this.bufs_size += input.length;
if ((input.length + this.bufs_size) > this.buffer_size) {
this.buf = Buffer.alloc(this.buffer_size);
const in_new = Buffer.concat(this.bufs, this.bufs_size);
input = in_new;
// Reset
this.bufs = [];
this.bufs_size = 0;
}
else {
return;
}
}

plugin.cfg = plugin.config.get('template.ini', {
booleans: [
'+enabled', // plugin.cfg.main.enabled=true
'-disabled', // plugin.cfg.main.disabled=false
'+feature_section.yes' // plugin.cfg.feature_section.yes=true
]
},
function () {
plugin.load_example_ini()
})
while (input.length > 0) {
let remaining = this.buffer_size - this.pos;
if (remaining === 0) {
this.emit('data', this.buf); //.slice(0));
this.buf = Buffer.alloc(this.buffer_size);
this.pos = 0;
remaining = this.buffer_size;
}
const to_write = ((remaining > input.length) ? input.length : remaining);
input.copy(this.buf, this.pos, 0, to_write);
this.pos += to_write;
input = input.slice(to_write);
}
}

end (cb) {
let emitted = false;
if (this.bufs_size > 0) {
this.emit('data', Buffer.concat(this.bufs, this.bufs_size));
emitted = true;
}
else if (this.pos > 0) {
this.emit('data', this.buf.slice(0, this.pos));
emitted = true;
}
// Reset
this.buf = null;
this.pos = 0;
this.bufs = [];
this.bufs_size = 0;
if (cb && typeof cb === 'function') cb();
return emitted;
}
}

module.exports = ChunkEmitter;
27 changes: 12 additions & 15 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,33 +1,30 @@
{
"name": "haraka-plugin-template",
"version": "1.0.3",
"description": "Haraka plugin that frobnicates email connections",
"name": "haraka-chunk-emitter",
"version": "1.0.0",
"description": "Haraka chunk emitter",
"main": "index.js",
"scripts": {
"lint": "npx eslint *.js test/*.js",
"lintfix": "npx eslint --fix *.js test/*.js",
"lint": "npx eslint *.js test",
"lintfix": "npx eslint --fix *.js test",
"versions": "npx dependency-version-checker check",
"test": "npx mocha"
},
"repository": {
"type": "git",
"url": "git+https://github.com/haraka/haraka-plugin-template.git"
"url": "git+https://github.com/haraka/chunk-emitter.git"
},
"keywords": [
"haraka",
"plugin",
"template"
"chunk-emitter"
],
"author": "Welcome Member <happy-haraka-hacker@example.com>",
"author": "Haraka Team <haraka.mail@gmail.com>",
"license": "MIT",
"bugs": {
"url": "https://github.com/haraka/haraka-plugin-template/issues"
"url": "https://github.com/haraka/chunk-emitter/issues"
},
"homepage": "https://github.com/haraka/haraka-plugin-template#readme",
"homepage": "https://github.com/haraka/chunk-emitter#readme",
"devDependencies": {
"eslint": "8",
"eslint-plugin-haraka": "*",
"haraka-test-fixtures": "*",
"mocha": "9"
"eslint": ">=8",
"eslint-plugin-haraka": "*"
}
}
Loading

0 comments on commit c6088fb

Please sign in to comment.