Skip to content

Commit

Permalink
ci: switch to github actions (#88)
Browse files Browse the repository at this point in the history
  • Loading branch information
willdurand authored Jan 30, 2022
1 parent 4b96a55 commit f25f8c6
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 54 deletions.
34 changes: 34 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: ci

on:
pull_request:
push:
branches:
- master

jobs:
phpunit:
runs-on: "ubuntu-20.04"

strategy:
fail-fast: false
matrix:
php-version:
- "7.4"
- "8.0"
- "8.1"

steps:
- uses: actions/checkout@v2

- name: "Install PHP ${{ matrix.php-version }}"
uses: "shivammathur/setup-php@v2"
with:
php-version: "${{ matrix.php-version }}"
coverage: "pcov"

- name: "Install dependencies with Composer"
uses: "ramsey/composer-install@v1"

- name: "Run PHPUnit"
run: "vendor/bin/simple-phpunit --coverage-text"
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
vendor/
composer.lock
.phpunit.result.cache
11 changes: 0 additions & 11 deletions .travis.yml

This file was deleted.

65 changes: 24 additions & 41 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
EmailReplyParser
================
# EmailReplyParser

[![Build
Status](https://secure.travis-ci.org/willdurand/EmailReplyParser.png)](http://travis-ci.org/willdurand/EmailReplyParser)
[![GitHub Actions](https://github.com/willdurand/EmailReplyParser/workflows/ci/badge.svg)](https://github.com/willdurand/EmailReplyParser/actions?query=workflow%3A%22ci%22+branch%3Amaster)
[![Total
Downloads](https://poser.pugx.org/willdurand/email-reply-parser/downloads.png)](https://packagist.org/packages/willdurand/email-reply-parser)
[![Latest Stable
Expand All @@ -12,23 +10,20 @@ Version](https://poser.pugx.org/willdurand/email-reply-parser/v/stable.png)](htt
based on GitHub's [email_reply_parser](http://github.com/github/email_reply_parser)
library written in Ruby.


Installation
------------
## Installation

The recommended way to install EmailReplyParser is through
[Composer](http://getcomposer.org/):

``` shell
```shell
composer require willdurand/email-reply-parser
```

Usage
-----
## Usage

Instantiate an `EmailParser` object and parse your email:

``` php
```php
<?php

use EmailReplyParser\Parser\EmailParser;
Expand All @@ -39,14 +34,14 @@ $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
- `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
```php
<?php

$fragment = current($email->getFragments());
Expand All @@ -65,15 +60,13 @@ $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:

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

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


Known Issues
------------
## Known Issues

### Quoted Headers

Expand All @@ -84,23 +77,23 @@ Quoted headers aren't picked up if there's an extra line break:
> 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.
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:

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

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

Possible solution: Remove "[email protected]" lines...
Expand All @@ -127,8 +120,6 @@ Not everyone follows this convention:
* Note: blah blah blah *
**********************DISCLAIMER***********************************



### Strange Quoting

Apparently, prefixing lines with `>` isn't universal either:
Expand All @@ -143,34 +134,26 @@ Apparently, prefixing lines with `>` isn't universal either:
Sent: Monday, March 14, 2011 6:16 PM
To: Rick


Unit Tests
----------
## Unit Tests

Setup the test suite using Composer:

$ composer install

Run it using PHPUnit:

$ ./vendor/bin/phpunit

$ ./vendor/bin/simple-phpunit

Contributing
------------
## Contributing

See CONTRIBUTING file.

## Credits

Credits
-------

* GitHub
* William Durand

- GitHub
- William Durand

License
-------
## License

EmailReplyParser is released under the MIT License. See the bundled LICENSE
file for details.
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
}
],
"require": {
"php": ">=7.3.0"
"php": ">=7.4.0"
},
"autoload": {
"psr-4": { "EmailReplyParser\\": "src/EmailReplyParser" }
Expand All @@ -25,6 +25,6 @@
}
},
"require-dev": {
"phpunit/phpunit": "^9.5"
"symfony/phpunit-bridge": "^5.0"
}
}
4 changes: 4 additions & 0 deletions src/EmailReplyParser/Parser/EmailParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@ class EmailParser
*/
public function parse($text)
{
if (!is_string($text)) {
return new Email();
}

$text = str_replace(array("\r\n", "\r"), "\n", $text);

foreach ($this->quoteHeadersRegex as $regex) {
Expand Down

0 comments on commit f25f8c6

Please sign in to comment.