From aff9bcb6bc0a43b84c599f348ea142ce010d26c3 Mon Sep 17 00:00:00 2001
From: Peter Rotich <peter@enhancesoft.com>
Date: Wed, 22 Aug 2018 03:14:55 +0000
Subject: [PATCH] Thread Entry: Chucked body

This commit addresses a case where a large thread entry body (emailed) is
stored as a file, when fetching it we have to make sure we're only fetching
plain text/html and not attachment files.
---
 include/class.thread.php | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/include/class.thread.php b/include/class.thread.php
index 2aa82cd49..b499b95ed 100644
--- a/include/class.thread.php
+++ b/include/class.thread.php
@@ -848,20 +848,24 @@ implements TemplateVariable {
     }
 
     function getBody() {
-
         if (!isset($this->_body)) {
             $body = $this->body;
             if ($body == null && $this->getNumAttachments()) {
-                foreach ($this->attachments as $a)
+                $attachments = Attachment::objects()
+                   ->filter(array(
+                               'inline' => 1,
+                               'object_id' => $this->getId(),
+                               'type' => ObjectModel::OBJECT_TYPE_THREAD,
+                               'file__type__in' => array('text/html','text/plain'))
+                           );
+                foreach ($attachments as $a)
                     if ($a->inline && ($f=$a->getFile()))
                         $body .= $f->getData();
             }
-
             $this->_body = ThreadEntryBody::fromFormattedText($body, $this->format,
                 array('balanced' => $this->hasFlag(self::FLAG_BALANCED))
             );
         }
-
         return $this->_body;
     }
 
-- 
GitLab