Skip to content

Instantly share code, notes, and snippets.

@lukyth
Forked from veer66/parse_mail.js
Last active March 9, 2016 07:38
Show Gist options
  • Save lukyth/b08b6046e1d67940fe9e to your computer and use it in GitHub Desktop.
Save lukyth/b08b6046e1d67940fe9e to your computer and use it in GitHub Desktop.
โปรแกรมสำหรับ แกะ e-mail จาก folder ครับ
// 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