@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Fix over-matching of quoted text for message bodies beginning with "On..."

Summary:
A user sent a message to Phabricator which looked like:

On blah blah blah ?

On <date>, <user> wrote:
> blah blah blah

The current algorithm is too aggressive and thinks lines 1-3 are //all// the "On ... wrote:" string. Instead, patch only the most recent "On".

Test Plan: Added a failing test and made it pass.

Reviewers: btrahan, zeeg

Reviewed By: zeeg

CC: aran

Differential Revision: https://secure.phabricator.com/D7732

+37 -4
+23 -4
src/applications/metamta/parser/PhabricatorMetaMTAEmailBodyParser.php
··· 50 50 } 51 51 52 52 private function stripQuotedText($body) { 53 - $body = preg_replace( 54 - '/^\s*>?\s*On\b.*\bwrote:.*?/msU', 55 - '', 56 - $body); 53 + 54 + // Look for "On <date>, <user> wrote:". This may be split across multiple 55 + // lines. We need to be careful not to remove all of a message like this: 56 + // 57 + // On which day do you want to meet? 58 + // 59 + // On <date>, <user> wrote: 60 + // > Let's set up a meeting. 61 + 62 + $start = null; 63 + $lines = phutil_split_lines($body); 64 + foreach ($lines as $key => $line) { 65 + if (preg_match('/^\s*>?\s*On\b/', $line)) { 66 + $start = $key; 67 + } 68 + if ($start !== null) { 69 + if (preg_match('/\bwrote:/', $line)) { 70 + $lines = array_slice($lines, 0, $start); 71 + $body = implode('', $lines); 72 + break; 73 + } 74 + } 75 + } 57 76 58 77 // Outlook english 59 78 $body = preg_replace(
+14
src/applications/metamta/parser/__tests__/PhabricatorMetaMTAEmailBodyParserTestCase.php
··· 31 31 } 32 32 } 33 33 34 + public function testFalsePositiveForOnWrote() { 35 + $body = <<<EOEMAIL 36 + On which horse shall you ride? 37 + 38 + On Sep 23, alincoln wrote: 39 + 40 + > Hey bro do you want to go ride horses tomorrow? 41 + EOEMAIL; 42 + 43 + $parser = new PhabricatorMetaMTAEmailBodyParser(); 44 + $stripped = $parser->stripTextBody($body); 45 + $this->assertEqual("On which horse shall you ride?", $stripped); 46 + } 47 + 34 48 private function getEmailBodiesWithFullCommands() { 35 49 $bodies = $this->getEmailBodies(); 36 50 $with_commands = array();