From 9ce63f385a2270a44f0c5f92d23807e95f826b2a Mon Sep 17 00:00:00 2001
From: Jared Hancock <jared@osticket.com>
Date: Thu, 22 May 2014 14:26:55 -0500
Subject: [PATCH] Truncate thread messages that cannot be sent to db

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

diff --git a/include/class.thread.php b/include/class.thread.php
index decd0db5f..c69eb2854 100644
--- a/include/class.thread.php
+++ b/include/class.thread.php
@@ -1272,6 +1272,11 @@ class ThreadBody /* extends SplString */ {
         if (!in_array($type, static::$types))
             throw new Exception($type.': Unsupported ThreadBody type');
         $this->body = (string) $body;
+        if (strlen($this->body) > 250000) {
+            $max_packet = db_get_variable('max_allowed_packet', 'global');
+            // Truncate just short of the max_allowed_packet
+            $this->body = substr($this->body, $max_packet - 2048) . ' ... (truncated)';
+        }
         $this->type = $type;
         $this->options = array_merge($this->options, $options);
     }
-- 
GitLab