MDL-50790 inbound: Stop incorrect amount of lines getting removed.
authorCameron Ball <cameron@moodle.com>
Mon, 21 Sep 2015 05:01:02 +0000 (13:01 +0800)
committerCameron Ball <cameron@moodle.com>
Mon, 21 Sep 2015 06:25:21 +0000 (14:25 +0800)
Too many lines were being removed for GMail senders. The function was
also removed because it is no longer used, and guessing the client
and cutting accordingly is a poor approach and will probably lead
to issues similar to this one.

lib/classes/message/inbound/handler.php
lib/tests/messageinbound_test.php

index fcf9c37..9da1f0b 100644 (file)
@@ -245,7 +245,6 @@ abstract class handler {
      * @return array message and message format to use.
      */
     protected static function remove_quoted_text($messagedata) {
-        $linecount = self::get_linecount_to_remove($messagedata);
         if (!empty($messagedata->plain)) {
             $text = $messagedata->plain;
         } else {
@@ -258,8 +257,6 @@ abstract class handler {
             return array($text, $messageformat);
         }
 
-        // Remove extra line. "Xyz wrote on...".
-        $count = 0;
         $i = 0;
         $flag = false;
         foreach ($splitted as $i => $element) {
@@ -271,9 +268,6 @@ abstract class handler {
                     $element = $splitted[$j];
                     if (!empty($element)) {
                         unset($splitted[$j]);
-                        $count++;
-                    }
-                    if ($count == $linecount) {
                         break;
                     }
                 }
@@ -282,10 +276,8 @@ abstract class handler {
         }
         if ($flag) {
             // Quoted text was found.
-            $k = $i - $linecount; // Where to start the chopping process.
-
-            // Remove quoted text.
-            $splitted = array_slice($splitted, 0, $k);
+            // Retrieve everything from the start until the line before the quoted text.
+            $splitted = array_slice($splitted, 0, $i-1);
 
             // Strip out empty lines towards the end, since a lot of clients add a huge chunk of empty lines.
             $reverse = array_reverse($splitted);
@@ -311,24 +303,4 @@ abstract class handler {
         }
         return array($message, $messageformat);
     }
-
-    /**
-     * Try to guess how many lines to remove from the email to delete "xyz wrote on" text. Hard coded numbers for various email
-     * clients.
-     * Gmail uses two
-     * Evolution uses one
-     * Thunderbird uses one
-     *
-     * @param \stdClass $messagedata The Inbound Message record
-     *
-     * @return int number of lines to chop off before the start of quoted text.
-     */
-    protected static function get_linecount_to_remove($messagedata) {
-        $linecount = 1;
-        if (!empty($messagedata->html) && stripos($messagedata->html, 'gmail_quote') !== false) {
-            // Gmail uses two lines.
-            $linecount = 2;
-        }
-        return $linecount;
-    }
 }
index 8baf461..0d4b50f 100644 (file)
@@ -163,10 +163,6 @@ class test_handler extends \core\message\inbound\handler {
         return parent::remove_quoted_text($messagedata);
     }
 
-    public static function get_linecount_to_remove($messagedata) {
-        return parent::get_linecount_to_remove($messagedata);
-    }
-
     public function get_name() {}
 
     public function get_description() {}