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(
|
$this->rc->output->set_env('kolab_notes_template', array(
|
||||||
'_from_mail' => true,
|
'_from_mail' => true,
|
||||||
'title' => $message->get('subject'),
|
'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
|
// resolve message links
|
||||||
$me = $this;
|
$note['links'] = array_map(function($link) {
|
||||||
$note['links'] = array_map(function($link) use ($me, $resolve) {
|
return kolab_storage_config::get_message_reference($link, 'note') ?: array('uri' => $link);
|
||||||
return $me->get_message_reference($link, $resolve) ?: array('uri' => $link);
|
|
||||||
}, $this->get_links($note['uid']));
|
}, $this->get_links($note['uid']));
|
||||||
|
|
||||||
return $note;
|
return $note;
|
||||||
|
@ -1042,28 +1044,6 @@ class kolab_notes extends rcube_plugin
|
||||||
return $result;
|
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
|
* Update note tags
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -355,24 +355,6 @@ class kolab_storage_config
|
||||||
return false;
|
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
|
* Build array of member URIs from set of messages
|
||||||
*
|
*
|
||||||
|
@ -855,4 +837,30 @@ class kolab_storage_config
|
||||||
|
|
||||||
return self::build_member_url($params);
|
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)
|
private function get_links($uid)
|
||||||
{
|
{
|
||||||
$config = kolab_storage_config::get_instance();
|
$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();
|
$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();
|
$config = kolab_storage_config::get_instance();
|
||||||
$remove = array_diff($config->get_object_links($uid), $links);
|
$remove = array_diff($config->get_object_links($uid), $links);
|
||||||
return $config->save_object_links($uid, $links, $remove);
|
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);
|
if (is_object($uri_or_headers)) {
|
||||||
return kolab_storage_config::local_message_uri($uri);
|
$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) { }
|
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
|
* @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
|
// to be implemented by the derived classes
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -1099,8 +1099,8 @@ class tasklist extends rcube_plugin
|
||||||
// convert link URIs references into structs
|
// convert link URIs references into structs
|
||||||
if (array_key_exists('links', $rec)) {
|
if (array_key_exists('links', $rec)) {
|
||||||
foreach ((array)$rec['links'] as $i => $link) {
|
foreach ((array)$rec['links'] as $i => $link) {
|
||||||
if (strpos($link, 'imap://') === 0) {
|
if (strpos($link, 'imap://') === 0 && ($msgref = $this->driver->get_message_reference($link))) {
|
||||||
$rec['links'][$i] = $this->get_message_reference($link);
|
$rec['links'][$i] = $msgref;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1395,8 +1395,8 @@ class tasklist extends rcube_plugin
|
||||||
$this->load_driver();
|
$this->load_driver();
|
||||||
|
|
||||||
// add a reference to the email message
|
// add a reference to the email message
|
||||||
if ($msguri = $this->driver->get_message_uri($message->headers, $mbox)) {
|
if ($msgref = $this->driver->get_message_reference($message->headers, $mbox)) {
|
||||||
$task['links'] = array($this->get_message_reference($msguri));
|
$task['links'] = array($msgref);
|
||||||
}
|
}
|
||||||
// copy mail attachments to task
|
// copy mail attachments to task
|
||||||
else if ($message->attachments && $this->driver->attachments) {
|
else if ($message->attachments && $this->driver->attachments) {
|
||||||
|
@ -1602,45 +1602,6 @@ class tasklist extends rcube_plugin
|
||||||
return $list ?: $first;
|
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
|
* Import the full payload from a mail message attachment
|
||||||
*/
|
*/
|
||||||
|
|
Loading…
Add table
Reference in a new issue