summaryrefslogtreecommitdiff
path: root/lib/kolab_sync_data_email.php
diff options
context:
space:
mode:
authorAleksander Machniak <alec@alec.pl>2014-01-23 08:13:17 (GMT)
committerAleksander Machniak <alec@alec.pl>2014-01-23 08:13:17 (GMT)
commit66f67a719d19281f459e8572145ef2052b3e5719 (patch)
tree3af88cfe384da84f092c63aae44cc0779f0247da /lib/kolab_sync_data_email.php
parent732642249064fc6b2cb8f01117879a70403c9e8c (diff)
downloadkolab-syncroton-66f67a719d19281f459e8572145ef2052b3e5719.tar.gz
Add <Preview> element support - email content preview for Windows Phone (Bug #2173)
Diffstat (limited to 'lib/kolab_sync_data_email.php')
-rw-r--r--lib/kolab_sync_data_email.php31
1 files changed, 30 insertions, 1 deletions
diff --git a/lib/kolab_sync_data_email.php b/lib/kolab_sync_data_email.php
index cc3e19a..f378eb3 100644
--- a/lib/kolab_sync_data_email.php
+++ b/lib/kolab_sync_data_email.php
@@ -251,12 +251,17 @@ class kolab_sync_data_email extends kolab_sync_data implements Syncroton_Data_ID
if (!empty($prefs[$type]['truncationSize'])) {
$truncateAt = $prefs[$type]['truncationSize'];
}
+
+ $preview = (int) $prefs[$type]['preview'];
$airSyncBaseType = $type;
+
break;
}
}
}
+ $body_params = array('type' => $airSyncBaseType);
+
// Message body
// In Sync examples there's one in which bodyPreferences is not defined
// in such case Truncated=1 and there's no body sent to the client
@@ -283,6 +288,11 @@ class kolab_sync_data_email extends kolab_sync_data implements Syncroton_Data_ID
$real_length = $body_length = strlen($messageBody);
}
+ // add Preview element to the Body result
+ if (!empty($preview) && $body_length) {
+ $body_params['preview'] = $this->getPreview($messageBody, $airSyncBaseType, $preview);
+ }
+
// truncate the body if needed
if ($truncateAt && $body_length > $truncateAt) {
$messageBody = mb_strcut($messageBody, 0, $truncateAt);
@@ -290,7 +300,6 @@ class kolab_sync_data_email extends kolab_sync_data implements Syncroton_Data_ID
$isTruncated = 1;
}
- $body_params = array('type' => $airSyncBaseType);
if ($isTruncated) {
$body_params['truncated'] = 1;
$body_params['estimatedDataSize'] = $real_length;
@@ -1209,6 +1218,26 @@ class kolab_sync_data_email extends kolab_sync_data implements Syncroton_Data_ID
return $body;
}
+ /**
+ * Converts and truncates message body for use in <Preview>
+ *
+ * @return string Truncated plain text message
+ */
+ protected function getPreview($body, $type, $size)
+ {
+ if ($type == Syncroton_Command_Sync::BODY_TYPE_HTML) {
+ $txt = new rcube_html2text($body, false, true);
+ $body = $txt->get_text();
+ }
+
+ // size limit defined in ActiveSync protocol
+ if ($size > 255) {
+ $size = 255;
+ }
+
+ return mb_strcut(trim($body), 0, $size);
+ }
+
public static function charset_to_cp($charset)
{
// @TODO: ?????