Created
December 25, 2020 12:30
-
-
Save stepankuzmin/084a1e4c34eb2f6630e991556a0c46b3 to your computer and use it in GitHub Desktop.
Parse Mbox
This file contains hidden or 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
| 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