Consolidate message reference handling functions into libkolab plugin (in preparation for #4161)
This commit is contained in:
parent
0dc0490ba0
commit
0a51ccd5a4
5 changed files with 54 additions and 109 deletions
|
@ -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;
|
||||
|
@ -1042,28 +1044,6 @@ class kolab_notes extends rcube_plugin
|
|||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
|
|
|
@ -355,24 +355,6 @@ class kolab_storage_config
|
|||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
*
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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) {
|
||||
|
@ -1602,45 +1602,6 @@ class tasklist extends rcube_plugin
|
|||
return $list ?: $first;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
|
|
Loading…
Add table
Reference in a new issue