plugins/libkolab

Thomas Brüderli bruederli at kolabsys.com
Fri Jul 18 12:00:31 CEST 2014


 plugins/libkolab/lib/kolab_format.php         |    8 ++++++--
 plugins/libkolab/lib/kolab_storage_folder.php |   25 ++++++++++++++++++++++++-
 2 files changed, 30 insertions(+), 3 deletions(-)

New commits:
commit aada05332476bb56209fb6796eea2dc5e5b17665
Author: Thomas Bruederli <bruederli at kolabsys.com>
Date:   Fri Jul 18 12:00:08 2014 +0200

    Support reading attachments fully stored in XML payload instead of separate MIME parts

diff --git a/plugins/libkolab/lib/kolab_format.php b/plugins/libkolab/lib/kolab_format.php
index be2a0b8..4e53d85 100644
--- a/plugins/libkolab/lib/kolab_format.php
+++ b/plugins/libkolab/lib/kolab_format.php
@@ -510,8 +510,10 @@ abstract class kolab_format
      *
      * @param array Hash array reference to append attachment data into
      */
-    protected function get_attachments(&$object)
+    public function get_attachments(&$object)
     {
+        $this->init();
+
         // handle attachments
         $vattach = $this->obj->attachments();
         for ($i=0; $i < $vattach->size(); $i++) {
@@ -520,8 +522,10 @@ abstract class kolab_format
             // skip cid: attachments which are mime message parts handled by kolab_storage_folder
             if (substr($attach->uri(), 0, 4) != 'cid:' && $attach->label()) {
                 $name    = $attach->label();
+                $key     = $name . (isset($object['_attachments'][$name]) ? '.'.$i : '');
                 $content = $attach->data();
-                $object['_attachments'][$name] = array(
+                $object['_attachments'][$key] = array(
+                    'id'       => 'i:'.$i,
                     'name'     => $name,
                     'mimetype' => $attach->mimetype(),
                     'size'     => strlen($content),
diff --git a/plugins/libkolab/lib/kolab_storage_folder.php b/plugins/libkolab/lib/kolab_storage_folder.php
index fe0f0f3..ad6d5c0 100644
--- a/plugins/libkolab/lib/kolab_storage_folder.php
+++ b/plugins/libkolab/lib/kolab_storage_folder.php
@@ -346,7 +346,30 @@ class kolab_storage_folder extends kolab_storage_folder_api
     {
         if ($msguid = ($mailbox ? $uid : $this->cache->uid2msguid($uid))) {
             $this->imap->set_folder($mailbox ? $mailbox : $this->name);
-            return $this->imap->get_message_part($msguid, $part, null, $print, $fp, $skip_charset_conv);
+
+            if (substr($part, 0, 2) == 'i:') {
+                // attachment data is stored in XML
+                if ($object = $this->cache->get($msguid)) {
+                    // load data from XML (attachment content is not stored in cache)
+                    if ($object['_formatobj'] && isset($object['_size'])) {
+                        $object['_attachments'] = array();
+                        $object['_formatobj']->get_attachments($object);
+                    }
+
+                    foreach ($object['_attachments'] as $k => $attach) {
+                        if ($attach['id'] == $part) {
+                            if ($print)   echo $attach['content'];
+                            else if ($fp) fwrite($fp, $attach['content']);
+                            else          return $attach['content'];
+                            return true;
+                        }
+                    }
+                }
+            }
+            else {
+                // return message part from IMAP directly
+                return $this->imap->get_message_part($msguid, $part, null, $print, $fp, $skip_charset_conv);
+            }
         }
 
         return null;




More information about the commits mailing list