From e0bc40f16047ae908ca256b661f2532a7f83b831 Mon Sep 17 00:00:00 2001 From: Thomas Bruederli Date: Mon, 14 Apr 2014 18:25:04 +0200 Subject: [PATCH] Allow to store email message references for note objects (link format tentative) + store message-id in cache for querying --- plugins/libkolab/lib/kolab_format.php | 37 +++++++++++++++------- plugins/libkolab/lib/kolab_format_note.php | 11 ++++++- 2 files changed, 36 insertions(+), 12 deletions(-) diff --git a/plugins/libkolab/lib/kolab_format.php b/plugins/libkolab/lib/kolab_format.php index 563fbc6b..7c343100 100644 --- a/plugins/libkolab/lib/kolab_format.php +++ b/plugins/libkolab/lib/kolab_format.php @@ -502,6 +502,11 @@ abstract class kolab_format return array(); } + /** + * Utility function to extract object attachment data + * + * @param array Hash array reference to append attachment data into + */ protected function get_attachments(&$object) { // handle attachments @@ -520,13 +525,19 @@ abstract class kolab_format 'content' => $content, ); } - else if (substr($attach->uri(), 0, 4) == 'http') { + else if (in_array(substr($attach->uri(), 0, 4), array('http','imap'))) { $object['links'][] = $attach->uri(); } } } - protected function set_attachments($object) + /** + * Utility function to set attachment properties to the kolabformat object + * + * @param array Object data as hash array + * @param boolean True to always overwrite attachment information + */ + protected function set_attachments($object, $write = true) { // save attachments $vattach = new vectorattachment; @@ -537,16 +548,17 @@ abstract class kolab_format $attach->setLabel((string)$attr['name']); $attach->setUri('cid:' . $cid, $attr['mimetype'] ?: 'application/octet-stream'); if ($attach->isValid()) { - $vattach->push($attach); + $vattach->push($attach); + $write = true; } else { - rcube::raise_error(array( - 'code' => 660, - 'type' => 'php', - 'file' => __FILE__, - 'line' => __LINE__, - 'message' => "Invalid attributes for attachment $cid: " . var_export($attr, true), - ), true); + rcube::raise_error(array( + 'code' => 660, + 'type' => 'php', + 'file' => __FILE__, + 'line' => __LINE__, + 'message' => "Invalid attributes for attachment $cid: " . var_export($attr, true), + ), true); } } @@ -554,8 +566,11 @@ abstract class kolab_format $attach = new Attachment; $attach->setUri($link, 'unknown'); $vattach->push($attach); + $write = true; } - $this->obj->setAttachments($vattach); + if ($write) { + $this->obj->setAttachments($vattach); + } } } diff --git a/plugins/libkolab/lib/kolab_format_note.php b/plugins/libkolab/lib/kolab_format_note.php index 08b77350..bca51560 100644 --- a/plugins/libkolab/lib/kolab_format_note.php +++ b/plugins/libkolab/lib/kolab_format_note.php @@ -109,10 +109,19 @@ class kolab_format_note extends kolab_format { $tags = array(); - foreach ((array) $this->data['categories'] as $cat) { + foreach ((array)$this->data['categories'] as $cat) { $tags[] = rcube_utils::normalize_string($cat); } + // add tag for message references + foreach ((array)$this->data['links'] as $link) { + $url = parse_url($link); + if ($url['scheme'] == 'imap') { + parse_str($url['query'], $param); + $tags[] = 'ref:' . trim($param['message-id'] ?: urldecode($url['fragment']), '<> '); + } + } + return $tags; }