npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@tobnor/node-email-reply-parser

v0.1.31

Published

Parses emails to remove replies and other potentially unwanted data

Downloads

1

Readme

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.