lib/kolab_sync_data_email.php

Aleksander Machniak machniak at kolabsys.com
Thu Jan 23 09:16:14 CET 2014


 lib/kolab_sync_data_email.php |   31 ++++++++++++++++++++++++++++++-
 1 file changed, 30 insertions(+), 1 deletion(-)

New commits:
commit 66f67a719d19281f459e8572145ef2052b3e5719
Author: Aleksander Machniak <alec at alec.pl>
Date:   Thu Jan 23 09:13:17 2014 +0100

    Add <Preview> element support - email content preview for Windows Phone (Bug #2173)

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: ?????




More information about the commits mailing list