• Stars
    star
    621
  • Rank 72,294 (Top 2 %)
  • Language
    PHP
  • License
    MIT License
  • Created about 13 years ago
  • Updated about 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

PHP library for parsing plain text email content.

EmailReplyParser

GitHub Actions Total Downloads Latest Stable Version

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

Installation

The recommended way to install EmailReplyParser is through Composer:

composer require willdurand/email-reply-parser

Usage

Instantiate an EmailParser object and parse your email:

<?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:

  • 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:

<?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:

$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:

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.

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

The above On ....wrote: can be cleaned up with the following regex:

$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.

Possible solution: Remove "[email protected]" lines...

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

Setup the test suite using Composer:

$ composer install

Run it using PHPUnit:

$ ./vendor/bin/simple-phpunit

Contributing

See CONTRIBUTING file.

Credits

  • GitHub
  • William Durand

License

EmailReplyParser is released under the MIT License. See the bundled LICENSE file for details.

More Repositories

1

Negotiation

Content Negotiation tools for PHP.
PHP
1,371
star
2

Hateoas

A PHP library to support implementing representations for HATEOAS REST web services.
PHP
1,016
star
3

JsonpCallbackValidator

JSONP callback validator.
PHP
653
star
4

BazingaJsTranslationBundle

A pretty nice way to expose your Symfony translation messages to your client applications.
JavaScript
574
star
5

ArvernOS

💾 A minimal, experimental and "toy" monolithic kernel to learn about OS development // Work In Progress
C
325
star
6

BazingaHateoasBundle

Integration of the Hateoas library into Symfony.
PHP
290
star
7

BazingaFakerBundle

Put the awesome Faker library into the Symfony2 DIC and populate your database with fake data.
PHP
279
star
8

docker-elk

🐳 Creating an ELK stack could not be easier.
270
star
9

nmap

nmap is a PHP wrapper for Nmap.
PHP
154
star
10

willdurand.github.io

William Durand's website ✨
HTML
147
star
11

Propilex

Silex, Propel, Backbone, Stack, Hateoas, Negotiation, and so on!
PHP
134
star
12

anchorify.js

A dead simple JavaScript library for automatically creating anchored headings in your HTML documents.
JavaScript
117
star
13

BazingaRestExtraBundle

Provides extra features for your REST APIs built using Symfony.
PHP
95
star
14

puppet-nodejs

Puppet module to manage Node.js and NPM that just works.
Ruby
69
star
15

TravisLight

A build monitoring tool (buildwall) that allows you to quickly detect failing projects for Travis-CI.
JavaScript
64
star
16

rustwasm-addon

🦀 + 🕸 + 🦊 // A web-extension to reverse a string. Yep.
JavaScript
63
star
17

StateMachineBehavior

This behavior adds a finite state machine to your model.
PHP
38
star
18

EMD

Fast and Adaptive Bidimensional Empirical Mode Decomposition Using Order-Statistics Filter Based Envelope Estimation
C++
37
star
19

dotfiles

💻 My dotfiles.
Shell
36
star
20

hubot-cachet

A hubot script to manage incidents/statuses with Cachet.
CoffeeScript
34
star
21

BazingaOAuthServerBundle

[Symfony2] A server side implementation of the OAuth 1.0 protocol based on RFC 5849.
PHP
31
star
22

puppet-composer

Puppet module to install Composer.
Ruby
30
star
23

StackNegotiation

Stack middleware for content negotiation.
PHP
27
star
24

docker-logstash-forwarder

Docker image for Logstash Forwarder, formerly known as lumberjack.
25
star
25

TypehintableBehavior

Insane Propel behavior that helps you to be compliant with third-party interfaces by adding type hint to generated methods.
PHP
22
star
26

pihole-oled

💻 Pi-hole and system stats displayed on an OLED 0.96" screen.
Python
22
star
27

jenairienacacher.fr

Site informatif autour de l'argument "je n'ai rien à cacher".
HTML
22
star
28

pman

"pear-doc.php.net/pman" on Composer/Packagist!
Shell
20
star
29

EventDispatcherBehavior

Integrates the Symfony2 EventDispatcher component in your Model classes.
PHP
19
star
30

Speaker

Speaker aims to convert my blog posts in audio files.
Shell
16
star
31

EspWiFi

Arduino driver for the ESP8266 WiFi module.
C++
15
star
32

hubot-ansible

Let Hubot run `ansible-playbook` for you!
CoffeeScript
14
star
33

sonoff-webthing

💡 An alternative firmware to create "Things" with iTead Sonoff devices.
Makefile
13
star
34

pino-devtools

🌲 A transport for viewing logs in your favorite browser devtools!
JavaScript
13
star
35

jenkins-phing-symfony

Jenkins/Phing for symfony 1.x (Works with Hudson)
12
star
36

gitlab-elk-demo

A demo project showing how to integrate Gitlab with the ELK stack.
11
star
37

dynhost

📡 Automatically update a dynamic DNS record for an OVH domain.
Rust
11
star
38

workshop-rest-from-zero-to-hero

Workshop.
PHP
10
star
39

PublishableBehavior

The PublishableBehavior is designed to quickly add publish/unpublish features to your model.
PHP
10
star
40

container-registry-proxy

📖 A proxy that makes the GitHub Container Registry compatible with the Docker Registry HTTP API V2 specification.
Go
10
star
41

BazingaPropelEventDispatcherBundle

Integrates the Propel EventDispatcherBehavior into Symfony2.
PHP
10
star
42

docker-buildtools

9
star
43

chipolata

🌭 A CHIP-8 interpreter written in Rust.
Rust
9
star
44

clermontech-workshop-git-deploy

Material for my Git Workshop.
Shell
8
star
45

cwrm

📸 WiFi Remote Module ✨ // Work In Progress
Makefile
8
star
46

containers

📦 This is a repository with some code I wrote to learn more about containers.
Go
7
star
47

gitpod-firefox-dev

Firefox development with Gitpod = ❤️
Shell
6
star
48

gameboy-breakout-board

A GameBoy card slot breakout board.
OpenSCAD
6
star
49

Karotz-Plugin

A Jenkins Plugin for my beloved Karotz.
Java
6
star
50

puppet-bazinga

A set of Puppet roles and some useful functions.
Puppet
6
star
51

thesis

📝 Automated Test Generation for production systems with a Model-based Testing approach.
TeX
6
star
52

kicad-libs

William Durand's KiCad Libraries
OpenSCAD
6
star
53

DuckHunt

A little game in haXe.
Haxe
4
star
54

isomorphic-formdata

formdata-node + browser support = <3
JavaScript
4
star
55

StateMachineExporter

Generate a Graphviz compatible file (.dot file) from a Propel XML schema, and the StateMachineBehavior.
PHP
3
star
56

demo-pretty-printer

A demo project to complement my blog post about Pretty Printers.
JavaScript
3
star
57

amo-info

🦊 An extension to show information about AMO related services.
JavaScript
3
star
58

hardware-hacking-cast-device

Tools and design files related to my research on a cheap "cast device" clone.
C
3
star
59

uberdex

The official Uberdex!
2
star
60

puppet-stoplight

This module manages Stoplight, a powerful build monitoring tool.
Ruby
1
star
61

fx-attribution-data-reader

Attribution data reader for Firefox installers
JavaScript
1
star
62

drnd.me

CSS
1
star
63

universal-express-http-context

DEPRECATED: the work highlighted here has been merged into upstream.
JavaScript
1
star