The `node-mbox` library (current stable version 2.0.0) provides a fast, stream-based parser for mbox email archives in Node.js environments. It is designed to efficiently process large mbox files, reportedly handling 1.5GB in about 20 seconds. The library differentiates itself by focusing specifically on the mbox file structure parsing, emitting individual email messages as `Buffer` instances, rather than attempting to parse the intricate content of the email messages themselves (a task typically handled by companion libraries like `mailparser`). Version 2.0.0 introduces a completely new API, shifting towards a more idiomatic Node.js stream approach and allowing for custom line splitting technologies. While generally robust, it notes that it is not 100% compliant with RFC 4155, which is an important consideration for strict RFC adherence. Its release cadence appears to involve significant API revisions between major versions.
npm install node-mboxVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates three ways to use `node-mbox`: reading from a file, piping from a stream with a custom line splitter, and piping from a stream using the default splitter. It then shows how to listen for 'data', 'error', and 'finish' events to process parsed email messages, which are provided as Buffers.
Refer to the updated documentation and examples for v2.0.0, adopting the new stream-based API patterns.
Call `msg.toString([encoding])` to convert the buffer to a string for processing, or explicitly set the `encoding` option during Mbox instantiation.
Ensure your mbox files are well-formed. There is no option to disable strict parsing in v2.0.0.
Review your encoding requirements and explicitly configure buffer encoding options as needed for your specific use case.
Be aware of potential discrepancies when dealing with mbox files that strictly adhere to RFC 4155. Test thoroughly with your specific data.
Use `new Mbox()` for the class-based parser, or `MboxStream(stream, options)` for the functional convenience wrapper. Ensure you are using named imports `import { Mbox, MboxStream } from 'node-mbox'` or destructuring `const {Mbox, MboxStream} = require('node-mbox')`.Convert `msg` to a string first using `msg.toString([encoding])` before applying string-specific methods like `split()`.