Skip to content

Instantly share code, notes, and snippets.

@knalli
Created March 11, 2014 14:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save knalli/9487166 to your computer and use it in GitHub Desktop.
Save knalli/9487166 to your computer and use it in GitHub Desktop.
Given a raw mail content `mail.raw`, this decodes and extracts the html part and writes it into `mail.output.html`.
{
"name": "extract-html-from-raw-mail",
"version": "1.0.0",
"main": "parse.js",
"dependencies": {
"mailparser": "~0.4.1"
},
"author": "knalli <knallisworld@googlemail.com>",
"license": "MIT"
}
var MailParser = require("mailparser").MailParser;
var mailparser = new MailParser();
var FS = require('fs');
FS.readFile('./mail.raw', function (err, data) {
if (err) {
console.error("Failed read: " + err.message);
return;
}
var email = data;
mailparser.on("end", function(mail_object){
FS.writeFile('./mail.output.html', mail_object.html, function (err) {
if (err) {
console.error("Failed write: " + err.message);
}
});
});
mailparser.write(email);
mailparser.end();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment