Ive been exploring the haraka (http://haraka.github.io ) and Ive successfully install it on my linux machine. I'm wondering if there is a good tutorial on parsing an email meta headers and content body using haraka. Ive check on their manual but I couldnt find it. Any ideas/suggestions on how to do that would greatly appreciated. Thanks.
Here is my script to retrieve the email body:
var winston = require('winston');
exports.hook_data = function (next, connection) {
winston.log('info', '----------------------------------------');
winston.log('info', 'hook_data');
// enable mail body parsing
connection.transaction.parse_body = true;
winston.log('info', "body="+connection.transaction.body);
winston.log('info', "mail_from="+connection.transaction.mail_from);
next();
}
The output:
{"level":"info","message":"----------------------------------------","timestamp":"2015-01-12T07:16:28.216Z"}
{"level":"info","message":"hook_data","timestamp":"2015-01-12T07:16:28.217Z"}
{"level":"info","message":"body=null","timestamp":"2015-01-12T07:16:28.218Z"}
{"level":"info","message":"mail_from=myemail@hostname.com","timestamp":"2015-01-12T07:16:28.218Z"}
As you can see the body contains a null value.
You can retrieve email body using below code
connection.transaction.body.body_text_encoded
connection.transaction.body.bodytext
It's code is easy to understand. You can read it and do according to you.