Created
March 11, 2014 14:41
-
-
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`.
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
{ | |
"name": "extract-html-from-raw-mail", | |
"version": "1.0.0", | |
"main": "parse.js", | |
"dependencies": { | |
"mailparser": "~0.4.1" | |
}, | |
"author": "knalli <[email protected]>", | |
"license": "MIT" | |
} |
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
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