From f25f8c6c3cb876112e3857eb3da15e38e44e4725 Mon Sep 17 00:00:00 2001 From: William Durand Date: Sun, 30 Jan 2022 21:56:36 +0100 Subject: [PATCH] ci: switch to github actions (#88) --- .github/workflows/ci.yaml | 34 +++++++++++ .gitignore | 1 + .travis.yml | 11 ---- README.md | 65 ++++++++------------- composer.json | 4 +- src/EmailReplyParser/Parser/EmailParser.php | 4 ++ 6 files changed, 65 insertions(+), 54 deletions(-) create mode 100644 .github/workflows/ci.yaml delete mode 100644 .travis.yml diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml new file mode 100644 index 0000000..d3fee8c --- /dev/null +++ b/.github/workflows/ci.yaml @@ -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" diff --git a/.gitignore b/.gitignore index d1502b0..3d7e132 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ vendor/ composer.lock +.phpunit.result.cache diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index c3c95c5..0000000 --- a/.travis.yml +++ /dev/null @@ -1,11 +0,0 @@ -language: php - -php: - - 7.3 - - 7.4 - - 8.0 - -before_script: - - composer install - -script: XDEBUG_MODE=coverage ./vendor/bin/phpunit --coverage-text diff --git a/README.md b/README.md index 977ca97..984e2a0 100644 --- a/README.md +++ b/README.md @@ -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 @@ -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 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 getFragments()); @@ -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 @@ -84,7 +77,7 @@ 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 , wrote: @@ -92,15 +85,15 @@ multiple lines. GMail breaks up any lines over 80 characters for you. 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 "reply@reply.github.com" lines... @@ -127,8 +120,6 @@ Not everyone follows this convention: * Note: blah blah blah * **********************DISCLAIMER*********************************** - - ### Strange Quoting Apparently, prefixing lines with `>` isn't universal either: @@ -143,9 +134,7 @@ 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: @@ -153,24 +142,18 @@ Setup the test suite using Composer: 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. diff --git a/composer.json b/composer.json index dc3d1ca..9d193e3 100644 --- a/composer.json +++ b/composer.json @@ -11,7 +11,7 @@ } ], "require": { - "php": ">=7.3.0" + "php": ">=7.4.0" }, "autoload": { "psr-4": { "EmailReplyParser\\": "src/EmailReplyParser" } @@ -25,6 +25,6 @@ } }, "require-dev": { - "phpunit/phpunit": "^9.5" + "symfony/phpunit-bridge": "^5.0" } } diff --git a/src/EmailReplyParser/Parser/EmailParser.php b/src/EmailReplyParser/Parser/EmailParser.php index 61233f8..b1c2d5f 100644 --- a/src/EmailReplyParser/Parser/EmailParser.php +++ b/src/EmailReplyParser/Parser/EmailParser.php @@ -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) {