From e87a07a0b5bed5f7fa0cebf2465a9bd7d8e11bd9 Mon Sep 17 00:00:00 2001 From: Jonathan Cox Date: Fri, 8 May 2015 14:11:12 -0400 Subject: [PATCH] Make quote header regexes lazy to avoid collapsing multiple headers into one. (https://github.com/willdurand/EmailReplyParser/issues/27) --- src/EmailReplyParser/Parser/EmailParser.php | 10 +++---- .../Tests/EmailReplyParserTest.php | 29 +++++++++++++++++++ tests/Fixtures/email_thread.txt | 21 ++++++++++++++ 3 files changed, 55 insertions(+), 5 deletions(-) create mode 100644 tests/Fixtures/email_thread.txt diff --git a/src/EmailReplyParser/Parser/EmailParser.php b/src/EmailReplyParser/Parser/EmailParser.php index 4536fc6..9dce43a 100644 --- a/src/EmailReplyParser/Parser/EmailParser.php +++ b/src/EmailReplyParser/Parser/EmailParser.php @@ -26,11 +26,11 @@ class EmailParser * @var string[] */ private $quoteHeadersRegex = array( - '/^(On\s.+wrote:)$/ms', // On DATE, NAME wrote: - '/^(Le\s.+écrit :)$/ms', // Le DATE, NAME a écrit : - '/^(El\s.+escribió:)$/ms', // El DATE, NAME escribió: - '/^(W dniu\s.+(pisze|napisał):)$/ms', // W dniu DATE, NAME pisze|napisał: - '/^(20[0-9]{2}\-(?:0?[1-9]|1[012])\-(?:0?[0-9]|[1-2][0-9]|3[01]|[1-9])\s[0-2]?[0-9]:\d{2}\s.+:)$/ms', // 20YY-MM-DD HH:II GMT+01:00 NAME : + '/^(On\s.+?wrote:)$/ms', // On DATE, NAME wrote: + '/^(Le\s.+?écrit :)$/ms', // Le DATE, NAME a écrit : + '/^(El\s.+?escribió:)$/ms', // El DATE, NAME escribió: + '/^(W dniu\s.+?(pisze|napisał):)$/ms', // W dniu DATE, NAME pisze|napisał: + '/^(20[0-9]{2}\-(?:0?[1-9]|1[012])\-(?:0?[0-9]|[1-2][0-9]|3[01]|[1-9])\s[0-2]?[0-9]:\d{2}\s.+?:)$/ms', // 20YY-MM-DD HH:II GMT+01:00 NAME : ); /** diff --git a/tests/EmailReplyParser/Tests/EmailReplyParserTest.php b/tests/EmailReplyParser/Tests/EmailReplyParserTest.php index 36d16ea..0ee70b6 100644 --- a/tests/EmailReplyParser/Tests/EmailReplyParserTest.php +++ b/tests/EmailReplyParser/Tests/EmailReplyParserTest.php @@ -112,4 +112,33 @@ public function testUnquotedReply() $this->assertEquals('This is my reply.', EmailReplyParser::parseReply($body)); } + + public function testEmailThreadPreservesNewLines() + { + $body = $this->getFixtures('email_thread.txt'); + + $fragments = EmailReplyParser::read($body) + ->getFragments(); + + $this->assertEquals(<< wrote: + +> Ok. Thanks. +> +> On Nov 21, 2014, at 9:26, Jim Beam wrote: +> +>>> On Nov 20, 2014, at 11:03 AM, John Doe wrote: +>>> +>>> if you take a look at a short video from attachment, why full-typed filename does not stay in CMD+T pane? +>>> When I type last character, it is not shown anymore. +>> +>> We think we’ve tracked down the cause of this issue, write back if you see the issue after the next update. (Which will be out shortly.) +>> +>> -- +>> Jim Beam – Acme Corp +>> +> +EMAIL + , (string) $fragments[1]); + } } diff --git a/tests/Fixtures/email_thread.txt b/tests/Fixtures/email_thread.txt new file mode 100644 index 0000000..7e5e59d --- /dev/null +++ b/tests/Fixtures/email_thread.txt @@ -0,0 +1,21 @@ +This is new email reply in thread from bellow. + +On Nov 21, 2014, +at 10:18, +John Doe wrote: + +> Ok. Thanks. +> +> On Nov 21, 2014, at 9:26, Jim Beam wrote: +> +>>> On Nov 20, 2014, at 11:03 AM, John Doe wrote: +>>> +>>> if you take a look at a short video from attachment, why full-typed filename does not stay in CMD+T pane? +>>> When I type last character, it is not shown anymore. +>> +>> We think we’ve tracked down the cause of this issue, write back if you see the issue after the next update. (Which will be out shortly.) +>> +>> -- +>> Jim Beam – Acme Corp +>> +> \ No newline at end of file