Created
May 19, 2011 22:26
-
-
Save arlolra/981943 to your computer and use it in GitHub Desktop.
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
// A queue to deliver to couch | |
var cradle = require('cradle'), | |
logger = require('nebulog'), | |
fs = require('fs'), | |
config = JSON.parse(fs.readFileSync('config.json', 'utf8')), | |
db = new (cradle.Connection)(config.couch).database(config.couch.database); | |
exports.hook_queue = function(next, connection) { | |
var ct = connection.transaction; | |
if (ct.data_lines.length === 0) { return next(DENY); } | |
var rcpt_to = []; | |
ct.rcpt_to.forEach(function (rcpt) { | |
rcpt_to.push(rcpt.address()); | |
}); | |
db.save({ | |
docType: 'email', | |
dateReceived: (new Date()).toISOString().split('T')[0], | |
body: ct.data_lines.join(''), | |
to: rcpt_to, | |
from: connection.transaction.mail_from.address() | |
}, function (err, res) { | |
if (err) { | |
logger.warn("Saving the email to db failed"); | |
return next(DENY, "Saving to db failed"); | |
} | |
return next(OK); | |
}); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment