Commit f1a991b1 authored by Sebastian Kummer's avatar Sebastian Kummer

ZP-708 Wrap the plaintext body, html body or mime message into a

StringStreamWrapper. While the wrapper correctly truncates (UTF-8
compatible), we can also truncate before loading the data in.

Released under the Affero GNU General Public License (AGPL) version 3.
parent 19f9cb6e
...@@ -1024,37 +1024,39 @@ class BackendIMAP extends BackendDiff { ...@@ -1024,37 +1024,39 @@ class BackendIMAP extends BackendDiff {
if (Request::GetProtocolVersion() >= 12.0) { if (Request::GetProtocolVersion() >= 12.0) {
$output->asbody = new SyncBaseBody(); $output->asbody = new SyncBaseBody();
$data = "";
switch($bpReturnType) { switch($bpReturnType) {
case SYNC_BODYPREFERENCE_PLAIN: case SYNC_BODYPREFERENCE_PLAIN:
$output->asbody->data = $plainBody; $data = $plainBody;
break; break;
case SYNC_BODYPREFERENCE_HTML: case SYNC_BODYPREFERENCE_HTML:
if ($htmlBody == "") { if ($htmlBody == "") {
$output->asbody->data = $plainBody; $data = $plainBody;
$bpReturnType = SYNC_BODYPREFERENCE_PLAIN; $bpReturnType = SYNC_BODYPREFERENCE_PLAIN;
} }
else { else {
$output->asbody->data = $htmlBody; $data = $htmlBody;
} }
break; break;
case SYNC_BODYPREFERENCE_MIME: case SYNC_BODYPREFERENCE_MIME:
//We don't need to create a new MIME mail, we already have one!! //We don't need to create a new MIME mail, we already have one!!
$output->asbody->data = $mail; $data = $mail;
break; break;
case SYNC_BODYPREFERENCE_RTF: case SYNC_BODYPREFERENCE_RTF:
ZLog::Write(LOGLEVEL_DEBUG, "BackendIMAP->GetMessage RTF Format NOT CHECKED"); ZLog::Write(LOGLEVEL_DEBUG, "BackendIMAP->GetMessage RTF Format NOT SUPPORTED");
$output->asbody->data = base64_encode($plainBody); // TODO: this is broken. This is no RTF.
$data = base64_encode($plainBody);
break; break;
} }
// truncate body, if requested // truncate body, if requested
if(strlen($output->asbody->data) > $truncsize) { if(strlen($data) > $truncsize) {
$output->asbody->data = Utils::Utf8_truncate($output->asbody->data, $truncsize); $data = Utils::Utf8_truncate($data, $truncsize);
$output->asbody->truncated = 1; $output->asbody->truncated = 1;
} }
$output->asbody->data = StringStreamWrapper::Open($data);
$output->asbody->type = $bpReturnType; $output->asbody->type = $bpReturnType;
$output->nativebodytype = $bpReturnType; $output->nativebodytype = $bpReturnType;
$output->asbody->estimatedDataSize = strlen($output->asbody->data); $output->asbody->estimatedDataSize = strlen($data);
$bpo = $contentparameters->BodyPreference($output->asbody->type); $bpo = $contentparameters->BodyPreference($output->asbody->type);
if (Request::GetProtocolVersion() >= 14.0 && $bpo->GetPreview()) { if (Request::GetProtocolVersion() >= 14.0 && $bpo->GetPreview()) {
...@@ -1068,28 +1070,22 @@ class BackendIMAP extends BackendDiff { ...@@ -1068,28 +1070,22 @@ class BackendIMAP extends BackendDiff {
else { // ASV_2.5 else { // ASV_2.5
$output->bodytruncated = 0; $output->bodytruncated = 0;
/* BEGIN fmbiete's contribution r1528, ZP-320 */ /* BEGIN fmbiete's contribution r1528, ZP-320 */
$data = "";
if ($bpReturnType == SYNC_BODYPREFERENCE_MIME) { if ($bpReturnType == SYNC_BODYPREFERENCE_MIME) {
if (strlen($mail) > $truncsize) { $data = $mail;
$output->mimedata = Utils::Utf8_truncate($mail, $truncsize);
$output->mimetruncated = 1;
} }
else { else {
$output->mimetruncated = 0; $data = $plainBody;
$output->mimedata = $mail;
} }
$output->mimesize = strlen($output->mimedata);
} $output->mimesize = strlen($data);
else { if (strlen($data) > $truncsize) {
// truncate body, if requested $output->mimedata = StringStreamWrapper::Open(Utils::Utf8_truncate($data, $truncsize));
if (strlen($plainBody) > $truncsize) { $output->mimetruncated = 1;
$output->body = Utils::Utf8_truncate($plainBody, $truncsize);
$output->bodytruncated = 1;
} }
else { else {
$output->body = $plainBody; $output->mimetruncated = 0;
$output->bodytruncated = 0; $output->mimedata = StringStreamWrapper::Open($data);
}
$output->bodysize = strlen($output->body);
} }
/* END fmbiete's contribution r1528, ZP-320 */ /* END fmbiete's contribution r1528, ZP-320 */
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment