From 8fc79035b6b72676a8b215e975dfe2dc9e3d922c Mon Sep 17 00:00:00 2001 From: epriestley Date: Mon, 16 May 2011 15:42:20 -0700 Subject: [PATCH] Provide an "algorithm" for stripping quoted text from email replies Summary: There's an undoubtedly-far-more-refined version of this in xmail if someone wants to crib it for me. Otherwise we can anneal this as counterexamples arise. This seems to be what mail.app and gmail do. Test Plan: Used mail receiver console to "send" some mail and verified it was correctly truncated. Reviewed By: jungejason Reviewers: aran, tuomaspelkonen, jungejason CC: aran, jungejason Differential Revision: 290 --- .../receivedmail/PhabricatorMetaMTAReceivedMail.php | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/applications/metamta/storage/receivedmail/PhabricatorMetaMTAReceivedMail.php b/src/applications/metamta/storage/receivedmail/PhabricatorMetaMTAReceivedMail.php index 1f61c56615..d43eefb818 100644 --- a/src/applications/metamta/storage/receivedmail/PhabricatorMetaMTAReceivedMail.php +++ b/src/applications/metamta/storage/receivedmail/PhabricatorMetaMTAReceivedMail.php @@ -96,9 +96,17 @@ class PhabricatorMetaMTAReceivedMail extends PhabricatorMetaMTADAO { public function getCleanTextBody() { $body = idx($this->bodies, 'text'); - // TODO: Detect quoted content and exclude it. + // TODO: Refine this "algorithm". - return $body; + $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)); } public static function loadReceiverObject($receiver_name) {