Permalink
Browse files

qmd: log entries have connection UUID and

config fetching moved inside the rcpt_to hook
  • Loading branch information...
msimerson committed Dec 25, 2013
1 parent f1d25b9 commit 040258390638bf86cfff0145641e8f40637496c5
Showing with 36 additions and 37 deletions.
  1. +36 −37 plugins/rcpt_to.qmail_deliverable.js
@@ -8,101 +8,100 @@ var options = {
}
exports.register = function() {
- var config = this.config.get('rcpt_to.qmail_deliverable.ini');
+ this.register_hook('rcpt', 'rcpt_to_qmd');
+};
+
+exports.rcpt_to_qmd = function(next, connection, params) {
+ var config = this.config.get('rcpt_to.qmail_deliverable.ini');
options.host = config.main.host || '127.0.0.1';
options.port = config.main.port || 8998;
+ this.logdebug(connection, "host: " + options.host );
+ this.logdebug(connection, "port: " + options.port );
- this.logdebug(this, "host: " + options.host );
- this.logdebug(this, "port: " + options.port );
-
- this.register_hook('rcpt', 'rcpt_to_qmd');
-}
-
-exports.rcpt_to_qmd = function(next, connection, params) {
var rcpt = params[0];
var email = rcpt.address();
// TODO: this is a good place to validate email
- // the perl Qmail::Deliverable client does a rfc2822 "atext" test
- // but Haraka might have done this for us, by this point
+ // Qmail::Deliverable::Client does a rfc2822 "atext" test
+ // but Haraka might have done this for us, at this point?
- this.logdebug("checking " + email );
+ this.logdebug(connection, "checking " + email );
return get_qmd_response(next,this,connection,email);
}
-function get_qmd_response(next,plugin,connection,email) {
+function get_qmd_response(next,plugin,conn,email) {
options.path = '/qd1/deliverable?' + querystring.escape(email);
- plugin.logprotocol('PATH: ' + options.path);
+ plugin.logprotocol(conn, 'PATH: ' + options.path);
var req = http.get(options, function(res) {
- plugin.logprotocol('STATUS: ' + res.statusCode);
- plugin.logprotocol('HEADERS: ' + JSON.stringify(res.headers));
+ plugin.logprotocol(conn, 'STATUS: ' + res.statusCode);
+ plugin.logprotocol(conn, 'HEADERS: ' + JSON.stringify(res.headers));
res.setEncoding('utf8');
res.on('data', function (chunk) {
- plugin.logprotocol('BODY: ' + chunk);
+ plugin.logprotocol(conn, 'BODY: ' + chunk);
var hexnum = new Number(chunk).toString(16);
- return check_qmd_reponse(next,plugin,connection,hexnum);
+ return check_qmd_reponse(next,plugin,conn,hexnum);
});
}).on('error', function(e) {
- plugin.loginfo("Got error: " + e.message);
+ plugin.loginfo(conn, "Got error: " + e.message);
});
};
-function check_qmd_reponse(next,plugin,connection,hexnum) {
- plugin.logprotocol("HEXRV: " + hexnum );
+function check_qmd_reponse(next,plugin,conn,hexnum) {
+ plugin.logprotocol(conn,"HEXRV: " + hexnum );
switch(hexnum) {
case '11':
- plugin.loginfo("error, permission failure");
+ plugin.loginfo(conn, "error, permission failure");
return next();
case '12':
- plugin.loginfo("pass, qmail-command in dot-qmail");
+ plugin.loginfo(conn, "pass, qmail-command in dot-qmail");
return next(OK);
case '13':
- plugin.loginfo("pass, bouncesaying with program");
+ plugin.loginfo(conn, "pass, bouncesaying with program");
return next(OK);
case '14':
- var from = connection.transaction.mail_from.address();
+ var from = conn.transaction.mail_from.address();
if ( ! from || from === '<>') {
return next(DENY, "fail, mailing lists do not accept null senders");
}
- plugin.loginfo("pass, ezmlm list");
+ plugin.loginfo(conn, "pass, ezmlm list");
return next(OK);
case '21':
- plugin.loginfo("Temporarily undeliverable: group/world writable");
+ plugin.loginfo(conn, "Temporarily undeliverable: group/world writable");
return next();
case '22':
- plugin.loginfo("Temporarily undeliverable: sticky home directory");
+ plugin.loginfo(conn, "Temporarily undeliverable: sticky home directory");
return next();
case '2f':
- plugin.loginfo("error communicating with qmail-deliverabled.");
+ plugin.loginfo(conn, "error communicating with qmail-deliverabled.");
return next();
case 'f1':
- plugin.loginfo("pass, normal delivery");
+ plugin.loginfo(conn, "pass, normal delivery");
return next(OK);
case 'f2':
- plugin.loginfo("pass, vpopmail dir");
+ plugin.loginfo(conn, "pass, vpopmail dir");
return next(OK);
case 'f3':
- plugin.loginfo("pass, vpopmail alias");
+ plugin.loginfo(conn, "pass, vpopmail alias");
return next(OK);
case 'f4':
- plugin.loginfo("pass, vpopmail catchall");
+ plugin.loginfo(conn, "pass, vpopmail catchall");
return next(OK);
case 'f5':
- plugin.loginfo("pass, vpopmail vuser");
+ plugin.loginfo(conn, "pass, vpopmail vuser");
return next(OK);
case 'f6':
- plugin.loginfo("pass, vpopmail qmail-ext");
+ plugin.loginfo(conn, "pass, vpopmail qmail-ext");
return next(OK);
case 'fe':
- plugin.loginfo("error, SHOULD NOT HAPPEN");
+ plugin.loginfo(conn, "error, SHOULD NOT HAPPEN");
return next();
case 'ff':
- plugin.loginfo("fail, address not local");
+ plugin.loginfo(conn, "fail, address not local");
return next();
default:
- plugin.loginfo("error, unknown rv: " + hexnum);
+ plugin.loginfo(conn, "error, unknown rv: " + hexnum);
return next();
}
};

0 comments on commit 0402583

Please sign in to comment.