diff --git a/include/class.thread.php b/include/class.thread.php index 164624d35c6b8ab34300f07cda5a8f4cd9a2b1cc..3911f714b672fd98287a9ac5578fbbc3d1567473 100644 --- a/include/class.thread.php +++ b/include/class.thread.php @@ -601,6 +601,7 @@ implements TemplateVariable { const PERM_EDIT = 'thread.edit'; var $_headers; + var $_body; var $_thread; var $_actions; var $is_autoreply; @@ -676,9 +677,21 @@ implements TemplateVariable { } function getBody() { - return ThreadEntryBody::fromFormattedText($this->body, $this->format, - array('balanced' => $this->hasFlag(self::FLAG_BALANCED)) - ); + + if (!isset($this->_body)) { + $body = $this->body; + if ($body == null && $this->getNumAttachments()) { + foreach ($this->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; } function setBody($body) { @@ -1396,14 +1409,36 @@ implements TemplateVariable { // Set body here after it was rewritten to capture the stored file // keys (above) - $entry->body = $body; - if (!$entry->save()) + // Store body as an attachment if bigger than allowed packet size + if (mb_strlen($body) >= 65000) { // 65,535 chars in text field. + $entry->body = NULL; + $file = array( + 'type' => 'text/html', + 'name' => md5($body).'.txt', + 'data' => $body, + ); + + if (($AF = AttachmentFile::create($file))) { + $attached_files[$file['key']] = array( + 'id' => $AF->getId(), + 'inline' => true, + 'file' => $AF); + } else { + $entry->body = $body; + } + } else { + $entry->body = $body; + + } + + if (!$entry->save(true)) return false; // Associate the attached files with this new entry $entry->createAttachments($attached_files); + // Save mail message id, if available $entry->saveEmailInfo($vars); diff --git a/include/class.thread_actions.php b/include/class.thread_actions.php index 6650ee09810b2854ce7fe01f318813d6584d6706..b585c8cb7e6f58533d586ca349a829de3dcaf61d 100644 --- a/include/class.thread_actions.php +++ b/include/class.thread_actions.php @@ -123,7 +123,7 @@ JS $old = $this->entry; $new = ThreadEntryBody::fromFormattedText($_POST['body'], $old->format); - if ($new->getClean() == $old->body) + if ($new->getClean() == $old->getBody()) // No update was performed return $old; diff --git a/include/staff/templates/thread-entry-edit.tmpl.php b/include/staff/templates/thread-entry-edit.tmpl.php index 3f2d0fe56235af4ab6e539da566dc6ba578ce1ee..14a13b63e7a366afee18ba9f21ecfa41cf276252 100644 --- a/include/staff/templates/thread-entry-edit.tmpl.php +++ b/include/staff/templates/thread-entry-edit.tmpl.php @@ -34,7 +34,8 @@ class="large <?php if ($cfg->isRichTextEnabled() && $this->entry->format == 'html') echo 'richtext'; - ?>"><?php echo htmlspecialchars(Format::viewableImages($this->entry->body)); + ?>"><?php echo htmlspecialchars(Format::viewableImages( + (string) $this->entry->getBody())); ?></textarea> <?php if ($this->entry->type == 'R') { ?>