Skip to content

Commit

Permalink
Merge pull request #40 from hkdobrev/singature-no-empty-line
Browse files Browse the repository at this point in the history
Find signatures with no empty line above
  • Loading branch information
willdurand committed Sep 24, 2015
2 parents b9da621 + 9e1fea1 commit b32ab72
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/EmailReplyParser/Parser/EmailParser.php
Expand Up @@ -66,15 +66,15 @@ public function parse($text)
$line = ltrim($line);
}

if ($fragment && empty($line)) {
if ($fragment) {
$last = end($fragment->lines);

if ($this->isSignature($last)) {
$fragment->isSignature = true;
$this->addFragment($fragment);

$fragment = null;
} elseif ($this->isQuoteHeader($last)) {
} elseif (empty($line) && $this->isQuoteHeader($last)) {
$fragment->isQuoted = true;
$this->addFragment($fragment);

Expand Down
41 changes: 41 additions & 0 deletions tests/EmailReplyParser/Tests/Parser/EmailParserTest.php
Expand Up @@ -166,6 +166,25 @@ public function testReadsEmailWithCorrectSignature()
$this->assertRegExp('/^--\nrick/', (string) $fragments[1]);
}

public function testReadsEmailWithSignatureWithNoEmptyLineAbove()
{
$email = $this->parser->parse($this->getFixtures('sig_no_empty_line.txt'));
$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 testReadsEmailWithCorrectSignatureWithSpace()
{
// A common convention is to use "-- " as delimitor, but trailing spaces are often stripped by IDEs, so add them here
Expand All @@ -188,6 +207,28 @@ public function testReadsEmailWithCorrectSignatureWithSpace()
$this->assertRegExp('/^-- \nrick/', (string) $fragments[1]);
}

public function testReadsEmailWithCorrectSignatureWithNoEmptyLineWithSpace()
{
// 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('sig_no_empty_line.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()
{
$email = $this->parser->parse($this->getFixtures('email_one_is_not_on.txt'));
Expand Down
3 changes: 3 additions & 0 deletions tests/Fixtures/sig_no_empty_line.txt
@@ -0,0 +1,3 @@
this is an email with a signature with no empty line above.
--
rick

0 comments on commit b32ab72

Please sign in to comment.