{"library":"node-mbox","title":"Mbox File Parser for Node.js","description":"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.","language":"javascript","status":"active","last_verified":"Tue Apr 21","install":{"commands":["npm install node-mbox"],"cli":null},"imports":["import { Mbox } from 'node-mbox';","import { MboxStream } from 'node-mbox';"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import { Mbox, MboxStream } from 'node-mbox';\nimport fs from 'fs';\nimport split from 'line-stream';\n\n// 1. Pass it a filename\nconst mboxFromFile = new Mbox();\nfs.createReadStream('test/test-4-message.mbox').pipe(mboxFromFile);\n\n// 2. Pass it a stream and use a custom line splitter\nconst mailboxStream = fs.createReadStream('test/test-4-message.mbox');\nconst splitter = split('\\n');\nconst mboxFromCustomStream = mailboxStream.pipe(splitter).pipe(new Mbox());\n\n// 3. Pass it a stream and use the default line splitter (same as #2 without explicit splitter)\nconst mboxFromDefaultStream = MboxStream(fs.createReadStream('test/test-4-message.mbox'), { includeMboxHeader: false });\n\nconst activeMbox = mboxFromDefaultStream; // Choose one for demonstration\n\nactiveMbox.on('data', function(msg) {\n  // `msg` is a `Buffer` instance\n  console.log('Got a message (first 100 chars):', msg.toString().substring(0, 100) + '...');\n});\n\nactiveMbox.on('error', function(err) {\n  console.log('Got an error:', err);\n});\n\nactiveMbox.on('finish', function() {\n  console.log('Done reading mbox file.');\n});\n\n// Example for an input file. Create a dummy if it doesn't exist for running the quickstart.\n// You'd typically pipe real mbox data into this.\n// For quick testing, you can create a simple file:\n// echo \"From MAILER-DAEMON Mon Apr 18 10:00:00 2022\\nSubject: Test Email 1\\n\\nThis is the body of test email 1.\\n\\nFrom MAILER-DAEMON Mon Apr 18 10:01:00 2022\\nSubject: Test Email 2\\n\\nThis is the body of test email 2.\" > test/test-4-message.mbox","lang":"typescript","description":"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.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}