summaryrefslogtreecommitdiff
path: root/lib/kolab_sync_data_email.php
diff options
context:
space:
mode:
authorAleksander Machniak <alec@alec.pl>2013-02-07 10:02:44 (GMT)
committerAleksander Machniak <alec@alec.pl>2013-02-07 10:02:44 (GMT)
commit778eb3a5c84c3348f2fbcfdff7b6d2ea48bd4639 (patch)
tree4d115842659af74de8a3a17dcb58a7a7749da117 /lib/kolab_sync_data_email.php
parent78339d3ae6720b99c3493edaa2310a436b5f771e (diff)
downloadkolab-syncroton-778eb3a5c84c3348f2fbcfdff7b6d2ea48bd4639.tar.gz
Fix handling of Body parameters and MessageClass element of email object (Bug #1620)kolab-syncroton-2.1-rc1
Diffstat (limited to 'lib/kolab_sync_data_email.php')
-rw-r--r--lib/kolab_sync_data_email.php61
1 files changed, 35 insertions, 26 deletions
diff --git a/lib/kolab_sync_data_email.php b/lib/kolab_sync_data_email.php
index 0bc3be8..45ac1b9 100644
--- a/lib/kolab_sync_data_email.php
+++ b/lib/kolab_sync_data_email.php
@@ -195,7 +195,8 @@ class kolab_sync_data_email extends kolab_sync_data implements Syncroton_Data_ID
}
}
- // get truncation
+ // get truncation and body type
+ $airSyncBaseType = Syncroton_Command_Sync::BODY_TYPE_PLAIN_TEXT;
$truncateAt = null;
$opts = $collection->options;
$prefs = $opts['bodyPreferences'];
@@ -235,17 +236,25 @@ class kolab_sync_data_email extends kolab_sync_data implements Syncroton_Data_ID
}
}
}
- else if (!empty($prefs[Syncroton_Command_Sync::BODY_TYPE_HTML])) {
- if (!empty($prefs[Syncroton_Command_Sync::BODY_TYPE_HTML]['truncationSize'])) {
- $truncateAt = $prefs[Syncroton_Command_Sync::BODY_TYPE_HTML]['truncationSize'];
- }
- $airSyncBaseType = Syncroton_Command_Sync::BODY_TYPE_HTML;
- }
else {
- if (!empty($prefs[Syncroton_Command_Sync::BODY_TYPE_PLAIN_TEXT]) && !empty($prefs[Syncroton_Command_Sync::BODY_TYPE_PLAIN_TEXT]['truncationSize'])) {
- $truncateAt = $prefs[Syncroton_Command_Sync::BODY_TYPE_PLAIN_TEXT]['truncationSize'];
+ $types = array(
+ Syncroton_Command_Sync::BODY_TYPE_MIME,
+ Syncroton_Command_Sync::BODY_TYPE_HTML,
+ Syncroton_Command_Sync::BODY_TYPE_PLAIN_TEXT,
+ );
+
+ // @TODO: client can support both HTML and TEXT use one of
+ // them which is better according to the real message body type
+
+ foreach ($types as $type) {
+ if (!empty($prefs[$type])) {
+ if (!empty($prefs[$type]['truncationSize'])) {
+ $truncateAt = $prefs[$type]['truncationSize'];
+ }
+ $airSyncBaseType = $type;
+ break;
+ }
}
- $airSyncBaseType = Syncroton_Command_Sync::BODY_TYPE_PLAIN_TEXT;
}
// Message body
@@ -257,6 +266,7 @@ class kolab_sync_data_email extends kolab_sync_data implements Syncroton_Data_ID
$real_length = $message->size;
$truncateAt = 0;
$body_length = 0;
+ $isTruncated = 1;
}
else if ($airSyncBaseType == Syncroton_Command_Sync::BODY_TYPE_MIME) {
$messageBody = $this->storage->get_raw_body($message->uid);
@@ -271,30 +281,29 @@ class kolab_sync_data_email extends kolab_sync_data implements Syncroton_Data_ID
$real_length = $body_length = strlen($messageBody);
}
- if ($truncateAt !== null) {
- if ($body_length > $truncateAt) {
- $messageBody = mb_strcut($messageBody, 0, $truncateAt);
- $body_length = strlen($truncateAt);
- }
- $isTruncacted = 1;
- }
- else {
- $isTruncacted = 0;
+ // truncate the body if needed
+ if ($truncateAt && $body_length > $truncateAt) {
+ $messageBody = mb_strcut($messageBody, 0, $truncateAt);
+ $body_length = strlen($messageBody);
+ $isTruncated = 1;
}
- $body_params = array(
- 'type' => $airSyncBaseType,
- 'truncated' => $isTruncacted,
- );
+ $body_params = array('type' => $airSyncBaseType);
if ($isTruncated) {
+ $body_params['truncated'] = 1;
$body_params['estimatedDataSize'] = $real_length;
}
- $result['body'] = $this->setBody($messageBody, $body_params);
- $result['nativeBodyType'] = intval($message->has_html_part(false));
+ // add Body element to the result
+ $result['body'] = $this->setBody($messageBody, $body_params);
+
+ // original body type
+ // @TODO: get this value from getMessageBody()
+ $result['nativeBodyType'] = $message->has_html_part(false) ? 2 : 1;
// Message class
- $result['messageClass'] = 'IPM.Note' . ($airSyncBaseType == Syncroton_Command_Sync::MIMESUPPORT_SEND_MIME ? '.SMIME' : '');
+ // @TODO: add messageClass suffix for encrypted messages
+ $result['messageClass'] = 'IPM.Note';
$result['contentClass'] = 'urn:content-classes:message';
// attachments