-
-
Save veer66/3450d094d344713a7d6a 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
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