@bjoveski/node-email-reply-parser

中文文档
1.0.1发布于 2025/05/31MITTypeScript近 30 天下载 3.3万

Parses emails to remove replies and other potentially unwanted data

原始使用文档
文档目录3 节
  1. Quoted Headers
  2. Weird Signatures
  3. Strange Quoting

node-email-reply-parser

npm version

A port of willdurand/EmailReplyParser (which is a port of github/email_reply_parser) to nodejs

willdurand's port of the Github library supports multiple spoken languages and has some enhanced parsing and therefore was used as a template for this library.

Installing

This package can be found on npm:

npm install node-email-reply-parser

Note: This package is ES6 compatible and does not transpile automatically.

Usage

var replyParser = require("node-email-reply-parser");

var email = replyParser(emailContent);

email has two primary methods:

  • getFragments(): returns all the fragments of the email
  • getVisibleText(): returns the text that is considered 'visible'

getVisibleText() accepts an optional options object:

getVisibleText({aggressive: true})

Setting aggressive to true will make the parser assume that any fragment which is not hidden, but which is both preceded and followed by a hidden fragment, should not be visible. This works around the issue of clients breaking quoted text into multiple lines (e.g. Gmail).

Using aggressive mode runs the risk of losing visible lines which are interspersed with quoted lines, but is useful when parsing e.g. emails from a 'reply by email' feature which contain a large block of quoted text.

A fragment has the following functions:

  • getContent(): returns the content of the fragment
  • isSignature(): returns whether or not the fragment is likely a signature
  • isQuoted(): returns whether or not the fragment is likely a quote
  • isHidden(): returns whether or not the text is considered 'hidden'
  • isEmpty(): returns whether or not the fragment has any content

Passing true as the second argument to replyParser will have the return value be just the visible text:

$visibleText = replyParser($emailContent, true);

Known Issues

The parser is not able to pick up some of the edge cases. They are outlined below.

Quoted Headers

Quoted headers aren't picked up if there's an extra line break:

On <date>, <author> wrote:

> blah

They also aren't picked up if the email client breaks it up into multiple lines, like gmail and it's 80 column automatic limit:

On <date>, <author>
wrote:
> blah

Weird Signatures

Lines starting with - or _ sometimes mark the beginning of signatures:

Hello

--
Rick

Not everyone follows this convention:

Hello

Mr Rick Olson
Galactic President Superstar Mc Awesomeville
GitHub

**********************DISCLAIMER***********************************
* Note: blah blah blah                                            *
**********************DISCLAIMER***********************************

Strange Quoting

Apparently, prefixing lines with > isn't universal either:

Hello

--
Rick

________________________________________
From: Bob [[email protected]]
Sent: Monday, March 14, 2011 6:16 PM
To: Rick

Unit Tests

Install the required dependencies:

npm install --dev

Run the tests:

npm test

Contributing

Please see the CONTRIBUTING.md file.

Credits

  • GitHub - Amazing Ruby gem for parsing emails
  • William Durand [email protected] - Extensive PHP version of GitHub's library

License

node-email-reply-parser is released under the MIT Licenses. Please see the bundled LICENSE file for details.

版本与发布记录

@bjoveski/node-email-reply-parser 共发布 2 个版本,首次发布于 2025/05/31;过去 12 个月发布了 0 个版本。

版本发布日期距今
1.0.1latest2025/05/311.4 年前
1.0.02025/05/311.4 年前

关于 @bjoveski/node-email-reply-parser 的常见问题

@bjoveski/node-email-reply-parser 是什么?

Parses emails to remove replies and other potentially unwanted data

如何安装 @bjoveski/node-email-reply-parser?

在项目目录运行 npm install @bjoveski/node-email-reply-parser,或使用 pnpm add / yarn add / bun add。

@bjoveski/node-email-reply-parser 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@bjoveski/node-email-reply-parser 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >= 14.0.0。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@bjoveski/node-email-reply-parser 可以商用吗?

@bjoveski/node-email-reply-parser 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@bjoveski/node-email-reply-parser 的下载量有多少?

根据 npm 官方下载统计,@bjoveski/node-email-reply-parser 在 2026/10/08 – 2026/11/06 这 30 天内被下载 32,761 次,日均约 1,092 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@bjoveski/node-email-reply-parser 还在维护吗?

最新版本 1.0.1 发布于 2025/05/31(1.4 年前);至今共发布 2 个版本,其中过去 12 个月发布了 0 个;首次发布于 2025/05/31。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。