Skip to content

Instantly share code, notes, and snippets.

@Dexus
Last active September 24, 2015 13:54
Show Gist options
  • Save Dexus/7d4f0731e522933908d0 to your computer and use it in GitHub Desktop.
Save Dexus/7d4f0731e522933908d0 to your computer and use it in GitHub Desktop.
save for each rcpt in haraka mail server
var fs = require('fs');
var os = require('os');
var tempDir = os.tmpdir();
exports.hook_queue = function(next, connection) {
var i;
var done=0;
var ws = [];
var rcpts = transaction.rcpt_to.lenght;
for(i=0;i<rcpts;i++){
var ws[i] = fs.createWriteStream(
tempDir + '/mail.' + transaction.uuid + '.' + transaction.rcpt_to[i].user +
'.' + transaction.rcpt_to[i].host + '.' + i + '.eml'
);
ws[i].once('close', function () {
done++;
if(done === (rcpts - 1)){
return next(OK);
}
});
connection.transaction.message_stream.pipe(ws[i]);
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment