public function parse_body() { // Parse the body and remove signatures, and reformat $parts = array(); $fragments = EmailReplyParser::read($this->body); foreach ($fragments as $fragment) { // We don't care about hidden parts (signatures, eg) if ($fragment->isHidden()) { continue; } elseif ($fragment->isQuoted()) { // Remove leading quote symbols $quoted = preg_replace('/^> */m', '', $fragment->getContent()); // Reparse to ensure that we strip signatures from here too $subfragments = EmailReplyParser::read($quoted); $subparts = array(); foreach ($subfragments as $subfrag) { if ($subfrag->isHidden()) { continue; } $subparts[] = $subfrag->getContent(); } $parts[] = '<blockquote>' . implode("\n", $subparts) . '</blockquote>'; } else { $parts[] = $fragment->getContent(); } } $content = implode("\n", $parts); return $content; }
public function testReadWithEmptyContent() { $reply = EmailReplyParser::read(''); $this->assertTrue(is_array($reply)); $this->assertEquals(1, count($reply)); $this->assertEmpty($reply[0]->__toString()); }
public function testEmailThreadPreservesNewLines() { $body = $this->getFixtures('email_thread.txt'); $fragments = EmailReplyParser::read($body)->getFragments(); $this->assertEquals(<<<EMAIL 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 >> > EMAIL , (string) $fragments[1]); }
public function testParseOutSentFromBlackBerry() { $body = file_get_contents(__DIR__ . '/../../Fixtures/email_blackberry.txt'); $this->assertEquals('Here is another email', EmailReplyParser::parseReply($body)); }