2017 © Pedro Peláez
 

library email-reply-parser

Port of the cool GitHub's EmailReplyParser library in PHP

image

willdurand/email-reply-parser

Port of the cool GitHub's EmailReplyParser library in PHP

  • Wednesday, February 7, 2018
  • by couac
  • Repository
  • 25 Watchers
  • 475 Stars
  • 505,346 Installations
  • PHP
  • 5 Dependents
  • 0 Suggesters
  • 53 Forks
  • 3 Open issues
  • 24 Versions
  • 12 % Grown

The README.md

EmailReplyParser

GitHub Actions Total
Downloads Latest Stable
Version, (*1)

EmailReplyParser is a PHP library for parsing plain text email content, based on GitHub's email_reply_parser library written in Ruby., (*2)

Installation

The recommended way to install EmailReplyParser is through Composer:, (*3)

composer require willdurand/email-reply-parser

Usage

Instantiate an EmailParser object and parse your email:, (*4)

<?php

use EmailReplyParser\Parser\EmailParser;

$email = (new EmailParser())->parse($emailContent);

You get an Email object that contains a set of Fragment objects. The Email class exposes two methods:, (*5)

  • getFragments(): returns all fragments;
  • getVisibleText(): returns a string which represents the content considered as "visible".

The Fragment represents a part of the full email content, and has the following API:, (*6)

<?php

$fragment = current($email->getFragments());

$fragment->getContent();

$fragment->isSignature();

$fragment->isQuoted();

$fragment->isHidden();

$fragment->isEmpty();

Alternatively, you can rely on the EmailReplyParser to either parse an email or get its visible content in a single line of code:, (*7)

$email = \EmailReplyParser\EmailReplyParser::read($emailContent);

$visibleText = \EmailReplyParser\EmailReplyParser::parseReply($emailContent);

Known Issues

Quoted Headers

Quoted headers aren't picked up if there's an extra line break:, (*8)

On <date>, <author> wrote:

> blah

Also, they're not picked up if the email client breaks it up into multiple lines. GMail breaks up any lines over 80 characters for you., (*9)

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

The above On ....wrote: can be cleaned up with the following regex:, (*10)

$fragment_without_date_author = preg_replace(
  '/\nOn(.*?)wrote:(.*?)$/si',
  "",
  $fragment->getContent()
);

Note though that we're search for "on" and "wrote". Therefore, it won't work with other languages., (*11)

Possible solution: Remove "reply@reply.github.com" lines..., (*12)

Weird Signatures

Lines starting with - or _ sometimes mark the beginning of signatures:, (*13)

Hello

--
Rick

Not everyone follows this convention:, (*14)

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:, (*15)

Hello

--
Rick

________________________________________
From: Bob [reply@reply.github.com]
Sent: Monday, March 14, 2011 6:16 PM
To: Rick

Unit Tests

Setup the test suite using Composer:, (*16)

$ composer install

Run it using PHPUnit:, (*17)

$ ./vendor/bin/simple-phpunit

Contributing

See CONTRIBUTING file., (*18)

Credits

  • GitHub
  • William Durand

License

EmailReplyParser is released under the MIT License. See the bundled LICENSE file for details., (*19)

The Versions

07/02 2018

dev-master

9999999-dev

Port of the cool GitHub's EmailReplyParser library in PHP

  Sources   Download

MIT

The Requires

  • php >=5.6.0

 

The Development Requires

email reply-parser

07/02 2018

2.8.0

2.8.0.0

Port of the cool GitHub's EmailReplyParser library in PHP

  Sources   Download

MIT

The Requires

  • php >=5.6.0

 

The Development Requires

email reply-parser

28/11 2017

2.7.0

2.7.0.0

Port of the cool GitHub's EmailReplyParser library in PHP

  Sources   Download

MIT

The Requires

  • php >=5.6.0

 

The Development Requires

email reply-parser

24/05 2017

2.6.0

2.6.0.0

Port of the cool GitHub's EmailReplyParser library in PHP

  Sources   Download

MIT

The Requires

  • php >=5.6.0

 

The Development Requires

email reply-parser

25/02 2016

2.5.0

2.5.0.0

Port of the cool GitHub's EmailReplyParser library in PHP 5.3

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

email reply-parser

01/10 2015

v2.4.1

2.4.1.0

Port of the cool GitHub's EmailReplyParser library in PHP 5.3

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

email reply-parser

31/07 2015

v2.4.0

2.4.0.0

Port of the cool GitHub's EmailReplyParser library in PHP 5.3

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

email reply-parser

10/05 2015

v2.3.1

2.3.1.0

Port of the cool GitHub's EmailReplyParser library in PHP 5.3

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

email reply-parser

09/01 2015

v2.3.0

2.3.0.0

Port of the cool GitHub's EmailReplyParser library in PHP 5.3

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

email reply-parser

21/10 2014

2.2.2

2.2.2.0

Port of the cool GitHub's EmailReplyParser library in PHP 5.3

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

email reply-parser

28/09 2014

2.2.1

2.2.1.0

Port of the cool GitHub's EmailReplyParser library in PHP 5.3

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

email reply-parser

07/08 2014

2.2.0

2.2.0.0

Port of the cool GitHub's EmailReplyParser library in PHP 5.3

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

email reply-parser

20/03 2014

2.1.0

2.1.0.0

Port of the cool GitHub's EmailReplyParser library in PHP 5.3

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

email reply-parser

30/01 2014

2.0.1

2.0.1.0

Port of the cool GitHub's EmailReplyParser library in PHP 5.3

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

email reply-parser

29/11 2013

2.0.0

2.0.0.0

Port of the cool GitHub's EmailReplyParser library in PHP 5.3

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

email reply-parser

28/11 2013

2.0.0-alpha1

2.0.0.0-alpha1

Port of the cool GitHub's EmailReplyParser library in PHP 5.3

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

email reply-parser

27/11 2013

1.1.0

1.1.0.0

Port of the cool GitHub's EmailReplyParser library in PHP 5.3

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

email reply-parser

12/06 2013

1.0.1

1.0.1.0

Port of the cool GitHub's EmailReplyParser library in PHP 5.3

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

email reply-parser

16/05 2013

1.0.0

1.0.0.0

Port of the cool GitHub's EmailReplyParser library in PHP 5.3

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

email reply-parser

15/05 2013

0.0.5

0.0.5.0

Port of the cool GitHub's EmailReplyParser library in PHP 5.3

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

email reply-parser

17/02 2013

0.0.4

0.0.4.0

Port of the cool GitHub's EmailReplyParser library in PHP 5.3

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

email reply-parser

09/02 2013

0.0.3

0.0.3.0

Port of the cool GitHub's EmailReplyParser library in PHP 5.3

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

email reply-parser

26/10 2012

0.0.2

0.0.2.0

Port of the cool GitHub's EmailReplyParser library in PHP 5.3

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

email reply-parser

13/05 2012

0.0.1

0.0.1.0

Port of the cool GitHub's EmailReplyParser library in PHP 5.3

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

email reply-parser