Skip to content

Commit

Permalink
Merge pull request #17 from cedriclombardot/more-date-headers
Browse files Browse the repository at this point in the history
Match more date quotes headers
  • Loading branch information
willdurand committed Mar 20, 2014
2 parents 7436896 + 39387c8 commit 4842dd4
Show file tree
Hide file tree
Showing 3 changed files with 31 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 @@ -27,6 +27,8 @@ class EmailParser
*/
private $quoteHeadersRegex = array(
'/^(On\s(.+)wrote:)$/ms', // On DATE, NAME <EMAIL> wrote:
'/^(Le\s(.+)écrit :)$/ms', // Le DATE, NAME <EMAIL> a écrit :
'/^(20[0-9]{2}\-(0?[1-9]|1[012])\-(0?[1-2][0-9]|3[01]|[1-9])\s0?[0-9]:\d{2}\s(.+):)$/ms', // 20YY-MM-DD HH:II GMT+01:00 MAME <EMAIL>:
);

/**
Expand Down
24 changes: 24 additions & 0 deletions tests/EmailReplyParser/Tests/Parser/EmailParserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,31 @@ public function testCustomQuoteHeader2()
$this->parser->setQuoteHeadersRegex($regex);

$email = $this->parser->parse($this->getFixtures('email_customer_quote_header_2.txt'));
$fragments = $email->getFragments();
$this->assertCount(2, $fragments);

$this->assertEquals('Thank you very much.', $email->getVisibleText());
$this->assertTrue($fragments[1]->isHidden());
$this->assertTrue($fragments[1]->isQuoted());
}

/**
* @dataProvider getDateFormats
*/
public function testDateQuoteHeader($date)
{
$email = $this->parser->parse(str_replace('[DATE]', $date, $this->getFixtures('email_with_date_headers.txt')));

$this->assertEquals('Thank you very much.', $email->getVisibleText());
}

public function getDateFormats()
{
return array(
array('On Tue, 2011-03-01 at 18:02 +0530, Abhishek Kona wrote:'),
array('2014-03-20 8:48 GMT+01:00 Rémi Dolan <[email protected]>:'), // Gmail
array('Le 19 mars 2014 10:37, Cédric Lombardot <[email protected]> a écrit :'), // Gmail
array('Le 19/03/2014 11:34, Georges du chemin a écrit :'), // Thunderbird
);
}
}
5 changes: 5 additions & 0 deletions tests/Fixtures/email_with_date_headers.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Thank you very much.

[DATE]

This is my previous mail

3 comments on commit 4842dd4

@stof
Copy link
Contributor

@stof stof commented on 4842dd4 Jul 15, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@willdurand any chance to get a release with this change in it ?

@willdurand
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah sure!

@willdurand
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2.1.0 is released!

Please sign in to comment.