From 433d7377ce66bf88ebf5e14936fb79e9e6f70afd Mon Sep 17 00:00:00 2001
From: Peter Rotich <peter@osticket.com>
Date: Fri, 31 Jan 2014 16:15:57 +0000
Subject: [PATCH] Add ability to trip tags on-request Cleanup and make HTML
 safe by default Strip empty lines in TEXT content

---
 include/class.thread.php | 22 +++++++++++++++++-----
 1 file changed, 17 insertions(+), 5 deletions(-)

diff --git a/include/class.thread.php b/include/class.thread.php
index 5e5d0fd6c..c77a5f4b6 100644
--- a/include/class.thread.php
+++ b/include/class.thread.php
@@ -1131,7 +1131,7 @@ class Note extends ThreadEntry {
 
 class ThreadBody /* extends SplString */ {
 
-    private static $types = array('text', 'html');
+    static $types = array('text', 'html');
 
     var $body;
     var $type;
@@ -1140,7 +1140,7 @@ class ThreadBody /* extends SplString */ {
         $type = strtolower($type);
         if (!in_array($type, static::$types))
             throw new Exception($type.': Unsupported ThreadBody type');
-        $this->body = $text;
+        $this->body = (string) $body;
         $this->type = $type;
     }
 
@@ -1154,10 +1154,21 @@ class ThreadBody /* extends SplString */ {
             return new ThreadBody(sprintf('<pre>%s</pre>',
                 Format::htmlchars($this->body)), $type);
         case 'html:text':
-            return new ThreadBody(Format::html2text($this->body), $type);
+            return new ThreadBody(Format::html2text((string) $this), $type);
         }
     }
 
+    function stripQuotedReply($tag) {
+
+        //Strip quoted reply...on emailed  messages
+        if (!$tag || strpos($this->body, $tag) === false)
+            return;
+
+        if ((list($msg) = explode($tag, $this->body, 2)) && trim($msg))
+            $this->body = $msg;
+
+    }
+
     function __toString() {
         return $this->body;
     }
@@ -1165,12 +1176,13 @@ class ThreadBody /* extends SplString */ {
 
 class TextThreadBody extends ThreadBody {
     function __construct($body) {
-        parent::__construct($body, 'text');
+        parent::__construct(Format::stripEmptyLines($body), 'text');
     }
 }
 class HtmlThreadBody extends ThreadBody {
     function __construct($body) {
-        parent::__contruct($body, 'html');
+        $body = trim($body, " <>br/\t\n\r") ? Format::safe_html($body) : '';
+        parent::__construct($body, 'html');
     }
 }
 ?>
-- 
GitLab