Branch 'roundcubemail-plugins-kolab-format2-horde5' - plugins/libkolab

Thomas Brüderli bruederli at kolabsys.com
Wed Feb 27 09:49:44 CET 2013


 plugins/libkolab/lib/kolab_storage_folder.php |   30 +++++++++++++++++++++++++-
 1 file changed, 29 insertions(+), 1 deletion(-)

New commits:
commit ad126d80ca3df8a6b6e3b2b6be6dcbd584e45f91
Author: Thomas Bruederli <bruederli at kolabsys.com>
Date:   Wed Feb 27 09:49:07 2013 +0100

    Gracefully handle buggy messages with either missing or duplicated X-Kolab-Type headers

diff --git a/plugins/libkolab/lib/kolab_storage_folder.php b/plugins/libkolab/lib/kolab_storage_folder.php
index 23bb3a6..d3659fa 100644
--- a/plugins/libkolab/lib/kolab_storage_folder.php
+++ b/plugins/libkolab/lib/kolab_storage_folder.php
@@ -423,12 +423,40 @@ class kolab_storage_folder
         $this->imap->set_folder($folder);
 
         $headers = $this->imap->get_message_headers($msguid);
+        $message = null;
 
         // Message doesn't exist?
         if (empty($headers)) {
             return false;
         }
 
+        // extract the X-Kolab-Type header from the XML attachment part if missing
+        if (empty($headers->others['x-kolab-type'])) {
+            $message = new rcube_message($msguid);
+            foreach ((array)$message->attachments as $part) {
+                if (strpos($part->mimetype, kolab_format::KTYPE_PREFIX) === 0) {
+                    $headers->others['x-kolab-type'] = $part->mimetype;
+                    break;
+                }
+            }
+        }
+        // fix buggy messages stating the X-Kolab-Type header twice
+        else if (is_array($headers->others['x-kolab-type'])) {
+            $headers->others['x-kolab-type'] = reset($headers->others['x-kolab-type']);
+        }
+
+        // no object type header found: abort
+        if (empty($headers->others['x-kolab-type'])) {
+            rcube::raise_error(array(
+                'code' => 600,
+                'type' => 'php',
+                'file' => __FILE__,
+                'line' => __LINE__,
+                'message' => "No X-Kolab-Type information found in message $msguid ($this->name).",
+            ), true);
+            return false;
+        }
+
         $object_type = kolab_format::mime2object_type($headers->others['x-kolab-type']);
         $content_type  = kolab_format::KTYPE_PREFIX . $object_type;
 
@@ -436,7 +464,7 @@ class kolab_storage_folder
         if ($type != '*' && $object_type != $type)
             return false;
 
-        $message = new rcube_message($msguid);
+        if (!$message) $message = new rcube_message($msguid);
         $attachments = array();
 
         // get XML part





More information about the commits mailing list