@ch4nn0n/email-forward-parser

中文文档
1.4.2发布于 2023/07/18MITCommonJS零依赖近 30 天下载 1万

Parses forwarded emails and extract content

原始使用文档
文档目录8 节
  1. Motivation
  2. Features
  3. Usage
  4. API
  5. Parse a forwarded email
  6. How does it work?
  7. Contributing
  8. License

Email Forward Parser

Test and Build Build and Release NPM Downloads

Parses forwarded emails and extracts original content.

This library supports most common email clients and locales.

Motivation

The original project from Crisp email-reply-parser relies on the RE2 library, which is not available on all platforms, namely some serverless and browser environments. This fork is a pure javascript implementation of the same library.

Features

  • Supported clients: Apple Mail, Gmail, Outlook Live / 365, Outlook 2013, Outlook 2019, New Outlook 2019, Yahoo Mail, Thunderbird, Missive, HubSpot, IONOS by 1 & 1
  • Supported locales: Croatian, Czech, Danish, Dutch, English, French, Finnish, German, Hungarian, Italian, Japanese, Norwegian, Polish, Portuguese (Brazil), Portuguese (Portugal), Romanian, Russian, Slovak, Spanish, Swedish, Turkish, Ukrainian

Usage

const EmailForwardParser = require("email-forward-parser");

const result = new EmailForwardParser().read(MY_EMAIL_STRING);

console.log(result.forwarded);
// true

API

Parse a forwarded email

read(body, subject) checks whether an email was forwarded or not, and parses its original content (From, To, Cc, Subject, Date and Body):

  • body must be a string representing the email body (as returned by mailparser, for example)
  • subject must be a string representing the email subject. This parameter is optional, but recommended to improve the detection for some email clients (especially New Outlook 2019)
const EmailForwardParser = require("email-forward-parser");

const result = new EmailForwardParser().read(MY_EMAIL_STRING, MY_SUBJECT_STRING);

console.log(result);
// {
//   forwarded: true,
//
//   message: "Praesent suscipit egestas hendrerit.",
//
//   email: {
//     body: "Aenean quis diam urna.",
//
//     from: {
//       address: "[email protected]",
//       name: "John Doe"
//     },
//     to: [{
//       address: "[email protected]",
//       name: "Bessie Berry"
//     }],
//     cc: [{
//       address: "[email protected]",
//       name: "Walter Sheltan"
//     }],
//
//     subject: "Integer consequat non purus",
//     date: "25 October 2021 at 11:17:21 EEST"
//   }
// }

How does it work?

Email forwarding (i.e. when you manually forward a copy of an email by clicking the "Forward" button in your email client) is not standardized by any RFC. Meaning that email clients are free to format the forwarded email the way they want.

There is no magic bullet to handle such disparities. The only viable solution is to rely on regular expressions (a lot!), to account for each email client's specificities:

ClientDetectable via subjectDetectable via separatorSubject localizedSeparator localizedAll original information availableOriginal information localizedOther specificities
Apple MailYesYesYesYesYesYes--
GmailYesYesNoNoYesOnly some parts--
Outlook Live / 365YesYesYesNoYesNo--
Outlook 2013YesNo?--??--
Outlook 2019YesYesNoYesNoYesThe From and Date parts (only original information available) are embedded in the separator, rather than the body itself
New Outlook 2019YesNoYes--YesYes--
Yahoo MailYesYesNoYesYesYesThe original information are all stuck to each other, without line breaks
ThunderbirdYesYesNoYesYesYes--
MissiveYesYesNoNoYesNo--
HubSpotYesYesYesYesYesYes--
IONOS by 1 & 1?Yes??Yes?--

Contributing

Feel free to fork this project and submit fixes. We may adapt your code to fit the codebase.

You can run unit tests using:

npm test

License

email-forward-parser is released under the MIT License. See the bundled LICENSE file for details.

版本与发布记录

@ch4nn0n/email-forward-parser 共发布 1 个版本,首次发布于 2023/07/18;过去 12 个月发布了 0 个版本。

版本发布日期距今
1.4.2latest2023/07/183 年前

关于 @ch4nn0n/email-forward-parser 的常见问题

@ch4nn0n/email-forward-parser 是什么?

Parses forwarded emails and extract content

如何安装 @ch4nn0n/email-forward-parser?

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

@ch4nn0n/email-forward-parser 支持 TypeScript 吗?

该包的 package.json 没有声明类型入口。需要类型提示时,可以在 npm 上查找社区维护的 @types/ch4nn0n__email-forward-parser 是否存在。

@ch4nn0n/email-forward-parser 支持 ESM 还是 CommonJS?

以 CommonJS 形式发布,可以直接 require();在 ES Module 项目中也可以用 import 引入(Node.js 会把 module.exports 作为默认导出)。

@ch4nn0n/email-forward-parser 可以商用吗?

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

@ch4nn0n/email-forward-parser 的下载量有多少?

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

@ch4nn0n/email-forward-parser 还在维护吗?

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