Permalink
Browse files

Refactored tests, improved multiline header detection

  • Loading branch information...
1 parent b588fbd commit eac55069baf6f10f4ccb00ce9effd3524cdc913b @willdurand committed May 13, 2012
View
@@ -1 +1,2 @@
vendor/
+composer.lock
View
@@ -5,8 +5,7 @@ php:
- 5.4
before_script:
- - ./bin/install_vendors.sh
+ - curl -s http://getcomposer.org/installer | php
+ - php composer.phar --dev install
-notifications:
- email:
- - william.durand1@gmail.com
+script: phpunit --coverage-text
View
@@ -3,14 +3,16 @@ EmailReplyParser
[![Build Status](https://secure.travis-ci.org/willdurand/EmailReplyParser.png)](http://travis-ci.org/willdurand/EmailReplyParser)
-**EmailReplyParser** is a port of the GitHub's [EmailReplyParser](http://github.com/github/email_reply_parser) library written in Ruby.
-This is a small PHP 5.3 library to parse plain text email content.
+**EmailReplyParser** is a port of the GitHub's [EmailReplyParser](http://github.com/github/email_reply_parser)
+library written in Ruby. This is a small PHP 5.3 library to parse plain text
+email content.
Installation
------------
-If you don't use a _ClassLoader_ in your application, just require the provided autoloader:
+If you don't use a _ClassLoader_ in your application, just require the provided
+autoloader:
``` php
<?php
@@ -42,9 +44,11 @@ Alternatively, you can use the static way:
$reply = \EmailReplyParser\EmailReplyParser::read($emailContent);
```
-`$reply` is an array of `Fragment` objects. To get the content of each fragment, just call the `getContent()` method.
+`$reply` is an array of `Fragment` objects. To get the content of each fragment,
+just call the `getContent()` method.
-A `Fragment` can be a signature, a quoted text, or an hidden text. Here is the API:
+A `Fragment` can be a signature, a quoted text, or an hidden text.
+Here is the API:
``` php
<?php
@@ -96,7 +100,7 @@ signatures:
Hello
- --
+ --
Rick
Not everyone follows this convention:
@@ -131,13 +135,13 @@ Apparently, prefixing lines with `>` isn't universal either:
Unit Tests
----------
-To run unit tests, you'll need a set of dependencies you can install by running the `install_vendors.sh` script:
+To run the test suite, run Composer first to setup the autoloader:
```
-./bin/install_vendors.sh
+php composer.phar install
```
-Once installed, just launch the following command:
+Then run the following command:
```
phpunit
@@ -154,4 +158,5 @@ Credits
License
-------
-EmailReplyParser is released under the MIT License. See the bundled LICENSE file for details.
+EmailReplyParser is released under the MIT License.
+See the bundled LICENSE file for details.
View
@@ -1,12 +0,0 @@
-<?php
-
-if (!class_exists('\Symfony\Component\ClassLoader\UniversalClassLoader')) {
- require_once __DIR__ . '/vendor/Symfony/Component/ClassLoader/UniversalClassLoader.php';
-}
-
-$loader = new \Symfony\Component\ClassLoader\UniversalClassLoader();
-$loader->registerNamespaces(array(
- 'EmailReplyParser' => __DIR__ . '/src',
- 'EmailReplyParser\Tests' => __DIR__ . '/tests',
-));
-$loader->register();
@@ -1,14 +0,0 @@
-function installOrUpdate
-{
- echo "Installing/Updating $1"
-
- if [ ! -d "$1" ] ; then
- git clone $2 $1
- fi
-
- cd $1
- git fetch -q origin
- git reset --hard $3
-}
-
-installOrUpdate "vendor/Symfony/Component/ClassLoader" "git://github.com/symfony/ClassLoader.git" "origin/master"
@@ -28,13 +28,17 @@ class Email
*/
public function read($text)
{
- $array = explode("\n", strrev($text));
+ if (preg_match('/^(On(.+)wrote:)$/ms', $text, $matches)) {
+ $text = str_replace($matches[1], str_replace("\n", ' ', $matches[1]), $text);
+ }
+
+ $lines = explode("\n", strrev($text));
$fragment = null;
$isQuoted = false;
$foundVisible = false;
- foreach ($array as $line) {
+ foreach ($lines as $line) {
$line = preg_replace("/\n$/", '', ltrim($line));
// isQuoted ?
@@ -106,4 +106,13 @@ public function testComplexBodyWithOnlyOneFragment()
$this->assertEquals(1, count($reply));
}
+
+ public function testDealsWithMultilineReplyHeaders()
+ {
+ $reply = $this->email->read(file_get_contents(__DIR__.'/../../Fixtures/email_6.txt'));
+
+ $this->assertRegExp('/^I get/', (string)$reply[0]);
+ $this->assertRegExp('/^On/', (string)$reply[1]);
+ $this->assertRegExp('/Was this/', (string)$reply[1]);
+ }
}
@@ -0,0 +1,15 @@
+I get proper rendering as well.
+
+Sent from a magnificent torch of pixels
+
+On Dec 16, 2011, at 12:47 PM, Corey Donohoe
+<reply@reply.github.com>
+wrote:
+
+> Was this caching related or fixed already? I get proper rendering here.
+>
+> ![](https://img.skitch.com/20111216-m9munqjsy112yqap5cjee5wr6c.jpg)
+>
+> ---
+> Reply to this email directly or view it on GitHub:
+> https://github.com/github/github/issues/2278#issuecomment-3182418
View
@@ -1,7 +1,4 @@
<?php
-if (file_exists($file = __DIR__.'/../autoload.php')) {
- require_once $file;
-} elseif (file_exists($file = __DIR__.'/../autoload.php.dist')) {
- require_once $file;
-}
+$loader = require_once __DIR__ . '/../vendor/autoload.php';
+$loader->add('EmailReplyParser\Tests', __DIR__);

0 comments on commit eac5506

Please sign in to comment.