Skip to content

Instantly share code, notes, and snippets.

@veer66
Forked from lukyth/parse_mail.js
Last active March 9, 2016 08:02
Show Gist options
  • Save veer66/3450d094d344713a7d6a to your computer and use it in GitHub Desktop.
Save veer66/3450d094d344713a7d6a to your computer and use it in GitHub Desktop.
โปรแกรมสำหรับ แกะ e-mail จาก folder ครับ
var MailParser = require('mailparser').MailParser
var fs = require('fs')
var dirname = 'data/'
var resultDir = 'result/'
var async = require('async');
if (!fs.existsSync(resultDir)){
fs.mkdirSync(resultDir)
}
var filenames = fs.readdirSync(dirname)
async.forEachOfSeries(filenames, function (filename, val, cb) {
var mailparser = new MailParser()
mailparser.filename = filename
mailparser.on('end', function(mail_object){
fs.writeFile(resultDir + mailparser.filename + '.json', JSON.stringify(mail_object))
cb();
})
mailparser.write(fs.readFileSync(dirname + filename).toString())
mailparser.end();
console.log(val, filename);
}, function(err) { console.log(err)});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment