Created
June 15, 2015 05:02
-
-
Save abhas/f240834f59eebe3b636a to your computer and use it in GitHub Desktop.
Simple haraka mail counter
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// params = [host, ip, response, delay, port, mode, recipients] | |
// 0 1 2 3 4 5 6 . | |
var winston = require('winston'); | |
require('winston-mongodb').MongoDB; | |
winston.add(winston.transports.MongoDB, { db: 'mail-logs', host: '127.0.0.1'}); | |
exports.hook_delivered = function (next, connection, params) { | |
connection.loginfo("delivered params are: " + connection.uuid + params + '|' + connection.notes.rcptokat | |
+ '|' + connection.notes.subject, this); | |
winston.info(connection.todo.uuid, { | |
host: params[0], | |
ip: params[1], | |
response: params[2], | |
delay: params[3], | |
mode: params[5], | |
recips: params[6], | |
size: connection.file_size, | |
num_failures: connection.num_failures, | |
envelope: connection.todo.mail_from, | |
subject: connection.notes.subject, | |
rcptok: connection.notes.rcptokat, | |
type: "delivery" | |
}); | |
next(); | |
} | |
exports.hook_bounce = function (next, connection, params) { | |
var util = require('util'); | |
var plugin = this; | |
var reason; | |
connection.loginfo("bounce params are: " + params, this); | |
connection.loginfo("connection details are: " + util.inspect(connection, false, null)); | |
connection.todo.rcpt_to.forEach(function(bounce) { | |
connection.loginfo("Mail for " + bounce.original + " rejected becasue of: " + bounce.reason, plugin); | |
}); | |
winston.info(connection.todo.uuid, { | |
ip: "todo", | |
response: connection.bounce_error, | |
recips: connection.todo.rcpt_to, | |
size: connection.file_size, | |
num_failures: connection.num_failures, | |
envelope: connection.todo.mail_from, | |
subject: connection.notes.subject, | |
type: "bounce" | |
}); | |
next(); | |
} | |
exports.hook_queue_ok = function (next, connection, params) { | |
connection.transaction.notes.subject = connection.transaction.header.get('subject').trim(); | |
next(); | |
} | |
exports.hook_rcpt_ok = function (next, connection, params) { | |
var strftime = require('strftime'); | |
connection.transaction.notes.rcptokat = strftime('%d-%m-%Y %H:%M:%S %Z'); | |
next(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment