plugins/kolab_notes plugins/libkolab plugins/tasklist
Thomas Brüderli
bruederli at kolabsys.com
Tue Jan 13 22:20:21 CET 2015
plugins/kolab_notes/kolab_notes.php | 32 +---------
plugins/libkolab/lib/kolab_storage_config.php | 44 ++++++++------
plugins/tasklist/drivers/kolab/tasklist_kolab_driver.php | 31 ++++-----
plugins/tasklist/drivers/tasklist_driver.php | 9 +-
plugins/tasklist/tasklist.php | 47 +--------------
5 files changed, 54 insertions(+), 109 deletions(-)
New commits:
commit 0a51ccd5a44882e84c0f14cf41e5c0bc790fb469
Author: Thomas Bruederli <bruederli at kolabsys.com>
Date: Tue Jan 13 22:19:52 2015 +0100
Consolidate message reference handling functions into libkolab plugin (in preparation for #4161)
diff --git a/plugins/kolab_notes/kolab_notes.php b/plugins/kolab_notes/kolab_notes.php
index c2b4945..b472d2a 100644
--- a/plugins/kolab_notes/kolab_notes.php
+++ b/plugins/kolab_notes/kolab_notes.php
@@ -394,7 +394,10 @@ class kolab_notes extends rcube_plugin
$this->rc->output->set_env('kolab_notes_template', array(
'_from_mail' => true,
'title' => $message->get('subject'),
- 'links' => array($this->get_message_reference(kolab_storage_config::get_message_uri($message, $folder))),
+ 'links' => array(kolab_storage_config::get_message_reference(
+ kolab_storage_config::get_message_uri($message, $folder),
+ 'note'
+ )),
));
}
}
@@ -573,9 +576,8 @@ class kolab_notes extends rcube_plugin
}
// resolve message links
- $me = $this;
- $note['links'] = array_map(function($link) use ($me, $resolve) {
- return $me->get_message_reference($link, $resolve) ?: array('uri' => $link);
+ $note['links'] = array_map(function($link) {
+ return kolab_storage_config::get_message_reference($link, 'note') ?: array('uri' => $link);
}, $this->get_links($note['uid']));
return $note;
@@ -1043,28 +1045,6 @@ class kolab_notes extends rcube_plugin
}
/**
- * Resolve the email message reference from the given URI
- */
- public function get_message_reference($uri, $resolve = false)
- {
- if ($linkref = kolab_storage_config::parse_member_url($uri)) {
- $linkref['subject'] = $linkref['params']['subject'];
- $linkref['uri'] = $uri;
- $linkref['mailurl'] = $this->rc->url(array(
- 'task' => 'mail',
- 'action' => 'show',
- 'mbox' => $linkref['folder'],
- 'uid' => $linkref['uid'],
- 'rel' => 'note',
- ));
-
- unset($linkref['params']);
- }
-
- return $linkref;
- }
-
- /**
* Update note tags
*/
private function save_tags($uid, $tags)
diff --git a/plugins/libkolab/lib/kolab_storage_config.php b/plugins/libkolab/lib/kolab_storage_config.php
index 59c191d..036b827 100644
--- a/plugins/libkolab/lib/kolab_storage_config.php
+++ b/plugins/libkolab/lib/kolab_storage_config.php
@@ -356,24 +356,6 @@ class kolab_storage_config
}
/**
- * Simplify the given message URI by converting the mailbox
- * part into a relative IMAP path valid for the current user.
- */
- public static function local_message_uri($uri)
- {
- if (strpos($uri, 'imap:///') === 0) {
- $linkref = kolab_storage_config::parse_member_url($uri);
-
- return 'imap:///' . implode('/', array_map('rawurlencode', explode('/', $linkref['folder']))) .
- '/' . $linkref['uid'] .
- '?' . http_build_query($linkref['params'], '', '&');
- }
-
- return $uri;
- }
-
-
- /**
* Build array of member URIs from set of messages
*
* @param string $folder Folder name
@@ -855,4 +837,30 @@ class kolab_storage_config
return self::build_member_url($params);
}
+
+ /**
+ * Resolve the email message reference from the given URI
+ */
+ public function get_message_reference($uri, $rel = null)
+ {
+ if ($linkref = self::parse_member_url($uri)) {
+ $linkref['subject'] = $linkref['params']['subject'];
+ $linkref['uri'] = $uri;
+
+ $rcmail = rcube::get_instance();
+ if (method_exists($rcmail, 'url')) {
+ $linkref['mailurl'] = $rcmail->url(array(
+ 'task' => 'mail',
+ 'action' => 'show',
+ 'mbox' => $linkref['folder'],
+ 'uid' => $linkref['uid'],
+ 'rel' => $rel,
+ ));
+ }
+
+ unset($linkref['params']);
+ }
+
+ return $linkref;
+ }
}
diff --git a/plugins/tasklist/drivers/kolab/tasklist_kolab_driver.php b/plugins/tasklist/drivers/kolab/tasklist_kolab_driver.php
index 6c9f418..0cb51ae 100644
--- a/plugins/tasklist/drivers/kolab/tasklist_kolab_driver.php
+++ b/plugins/tasklist/drivers/kolab/tasklist_kolab_driver.php
@@ -825,7 +825,7 @@ class tasklist_kolab_driver extends tasklist_driver
private function get_links($uid)
{
$config = kolab_storage_config::get_instance();
- return array_map(array('kolab_storage_config','local_message_uri'), $config->get_object_links($uid));
+ return $config->get_object_links($uid);
}
/**
@@ -838,18 +838,6 @@ class tasklist_kolab_driver extends tasklist_driver
$links = array();
}
- // convert the given (simplified) message links into absolute IMAP URIs
- $links = array_map(function($link) {
- $url = parse_url(substr($link, 8));
- parse_str($url['query'], $linkref);
-
- $path = explode('/', $url['path']);
- $linkref['uid'] = array_pop($path);
- $linkref['folder'] = join('/', array_map('rawurldecode', $path));
-
- return kolab_storage_config::build_member_url($linkref);
- }, $links);
-
$config = kolab_storage_config::get_instance();
$remove = array_diff($config->get_object_links($uid), $links);
return $config->save_object_links($uid, $links, $remove);
@@ -1272,14 +1260,21 @@ class tasklist_kolab_driver extends tasklist_driver
}
/**
- * Build a URI representing the given message reference
+ * Build a struct representing the given message reference
*
- * @see tasklist_driver::get_message_uri()
+ * @see tasklist_driver::get_message_reference()
*/
- public function get_message_uri($headers, $folder)
+ public function get_message_reference($uri_or_headers, $folder = null)
{
- $uri = kolab_storage_config::get_message_uri($headers, $folder);
- return kolab_storage_config::local_message_uri($uri);
+ if (is_object($uri_or_headers)) {
+ $uri_or_headers = kolab_storage_config::get_message_uri($uri_or_headers, $folder);
+ }
+
+ if (is_string($uri_or_headers)) {
+ return kolab_storage_config::get_message_reference($uri_or_headers, 'task');
+ }
+
+ return false;
}
/**
diff --git a/plugins/tasklist/drivers/tasklist_driver.php b/plugins/tasklist/drivers/tasklist_driver.php
index 791d2ab..1de0353 100644
--- a/plugins/tasklist/drivers/tasklist_driver.php
+++ b/plugins/tasklist/drivers/tasklist_driver.php
@@ -288,14 +288,15 @@ abstract class tasklist_driver
public function get_attachment_body($id, $task) { }
/**
- * Build a URI representing the given message reference
+ * Build a struct representing the given message reference
*
- * @param object $headers rcube_message_header instance holding the message headers
+ * @param object|string $uri_or_headers rcube_message_header instance holding the message headers
+ * or an URI from a stored link referencing a mail message.
* @param string $folder IMAP folder the message resides in
*
- * @return string An URI referencing the given IMAP message
+ * @return array An struct referencing the given IMAP message
*/
- public function get_message_uri($headers, $folder)
+ public function get_message_reference($uri_or_headers, $folder = null)
{
// to be implemented by the derived classes
return false;
diff --git a/plugins/tasklist/tasklist.php b/plugins/tasklist/tasklist.php
index d65507e..b260714 100644
--- a/plugins/tasklist/tasklist.php
+++ b/plugins/tasklist/tasklist.php
@@ -1099,8 +1099,8 @@ class tasklist extends rcube_plugin
// convert link URIs references into structs
if (array_key_exists('links', $rec)) {
foreach ((array)$rec['links'] as $i => $link) {
- if (strpos($link, 'imap://') === 0) {
- $rec['links'][$i] = $this->get_message_reference($link);
+ if (strpos($link, 'imap://') === 0 && ($msgref = $this->driver->get_message_reference($link))) {
+ $rec['links'][$i] = $msgref;
}
}
}
@@ -1395,8 +1395,8 @@ class tasklist extends rcube_plugin
$this->load_driver();
// add a reference to the email message
- if ($msguri = $this->driver->get_message_uri($message->headers, $mbox)) {
- $task['links'] = array($this->get_message_reference($msguri));
+ if ($msgref = $this->driver->get_message_reference($message->headers, $mbox)) {
+ $task['links'] = array($msgref);
}
// copy mail attachments to task
else if ($message->attachments && $this->driver->attachments) {
@@ -1603,45 +1603,6 @@ class tasklist extends rcube_plugin
}
/**
- * Resolve the email message reference from the given URI
- */
- public function get_message_reference($uri)
- {
- if (strpos($uri, 'imap:///') === 0) {
- $url = parse_url(substr($uri, 8));
- parse_str($url['query'], $params);
-
- $path = explode('/', $url['path']);
- $uid = array_pop($path);
- $folder = join('/', array_map('rawurldecode', $path));
- }
-
- if ($folder && $uid) {
- // TODO: check if folder/uid still references an existing message
- // TODO: validate message or resovle the new URI using the message-id parameter
-
- $linkref = array(
- 'folder' => $folder,
- 'uid' => $uid,
- 'subject' => $params['subject'],
- 'uri' => $uri,
- 'mailurl' => $this->rc->url(array(
- 'task' => 'mail',
- 'action' => 'show',
- 'mbox' => $folder,
- 'uid' => $uid,
- 'rel' => 'task',
- ))
- );
- }
- else {
- $linkref = array();
- }
-
- return $linkref;
- }
-
- /**
* Import the full payload from a mail message attachment
*/
public function mail_import_attachment()
More information about the commits
mailing list