Skip to content

Commit

Permalink
Merge pull request haraka#586 from msimerson/data.headers
Browse files Browse the repository at this point in the history
data.headers: move config loading into register()
  • Loading branch information
smfreegard committed Jun 26, 2014
2 parents e665a9a + 5dbe4dd commit 856db9b
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 25 deletions.
47 changes: 23 additions & 24 deletions plugins/data.headers.js
Expand Up @@ -3,13 +3,34 @@ var net_utils = require('./net_utils');

exports.register = function () {
var plugin = this;

var load_config = function () {
plugin.cfg = plugin.config.get('data.headers.ini', {
booleans: [
'+check.duplicate_singular',
'+check.missing_required',
'+check.invalid_return_path',
'+check.invalid_date',
'+check.user_agent',
'+check.direct_to_mx',
'+check.from_match',
'+check.mailing_list',

'-reject.duplicate_singular',
'-reject.missing_required',
'-reject.invalid_return_path',
'-reject.invalid_date',
],
}, load_config);
};
load_config();

try {
plugin.addrparser = require('address-rfc2822');
}
catch (e) {
plugin.logerror("unable to load address-rfc2822, try\n\n\t'npm install -g address-rfc2822'\n\n");
}
this.register_hook('data', 'refresh_config');
this.register_hook('data_post', 'duplicate_singular');
this.register_hook('data_post', 'missing_required');
this.register_hook('data_post', 'invalid_date');
Expand All @@ -22,31 +43,9 @@ exports.register = function () {
this.register_hook('data_post', 'mailing_list');
};

exports.refresh_config = function(next, connection) {

this.cfg = this.config.get('data.headers.ini', {
booleans: [
'+check.duplicate_singular',
'+check.missing_required',
'+check.invalid_return_path',
'+check.invalid_date',
'+check.user_agent',
'+check.direct_to_mx',
'+check.from_match',
'+check.mailing_list',

'-reject.duplicate_singular',
'-reject.missing_required',
'-reject.invalid_return_path',
'-reject.invalid_date',
],
});
return next();
};

exports.duplicate_singular = function(next, connection) {
var plugin = this;
if (!plugin.cfg.check.duplicate_singular) return next();
if (!plugin.cfg.check.duplicate_singular) { return next(); }

// RFC 5322 Section 3.6, Headers that MUST be unique if present
var singular = plugin.cfg.main.singular !== undefined ?
Expand Down
2 changes: 1 addition & 1 deletion tests/plugins/data.headers.js
Expand Up @@ -15,7 +15,7 @@ function _set_up(callback) {
this.plugin = Plugin('data.headers');
this.plugin.name = 'data.headers'; // TODO: delete after PR#495 merged
this.plugin.config = config;
this.plugin.refresh_config(function(){ return; });
this.plugin.register();
try {
this.plugin.addrparser = require('address-rfc2822');
}
Expand Down

0 comments on commit 856db9b

Please sign in to comment.