Skip to content

Instantly share code, notes, and snippets.

@stepankuzmin
Created December 25, 2020 12:30
Show Gist options
  • Save stepankuzmin/084a1e4c34eb2f6630e991556a0c46b3 to your computer and use it in GitHub Desktop.
Save stepankuzmin/084a1e4c34eb2f6630e991556a0c46b3 to your computer and use it in GitHub Desktop.
Parse Mbox
const fs = require("fs");
const Mbox = require("node-mbox");
const { simpleParser } = require("mailparser");
const mbox = new Mbox("./some.mbox/mbox");
const stream = fs.createWriteStream("./emails.json");
stream.write("[");
mbox.on("message", function (msg) {
simpleParser(msg.toString(), null, (err, parsed) => {
if (err) {
throw new Error(err);
}
stream.write(JSON.stringify(parsed));
stream.write(",");
});
});
mbox.on("error", function (err) {
throw new Error(err);
});
mbox.on("end", function () {
stream.end("]");
console.log('Done')
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment