lib/kolab_sync_data_email.php
Aleksander Machniak
machniak at kolabsys.com
Thu Feb 7 11:04:04 CET 2013
lib/kolab_sync_data_email.php | 61 ++++++++++++++++++++++++------------------
1 file changed, 35 insertions(+), 26 deletions(-)
New commits:
commit 778eb3a5c84c3348f2fbcfdff7b6d2ea48bd4639
Author: Aleksander Machniak <alec at alec.pl>
Date: Thu Feb 7 11:02:44 2013 +0100
Fix handling of Body parameters and MessageClass element of email object (Bug #1620)
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
More information about the commits
mailing list