Skip to content

Commit

Permalink
Merge pull request #25 from stof/fix_signature_detection
Browse files Browse the repository at this point in the history
Fixed the regex detecting signatures
  • Loading branch information
willdurand committed Oct 21, 2014
2 parents 2b5cf81 + 423cb80 commit 2b2e431
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/EmailReplyParser/Parser/EmailParser.php
Expand Up @@ -18,7 +18,7 @@
*/
class EmailParser
{
const SIG_REGEX = '/(?:^--|^__|\w-$)|(?:^(?:\w+\s*){1,3} ym morf tneS$)/s';
const SIG_REGEX = '/(?:--\s*$|__\s*$|\w-$)|(?:^(?:\w+\s*){1,3} ym morf tneS$)/s';

const QUOTE_REGEX = '/>+$/s';

Expand Down
27 changes: 26 additions & 1 deletion tests/EmailReplyParser/Tests/Parser/EmailParserTest.php
Expand Up @@ -7,6 +7,9 @@

class EmailParserTest extends TestCase
{
/**
* @var EmailParser
*/
private $parser;

protected function setUp()
Expand Down Expand Up @@ -160,7 +163,29 @@ public function testReadsEmailWithCorrectSignature()
$this->assertFalse($fragments[0]->isHidden());
$this->assertTrue($fragments[1]->isHidden());

$this->assertRegExp("/^--\nrick/", (string) $fragments[1]);
$this->assertRegExp('/^--\nrick/', (string) $fragments[1]);
}

public function testReadsEmailWithCorrectSignatureWithSpace()
{
// A common convention is to use "-- " as delimitor, but trailing spaces are often stripped by IDEs, so add them here
$content = str_replace('--', '-- ', $this->getFixtures('correct_sig.txt'));

$email = $this->parser->parse($content);
$fragments = $email->getFragments();

$this->assertCount(2, $fragments);

$this->assertFalse($fragments[0]->isQuoted());
$this->assertFalse($fragments[1]->isQuoted());

$this->assertFalse($fragments[0]->isSignature());
$this->assertTrue($fragments[1]->isSignature());

$this->assertFalse($fragments[0]->isHidden());
$this->assertTrue($fragments[1]->isHidden());

$this->assertRegExp('/^-- \nrick/', (string) $fragments[1]);
}

public function testOneIsNotOn()
Expand Down

0 comments on commit 2b2e431

Please sign in to comment.