diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index 81a9d42b03..0aca76d524 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -349,6 +349,8 @@ phutil_register_library_map(array( 'PhabricatorMetaMTAController' => 'applications/metamta/controller/base', 'PhabricatorMetaMTADAO' => 'applications/metamta/storage/base', 'PhabricatorMetaMTADaemon' => 'applications/metamta/daemon/mta', + 'PhabricatorMetaMTAEmailBodyParser' => 'applications/metamta/parser', + 'PhabricatorMetaMTAEmailBodyParserTestCase' => 'applications/metamta/parser/__tests__', 'PhabricatorMetaMTAListController' => 'applications/metamta/controller/list', 'PhabricatorMetaMTAMail' => 'applications/metamta/storage/mail', 'PhabricatorMetaMTAMailTestCase' => 'applications/metamta/storage/mail/__tests__', @@ -790,6 +792,7 @@ phutil_register_library_map(array( 'PhabricatorMetaMTAController' => 'PhabricatorController', 'PhabricatorMetaMTADAO' => 'PhabricatorLiskDAO', 'PhabricatorMetaMTADaemon' => 'PhabricatorDaemon', + 'PhabricatorMetaMTAEmailBodyParserTestCase' => 'PhabricatorTestCase', 'PhabricatorMetaMTAListController' => 'PhabricatorMetaMTAController', 'PhabricatorMetaMTAMail' => 'PhabricatorMetaMTADAO', 'PhabricatorMetaMTAMailTestCase' => 'PhabricatorTestCase', diff --git a/src/applications/metamta/parser/PhabricatorMetaMTAEmailBodyParser.php b/src/applications/metamta/parser/PhabricatorMetaMTAEmailBodyParser.php new file mode 100644 index 0000000000..e101429070 --- /dev/null +++ b/src/applications/metamta/parser/PhabricatorMetaMTAEmailBodyParser.php @@ -0,0 +1,36 @@ +corpus = $corpus; + } + + public function stripQuotedText() { + $body = $this->corpus; + + $body = preg_replace( + '/^\s*On\b.*\bwrote:.*?/msU', + '', + $body); + + return rtrim($body); + } + +} diff --git a/src/applications/metamta/parser/__init__.php b/src/applications/metamta/parser/__init__.php new file mode 100644 index 0000000000..a088211fd8 --- /dev/null +++ b/src/applications/metamta/parser/__init__.php @@ -0,0 +1,10 @@ +getEmailBodies(); + foreach ($bodies as $body) { + $parser = new PhabricatorMetaMTAEmailBodyParser($body); + $stripped = $parser->stripQuotedText(); + $this->assertEqual("OKAY", $stripped); + } + } + + private function getEmailBodies() { + return array( +<< ... + +EOEMAIL +, +<< wrote: + +> ... + +EOEMAIL +, +<< wrote: + +> ... + +EOEMAIL + ); + } + +} diff --git a/src/applications/metamta/parser/__tests__/__init__.php b/src/applications/metamta/parser/__tests__/__init__.php new file mode 100644 index 0000000000..e2cbf69d4f --- /dev/null +++ b/src/applications/metamta/parser/__tests__/__init__.php @@ -0,0 +1,13 @@ +bodies, 'text'); - // TODO: Refine this "algorithm". - - $lines = explode("\n", trim($body)); - for ($ii = 0; $ii < count($lines); $ii++) { - if (preg_match('/^\s*On\b.*\bwrote:\s*$/', $lines[$ii])) { - $lines = array_slice($lines, 0, $ii); - break; - } - } - - return trim(implode("\n", $lines)); + $parser = new PhabricatorMetaMTAEmailBodyParser($body); + return $parser->stripQuotedText(); } public static function loadReceiverObject($receiver_name) { diff --git a/src/applications/metamta/storage/receivedmail/__init__.php b/src/applications/metamta/storage/receivedmail/__init__.php index 72c98b9068..afd38aa144 100644 --- a/src/applications/metamta/storage/receivedmail/__init__.php +++ b/src/applications/metamta/storage/receivedmail/__init__.php @@ -8,6 +8,7 @@ phutil_require_module('phabricator', 'applications/differential/mail/base'); phutil_require_module('phabricator', 'applications/maniphest/editor/transaction'); +phutil_require_module('phabricator', 'applications/metamta/parser'); phutil_require_module('phabricator', 'applications/metamta/storage/base'); phutil_require_module('phabricator', 'applications/people/storage/user'); phutil_require_module('phabricator', 'infrastructure/env');