From 50ee86edc8697b57a5df5a0d57d6f0090f0332e0 Mon Sep 17 00:00:00 2001 From: Dan Poltawski Date: Wed, 8 Jul 2015 12:24:46 +0100 Subject: [PATCH 1/3] MDL-50790 messageinbound: fixture for gmail --- lib/tests/fixtures/messageinbound/gmail.test | 148 +++++++++++++++++++ 1 file changed, 148 insertions(+) create mode 100644 lib/tests/fixtures/messageinbound/gmail.test diff --git a/lib/tests/fixtures/messageinbound/gmail.test b/lib/tests/fixtures/messageinbound/gmail.test new file mode 100644 index 00000000000..a3356a8a28f --- /dev/null +++ b/lib/tests/fixtures/messageinbound/gmail.test @@ -0,0 +1,148 @@ +----CLIENT---- +Gmail +----EXPECTEDPLAIN---- +This is a test response +----EXPECTEDHTML---- +This is a test response +----FULLSOURCE---- +Delivered-To: nxtmorg+aaaaaaaaaaiaaaaaaaaaagaaaaaaaaahbfpyofgjbkpkwpeh@gmail.com +Received: by 10.202.174.212 with SMTP id x203csp2773063oie; + Wed, 8 Jul 2015 03:45:49 -0700 (PDT) +X-Received: by 10.194.2.161 with SMTP id 1mr17755340wjv.143.1436352348859; + Wed, 08 Jul 2015 03:45:48 -0700 (PDT) +Return-Path: +Received: from mail-wg0-x22d.google.com (mail-wg0-x22d.google.com. [2a00:1450:400c:c00::22d]) + by mx.google.com with ESMTPS id hf10si1873428wib.2.2015.07.08.03.45.48 + for + (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); + Wed, 08 Jul 2015 03:45:48 -0700 (PDT) +Received-SPF: pass (google.com: domain of dan@moodle.com designates 2a00:1450:400c:c00::22d as permitted sender) client-ip=2a00:1450:400c:c00::22d; +Authentication-Results: mx.google.com; + spf=pass (google.com: domain of dan@moodle.com designates 2a00:1450:400c:c00::22d as permitted sender) smtp.mail=dan@moodle.com; + dkim=pass header.i=@moodle.com; + dmarc=pass (p=QUARANTINE dis=NONE) header.from=moodle.com +Received: by mail-wg0-x22d.google.com with SMTP id x7so186242655wgj.2 + for ; Wed, 08 Jul 2015 03:45:48 -0700 (PDT) +DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; + d=moodle.com; s=google; + h=mime-version:references:in-reply-to:from:date:message-id:subject:to + :content-type; + bh=jBsUlzIsNVo/9X0XRyhQfQKdI8jqA6v/XM5yi08CpW4=; + b=oyncjzbEuLnDDSZ4v7AbfMV8rlNClygbSabhxlhdgiUsZEORCGL83ZmjMencwF/MLm + a20Eh1Tho/5gGU3ZsacTgV8phNAp0yBl59mzZUVF4wabIQBMbQQlyBJsqn7RbIRky+DA + FpneKKLreS29B0BMr+95VGSJ/XRohQZSjw7nY= +X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; + d=1e100.net; s=20130820; + h=x-gm-message-state:mime-version:references:in-reply-to:from:date + :message-id:subject:to:content-type; + bh=jBsUlzIsNVo/9X0XRyhQfQKdI8jqA6v/XM5yi08CpW4=; + b=GXbTXInSb7VhTCe7uIdixAgUNh0tusJkfgc606jk8ZD5xy89IjLcCDaKBY4wPT/xgH + KqELVFnwUsAJRBv0ZiflgzvUQ7SC2znVbkfQK8idswgc7p3iaWxXLT/m3HwVrnn0Aord + uRlEW1eBraBdOD/as24aCbzBGFPjFDkynfK0dIyCVmXN05p8QE09bYqkOVSh3lDxeZfX + AIDjlfC8DmvKZQN68Con86SyzQ6epzs2A3yrQ3oMYxG5yAHFqoXbmQPZLyjWMqx0uJ4L + lRnq7wSSLsSA8a9q8RBO8JltmZHa1AShqMkHghh/RISISXyriFezN71F7lt303fDJLvw + 5Z9g== +X-Gm-Message-State: ALoCoQk4VlKEKkaqy6MLYzq2ZN82v3a64TLQZJo0b26DUbmmS8UDpT8tstQh2kodndsV2GgB/bpT +X-Received: by 10.180.102.74 with SMTP id fm10mr112402988wib.25.1436352348167; + Wed, 08 Jul 2015 03:45:48 -0700 (PDT) +MIME-Version: 1.0 +References: <665442d32a4d85d3ac239d88a146ffdf9becf154c78bf8394bf3bfdbb4c312f6@dan.moodle.local> + +In-Reply-To: +From: Dan Poltawski +Date: Wed, 08 Jul 2015 10:45:38 +0000 +Message-ID: +Subject: Re: Using Moodle Test: Re: A test +To: nxtmorg+AAAAAAAAAAIAAAAAAAAAAgAAAAAAAAAhBfpyofgjbKpKWPeH@gmail.com +Content-Type: multipart/alternative; boundary=f46d0444812b7c332b051a5ad7d1 + +--f46d0444812b7c332b051a5ad7d1 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: quoted-printable + +This is a test response + +On Wed, Jul 8, 2015 at 11:45 AM Admin User wrote: + +> Using Moodle Test = + =C2=BB +> Forums =C2=BB = +Discussion +> forum =C2=BB A t= +est +> +> [image: Picture of Admin User] +> +> Re: A test +> by Admin User +> - Wednesday, 8 July 2015, 11:45 am +> +> +> test 123 +> Show parent +> = +| +> Reply +> See this post in context +> +> ------------------------------ +> Unsubscribe from this forum +> Unsubscrib= +e +> from this discussion +> Uns= +ubscribe +> from all forums +> Change your +> forum digest preferences +> +> +> You can reply to this via email. +> + +--f46d0444812b7c332b051a5ad7d1 +Content-Type: text/html; charset=UTF-8 +Content-Transfer-Encoding: quoted-printable + +
This is a test response

On Wed, Jul 8, 2015 at 11:45 AM Admin User <nxtmorg@gmail.com> wrote:
+
+ + + +

You can reply to this via email.

+ + + +--f46d0444812b7c332b051a5ad7d1-- From 8503ae75585594f1879bfae92f4afb35d04db6d4 Mon Sep 17 00:00:00 2001 From: Cameron Ball Date: Mon, 21 Sep 2015 13:01:02 +0800 Subject: [PATCH 2/3] MDL-50790 inbound: Stop incorrect amount of lines getting removed. 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 | 32 ++----------------------- lib/tests/messageinbound_test.php | 4 ---- 2 files changed, 2 insertions(+), 34 deletions(-) diff --git a/lib/classes/message/inbound/handler.php b/lib/classes/message/inbound/handler.php index fcf9c37ff79..9da1f0b19a3 100644 --- a/lib/classes/message/inbound/handler.php +++ b/lib/classes/message/inbound/handler.php @@ -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; - } } diff --git a/lib/tests/messageinbound_test.php b/lib/tests/messageinbound_test.php index 8baf461623c..0d4b50f6d5f 100644 --- a/lib/tests/messageinbound_test.php +++ b/lib/tests/messageinbound_test.php @@ -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() {} From b17f884ee0a2c321484b46305be4af389f52256e Mon Sep 17 00:00:00 2001 From: Cameron Ball Date: Mon, 21 Sep 2015 13:08:18 +0800 Subject: [PATCH 3/3] MDL-50790 tests: Fix outlook fixture. --- lib/tests/fixtures/messageinbound/outlook.test | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/tests/fixtures/messageinbound/outlook.test b/lib/tests/fixtures/messageinbound/outlook.test index ea4cd1d675b..5a488048f73 100644 --- a/lib/tests/fixtures/messageinbound/outlook.test +++ b/lib/tests/fixtures/messageinbound/outlook.test @@ -18,6 +18,7 @@ Sending mail via clent and it seems to go all good... Havent tried this before and it is awesome.... Cheers + Rajesh ----FULLSOURCE---- Delivered-To: moodlehqtest+aaaaaaaaaaiaaaaaaaaabqaaaaaaaaazd63zvl6kcy04ioh+@example.com
3D"Picture
Re: A test
<= +div>by Admin User - Wednesday, 8 July 2015, 11:45 = +am
=C2=A0

test 123

Show parent | Reply