1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-12-30 01:10:58 +01:00

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
This commit is contained in:
epriestley 2013-12-06 15:47:37 -08:00
parent 3ad4be4d93
commit f69793184e
2 changed files with 37 additions and 4 deletions

View file

@ -50,10 +50,29 @@ final class PhabricatorMetaMTAEmailBodyParser {
} }
private function stripQuotedText($body) { private function stripQuotedText($body) {
$body = preg_replace(
'/^\s*>?\s*On\b.*\bwrote:.*?/msU', // Look for "On <date>, <user> wrote:". This may be split across multiple
'', // lines. We need to be careful not to remove all of a message like this:
$body); //
// On which day do you want to meet?
//
// On <date>, <user> wrote:
// > Let's set up a meeting.
$start = null;
$lines = phutil_split_lines($body);
foreach ($lines as $key => $line) {
if (preg_match('/^\s*>?\s*On\b/', $line)) {
$start = $key;
}
if ($start !== null) {
if (preg_match('/\bwrote:/', $line)) {
$lines = array_slice($lines, 0, $start);
$body = implode('', $lines);
break;
}
}
}
// Outlook english // Outlook english
$body = preg_replace( $body = preg_replace(

View file

@ -31,6 +31,20 @@ final class PhabricatorMetaMTAEmailBodyParserTestCase
} }
} }
public function testFalsePositiveForOnWrote() {
$body = <<<EOEMAIL
On which horse shall you ride?
On Sep 23, alincoln wrote:
> Hey bro do you want to go ride horses tomorrow?
EOEMAIL;
$parser = new PhabricatorMetaMTAEmailBodyParser();
$stripped = $parser->stripTextBody($body);
$this->assertEqual("On which horse shall you ride?", $stripped);
}
private function getEmailBodiesWithFullCommands() { private function getEmailBodiesWithFullCommands() {
$bodies = $this->getEmailBodies(); $bodies = $this->getEmailBodies();
$with_commands = array(); $with_commands = array();