mailparser

Stream-based Node.js library for parsing raw MIME emails into structured text, HTML, headers, and attachments.

Library
npm
v3.12.4
1,672 stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum. How we score it →
86 /100 Excellent
Development Activity 96
Maintenance 84
Community 76
Maturity 60
Momentum 28

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation. How we score it →
78 /100 Good
Architecture 85
Code Quality 78
Innovation 74
Learning Curve 58

mailparser is a battle-tested Node.js library from the Nodemailer project that turns raw MIME-formatted email messages into structured JavaScript objects. It processes everything as a stream, so it can handle very large messages — including big attachments — with low memory overhead instead of buffering the entire email in memory first.

The library exposes both a low-level MailParser transform stream for advanced control and a simpleParser convenience function that resolves a fully parsed mail object in one call, including decoded text/HTML bodies, headers, address fields, and buffered attachments. It handles the gritty parts of email parsing automatically: charset decoding (including Japanese encodings via iconv-lite and encoding-japanese), quoted-printable/base64 transfer encodings, embedded/inline images, delivery-status reports, and RFC 2047 encoded headers.

What You Get

  • A simpleParser function that returns a fully parsed mail object (subject, from/to/cc, text, html, attachments) from a Buffer, string, or readable stream in one call.
  • A lower-level MailParser transform stream for processing very large messages (100MB+) without buffering the whole message in memory.
  • Automatic character-set decoding for dozens of encodings, including specialized handling for Japanese encodings via encoding-japanese.
  • Built-in handling for embedded/inline images, CID link rewriting to data URIs, delivery-status reports, and RFC 2047 encoded-word headers.
  • Address parsing via Nodemailer’s addressparser, plus automatic plain-text-to-HTML and HTML-to-text conversion and link detection.

Common Use Cases

  • Building an email-processing backend that ingests inbound mail (e.g. from an SMTP server or webhook) and extracts subject, sender, body, and attachments for storage or indexing.
  • Parsing .eml files pulled from IMAP/POP3 mailboxes to build a webmail client, archiving tool, or compliance/eDiscovery pipeline.
  • Extracting attachments from bulk-received emails for automated document processing (invoices, receipts, reports).
  • Feeding raw email content into a spam-filtering, ticketing, or support-inbox system that needs structured header/body data rather than raw MIME.

Under The Hood

Architecture

mailparser is architected around a streaming MIME pipeline: the MailParser class (lib/mail-parser.js) extends Node’s Transform stream and pipes incoming data through a ChunkedPassthrough into a Splitter from the @zone-eu/mailsplit fork of mailsplit, which walks the MIME tree node by node. As each node arrives, MailParser tracks position in the tree (this.tree, this.curnode), attaches per-node charset decoders (IconvDecoder wrapping the node iconv library, or a custom JPDecoder for Japanese encodings via encoding-japanese), and emits ‘headers’ and object-mode ‘data’ events tagged type: ‘text’ or type: ‘attachment’ as content becomes available. lib/simple-parser.js is a thin, buffering wrapper: it drives a MailParser instance, accumulates attachment stream chunks into Buffers, and resolves a single flat mail object via callback or Promise, trading the streaming/low-memory advantage of the low-level API for ergonomics.

Tech Stack

The library is plain CommonJS JavaScript with no build/compile step and no TypeScript. Its runtime dependencies are narrowly scoped to MIME/email concerns: @zone-eu/mailsplit for MIME splitting, libmime for RFC 2047 header decoding, nodemailer’s internal addressparser for To/From/Cc parsing, iconv-lite and encoding-japanese for charset transcoding, html-to-text and linkify-it for text/HTML conversion and link detection, he for HTML entity handling, and tlds/punycode.js to support link detection and internationalized domains. Dev tooling is Grunt-based (grunt-contrib-nodeunit for tests) rather than a modern runner, with ESLint (nodemailer’s shared config) and Prettier for style, and an .ncurc.js config for automated dependency-update checks.

Code Quality

Test coverage is substantial: 13 test files under test/ (~2,100 lines) exercise the parser against real .eml fixtures, including dedicated regression tests named after specific GitHub issues (issue-221, issue-272, issue-337, issue-385, issue-412), plus focused suites for RFC822 headers-only messages, flowed text, delivery-status reports, long References headers, and address-security edge cases. There is no static typing (TypeScript or JSDoc-based), but error handling is deliberate: the JPDecoder’s charset conversion is wrapped in try/catch and falls back to passing raw bytes through on failure rather than throwing, and stream errors are surfaced via standard ‘error’ event propagation in both the low-level and simpleParser APIs.

API Design mailparser offers a two-tier API: simpleParser(input, options, callback) covers the common case with a single call that accepts a Buffer, string, or readable stream and resolves a fully-parsed mail object (Promise or callback), while the underlying MailParser transform stream is exposed directly for advanced consumers who need to process very large messages incrementally. Options are narrowly named and self-explanatory (skipHtmlToText, skipImageLinks, skipTextToHtml, keepCidLinks, keepDeliveryStatus), keeping boilerplate low. The main friction points are a thin README that defers full documentation to an external site (nodemailer.com/extras/mailparser) rather than inline docs, and the project’s maintenance-mode status, which points new adopters toward a separate project (PostalMime) for continued feature development.

Used by 16 apps in this directory

TypeScript
90%
MIT

OpenClaw

AI Agents · AI Assistants

392,894

An open-source AI assistant that runs on your own hardware and meets you in Discord, Slack, WhatsApp, iMessage, Telegram, and 20+ other channels, with native apps for every major platform.

View details
88
Repo Health
88
Technical
66
Dependency
Built with
TypeScript 90%
Updated 5 days ago
TypeScript
93%
Apache 2.0

Openship

Devops · Hosting Control Panel

14,912

Openship is an open-source, self-hostable deployment platform that points at a repo and builds, ships, routes, and TLS-terminates the app — driven from a desktop app, web dashboard, or CLI.

View details
84
Repo Health
85
Technical
65
Dependency
Built with
TypeScript 93%
Updated 5 days ago
TypeScript
98%
Other

Outline

Collaboration · Knowledge Management

41,045

A fast, real-time collaborative knowledge base for growing teams built on React, Node.js, and ProseMirror.

View details
91
Repo Health
87
Technical
68
Dependency
Built with
TypeScript 98%
Updated 5 days ago
Python
49%
Other

Arize Phoenix

Analytics · Devops · Monitoring

11,976

Open-source AI observability platform for tracing, evaluating, and debugging LLM applications with built-in intelligence and MCP support.

View details
92
Repo Health
88
Technical
67
Dependency
Built with
Python 49%
TypeScript 43%
Updated 5 days ago
TypeScript
97%
Other

Rocket.Chat

Team Chat

46,304

The secure, self-hosted team communications platform for organizations that cannot compromise on data sovereignty.

View details
96
Repo Health
79
Technical
63
Dependency
Built with
TypeScript 97%
Updated 5 days ago
TypeScript
100%
AGPL 3.0

RSSHub

Automation · Social Media

46,631

Turn any website into an RSS feed — social media, streaming platforms, and niche sites all become subscribable in seconds.

View details
94
Repo Health
82
Technical
71
Dependency
Built with
TypeScript 100%
Updated 5 days ago
TypeScript
90%
AGPL 3.0

useSend

Developer Tools · Marketing

4,753

Self-hostable open source email platform built on Amazon SES with a full dashboard, SMTP relay, REST API, and multi-language SDKs.

View details
76
Repo Health
72
Technical
68
Dependency
Built with
TypeScript 90%
Updated 1 weeks ago

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers