Permalink
Browse files

Chunk long text body

  • Loading branch information...
protich committed Feb 21, 2017
1 parent 11de92f commit 7b68c99453ae71a8eb4f8cb96f3b27dadabddacc
View
@@ -601,6 +601,7 @@ class ThreadEntry extends VerySimpleModel
const PERM_EDIT = 'thread.edit';
var $_headers;
var $_body;
var $_thread;
var $_actions;
var $is_autoreply;
@@ -676,9 +677,21 @@ function getTitle() {
}
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 @@ static function create($vars=false) {
// 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);
@@ -123,7 +123,7 @@ function updateEntry($guard=false) {
$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;
@@ -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') { ?>

0 comments on commit 7b68c99

Please sign in to comment.