-
-
Save lukyth/b08b6046e1d67940fe9e to your computer and use it in GitHub Desktop.
โปรแกรมสำหรับ แกะ e-mail จาก folder ครับ
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
// npm install mailparser | |
// node parse_mail.js | |
var MailParser = require('mailparser').MailParser | |
var fs = require('fs') | |
var dirname = 'sample/' | |
var resultDir = 'result/' | |
if (!fs.existsSync(resultDir)){ | |
fs.mkdirSync(resultDir) | |
} | |
var filenames = fs.readdirSync(dirname) | |
filenames.forEach(function (filename) { | |
var mailparser = new MailParser() | |
mailparser.filename = filename | |
mailparser.on('end', function(mail_object){ | |
fs.writeFile(resultDir + mailparser.filename + '.json', JSON.stringify(mail_object)) | |
}) | |
mailparser.write(fs.readFileSync(dirname + filename).toString()) | |
mailparser.end() | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment