diff --git a/plugins/libkolab/lib/kolab_format.php b/plugins/libkolab/lib/kolab_format.php index c3c1b12c..d8842072 100644 --- a/plugins/libkolab/lib/kolab_format.php +++ b/plugins/libkolab/lib/kolab_format.php @@ -386,9 +386,11 @@ abstract class kolab_format /** * Convert the Kolab object into a hash array data structure * + * @param array Additional data for merge + * * @return array Kolab object data as hash array */ - abstract public function to_array(); + abstract public function to_array($data = array()); /** * Callback for kolab_storage_cache to get object specific tags to cache diff --git a/plugins/libkolab/lib/kolab_format_configuration.php b/plugins/libkolab/lib/kolab_format_configuration.php index 0edc6a24..5e64e307 100644 --- a/plugins/libkolab/lib/kolab_format_configuration.php +++ b/plugins/libkolab/lib/kolab_format_configuration.php @@ -88,9 +88,11 @@ class kolab_format_configuration extends kolab_format /** * Convert the Configuration object into a hash array data structure * + * @param array Additional data for merge + * * @return array Config object data as hash array */ - public function to_array() + public function to_array($data = array()) { // return cached result if (!empty($this->data)) diff --git a/plugins/libkolab/lib/kolab_format_contact.php b/plugins/libkolab/lib/kolab_format_contact.php index 39e579cd..7994b97d 100644 --- a/plugins/libkolab/lib/kolab_format_contact.php +++ b/plugins/libkolab/lib/kolab_format_contact.php @@ -266,9 +266,11 @@ class kolab_format_contact extends kolab_format /** * Convert the Contact object into a hash array data structure * + * @param array Additional data for merge + * * @return array Contact data as hash array */ - public function to_array() + public function to_array($data = array()) { // return cached result if (!empty($this->data)) @@ -341,7 +343,7 @@ class kolab_format_contact extends kolab_format if ($this->obj->photoMimetype()) $object['photo'] = $this->obj->photo(); else if ($this->xmlobject && ($photo_name = $this->xmlobject->pictureAttachmentName())) - $object['photo'] = $photo_name; + $object['photo'] = $photo_name; // relateds -> spouse, children $this->read_relateds($this->obj->relateds(), $object); diff --git a/plugins/libkolab/lib/kolab_format_distributionlist.php b/plugins/libkolab/lib/kolab_format_distributionlist.php index 5622fc55..f91f6978 100644 --- a/plugins/libkolab/lib/kolab_format_distributionlist.php +++ b/plugins/libkolab/lib/kolab_format_distributionlist.php @@ -83,9 +83,11 @@ class kolab_format_distributionlist extends kolab_format /** * Convert the Distlist object into a hash array data structure * + * @param array Additional data for merge + * * @return array Distribution list data as hash array */ - public function to_array() + public function to_array($data = array()) { // return cached result if (!empty($this->data)) diff --git a/plugins/libkolab/lib/kolab_format_event.php b/plugins/libkolab/lib/kolab_format_event.php index 4ef6735f..d750f8e0 100644 --- a/plugins/libkolab/lib/kolab_format_event.php +++ b/plugins/libkolab/lib/kolab_format_event.php @@ -106,9 +106,11 @@ class kolab_format_event extends kolab_format_xcal /** * Convert the Event object into a hash array data structure * + * @param array Additional data for merge + * * @return array Event data as hash array */ - public function to_array() + public function to_array($data = array()) { // return cached result if (!empty($this->data)) @@ -158,8 +160,19 @@ class kolab_format_event extends kolab_format_xcal } } - $this->data = $object; - return $this->data; + // merge with additional data, e.g. attachments from the message + if ($data) { + foreach ($data as $idx => $value) { + if (is_array($value)) { + $object[$idx] = array_merge((array)$object[$idx], $value); + } + else { + $object[$idx] = $value; + } + } + } + + return $this->data = $object; } /** diff --git a/plugins/libkolab/lib/kolab_format_file.php b/plugins/libkolab/lib/kolab_format_file.php index b3ab1580..22d1e7c5 100644 --- a/plugins/libkolab/lib/kolab_format_file.php +++ b/plugins/libkolab/lib/kolab_format_file.php @@ -27,6 +27,7 @@ class kolab_format_file extends kolab_format { public $CTYPE = 'application/x-vnd.kolab.file'; + protected $objclass = 'File'; protected $read_func = 'kolabformat::readKolabFile'; protected $write_func = 'kolabformat::writeKolabFile'; @@ -36,12 +37,6 @@ class kolab_format_file extends kolab_format 'confidential' => kolabformat::ClassConfidential, ); - function __construct($xmldata = null) - { - $this->obj = new File; - $this->xmldata = $xmldata; - } - /** * Set properties to the kolabformat object * @@ -101,9 +96,11 @@ class kolab_format_file extends kolab_format /** * Convert the Configuration object into a hash array data structure * + * @param array Additional data for merge + * * @return array Config object data as hash array */ - public function to_array() + public function to_array($data = array()) { // return cached result if (!empty($this->data)) @@ -123,12 +120,19 @@ class kolab_format_file extends kolab_format 'notes' => $this->obj->note(), ); - // attachments are mime message parts handled by kolab_storage_folder - // @TODO: handle inline attachments + // merge with additional data, e.g. attachments from the message + if ($data) { + foreach ($data as $idx => $value) { + if (is_array($value)) { + $object[$idx] = array_merge((array)$object[$idx], $value); + } + else { + $object[$idx] = $value; + } + } + } - $this->data = $object; - - return $this->data; + return $this->data = $object; } /** @@ -155,6 +159,10 @@ class kolab_format_file extends kolab_format public function get_words() { // Store filename in 'words' for fast access to file by name + if (empty($this->data['_attachments'])) { + return array(); + } + $attachment = array_shift($this->data['_attachments']); return array($attachment['name']); } diff --git a/plugins/libkolab/lib/kolab_format_journal.php b/plugins/libkolab/lib/kolab_format_journal.php index daab1acb..01cdc3db 100644 --- a/plugins/libkolab/lib/kolab_format_journal.php +++ b/plugins/libkolab/lib/kolab_format_journal.php @@ -66,9 +66,11 @@ class kolab_format_journal extends kolab_format /** * Convert the Configuration object into a hash array data structure * + * @param array Additional data for merge + * * @return array Config object data as hash array */ - public function to_array() + public function to_array($data = array()) { // return cached result if (!empty($this->data)) @@ -83,7 +85,6 @@ class kolab_format_journal extends kolab_format 'changed' => self::php_datetime($this->obj->lastModified()), ); - // TODO: read object properties $this->data = $object; diff --git a/plugins/libkolab/lib/kolab_format_note.php b/plugins/libkolab/lib/kolab_format_note.php index 5af93434..5a9c0bc5 100644 --- a/plugins/libkolab/lib/kolab_format_note.php +++ b/plugins/libkolab/lib/kolab_format_note.php @@ -66,9 +66,11 @@ class kolab_format_note extends kolab_format /** * Convert the Configuration object into a hash array data structure * + * @param array Additional data for merge + * * @return array Config object data as hash array */ - public function to_array() + public function to_array($data = array()) { // return cached result if (!empty($this->data)) @@ -83,7 +85,6 @@ class kolab_format_note extends kolab_format 'changed' => self::php_datetime($this->obj->lastModified()), ); - // TODO: read object properties $this->data = $object; diff --git a/plugins/libkolab/lib/kolab_format_task.php b/plugins/libkolab/lib/kolab_format_task.php index 77870c71..d66cafd7 100644 --- a/plugins/libkolab/lib/kolab_format_task.php +++ b/plugins/libkolab/lib/kolab_format_task.php @@ -71,9 +71,11 @@ class kolab_format_task extends kolab_format_xcal /** * Convert the Configuration object into a hash array data structure * + * @param array Additional data for merge + * * @return array Config object data as hash array */ - public function to_array() + public function to_array($data = array()) { // return cached result if (!empty($this->data)) diff --git a/plugins/libkolab/lib/kolab_format_xcal.php b/plugins/libkolab/lib/kolab_format_xcal.php index 3e1a7217..a6450afb 100644 --- a/plugins/libkolab/lib/kolab_format_xcal.php +++ b/plugins/libkolab/lib/kolab_format_xcal.php @@ -88,9 +88,11 @@ abstract class kolab_format_xcal extends kolab_format /** * Convert common xcard properties into a hash array data structure * + * @param array Additional data for merge + * * @return array Object data as hash array */ - public function to_array() + public function to_array($data = array()) { $status_map = array_flip($this->status_map); $sensitivity_map = array_flip($this->sensitivity_map); diff --git a/plugins/libkolab/lib/kolab_storage_folder.php b/plugins/libkolab/lib/kolab_storage_folder.php index 27517cff..a671faf2 100644 --- a/plugins/libkolab/lib/kolab_storage_folder.php +++ b/plugins/libkolab/lib/kolab_storage_folder.php @@ -524,11 +524,10 @@ class kolab_storage_folder $format->load($xml); if ($format->is_valid()) { - $object = $format->to_array(); - $object['_type'] = $object_type; - $object['_msguid'] = $msguid; - $object['_mailbox'] = $this->name; - $object['_attachments'] = array_merge((array)$object['_attachments'], $attachments); + $object = $format->to_array(array('_attachments' => $attachments)); + $object['_type'] = $object_type; + $object['_msguid'] = $msguid; + $object['_mailbox'] = $this->name; $object['_formatobj'] = $format; return $object; @@ -766,7 +765,7 @@ class kolab_storage_folder $object['uid'] = $format->uid; // read UID from format $object['_formatobj'] = $format; - if (!$format->is_valid() || empty($object['uid'])) { + if (empty($xml) || !$format->is_valid() || empty($object['uid'])) { return false; }