Skip to content

Commit

Permalink
add testcase for custom regex.
Browse files Browse the repository at this point in the history
refs: #42
  • Loading branch information
glensc committed Nov 28, 2017
1 parent fc1039c commit 7c64d7d
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/EmailReplyParser/Parser/EmailParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ public function setQuoteHeadersRegex(array $quoteHeadersRegex)

/**
* @return string
* @since 2.7.0
*/
public function getSignatureRegex()
{
Expand All @@ -155,6 +156,7 @@ public function getSignatureRegex()
* @param string $signatureRegex
*
* @return EmailParser
* @since 2.7.0
*/
public function setSignatureRegex($signatureRegex)
{
Expand Down
18 changes: 18 additions & 0 deletions tests/EmailReplyParser/Tests/Parser/EmailParserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,24 @@ public function testEmailWithFairAmountOfContent()
$this->assertRegexp('/^On Thursday/', (string) $fragments[0]);
}

/**
* override regexp, not to match too greedy signature.
*
* See: https://github.com/willdurand/EmailReplyParser/pull/42
*/
public function testCustomSignatureRegex()
{
$signatureRegex = '/(?:^\s*--|^\s*__|^-- $)|(?:^Sent from my (?:\s*\w+){1,3})$/s';
$this->parser->setSignatureRegex($signatureRegex);
$email = $this->parser->parse($this->getFixtures('email_ls-l.txt'));
$fragments = $email->getFragments();

// this should match two blocks, body and a signature
$this->assertCount(2, $fragments);
$this->assertFalse($fragments[0]->isSignature());
$this->assertTrue($fragments[1]->isSignature());
}

/**
* @dataProvider getDateFormats
*/
Expand Down

0 comments on commit 7c64d7d

Please sign in to comment.