From 15a38f87e0465da5fecd2486c8d85a708b562d1a Mon Sep 17 00:00:00 2001 From: Aleksander Machniak Date: Wed, 19 Jun 2019 10:59:46 +0000 Subject: [PATCH] Other user uid mapping for Chwala (Bifrost#T216238) ...also use format "Doe, Jane (jane.doe)" consistently everywhere. --- plugins/libkolab/lib/kolab_storage.php | 69 ++++++++++++++++++++++++-- plugins/libkolab/libkolab.php | 5 +- 2 files changed, 70 insertions(+), 4 deletions(-) diff --git a/plugins/libkolab/lib/kolab_storage.php b/plugins/libkolab/lib/kolab_storage.php index c72fb4b2..17041cbf 100644 --- a/plugins/libkolab/lib/kolab_storage.php +++ b/plugins/libkolab/lib/kolab_storage.php @@ -1713,15 +1713,78 @@ class kolab_storage if (!empty($user)) { if ($as_string) { foreach ($name_attr as $attr) { - if ($name = $user[$attr]) { - return $name; + if ($display = $user[$attr]) { + break; } } - return $user['displayname'] ?: $user['name']; + if (!$display) { + $display = $user['displayname'] ?: $user['name']; + } + + if ($display && $display != $folder_id) { + $display = "$display ($folder_id)"; + } + + return $display; } return $user; } } + + /** + * Chwala's 'folder_mod' hook handler for mapping other users folder names + */ + public static function folder_mod($args) + { + static $roots; + + if ($roots === null) { + self::setup(); + $roots = self::$imap->get_namespace('other'); + } + + // Note: We're working with UTF7-IMAP encoding here + + if ($args['dir'] == 'in') { + foreach ((array) $roots as $root) { + if (strpos($args['folder'], $root[0]) === 0) { + // remove root and explode folder + $delim = $root[1]; + $folder = explode($delim, substr($args['folder'], strlen($root[0]))); + // compare first (user) part with a regexp, it's supposed + // to look like this: "Doe, Jane (uid)", so we can extract the uid + // and replace the folder with it + if (preg_match('~^[^/]+ \(([^)]+)\)$~', $folder[0], $m)) { + $folder[0] = $m[1]; + $args['folder'] = $root[0] . implode($delim, $folder); + } + + break; + } + } + } + else { // dir == 'out' + foreach ((array) $roots as $root) { + if (strpos($args['folder'], $root[0]) === 0) { + // remove root and explode folder + $delim = $root[1]; + $folder = explode($delim, substr($args['folder'], strlen($root[0]))); + + // Replace uid with "Doe, Jane (uid)" + if ($user = self::folder_id2user($folder[0], true)) { + $user = str_replace($delim, '', $user); + $folder[0] = rcube_charset::convert($user, RCUBE_CHARSET, 'UTF7-IMAP'); + + $args['folder'] = $root[0] . implode($delim, $folder); + } + + break; + } + } + } + + return $args; + } } diff --git a/plugins/libkolab/libkolab.php b/plugins/libkolab/libkolab.php index 3aa6fbfb..8ad0838b 100644 --- a/plugins/libkolab/libkolab.php +++ b/plugins/libkolab/libkolab.php @@ -28,7 +28,7 @@ class libkolab extends rcube_plugin { static $http_requests = array(); - static $bonnie_api = false; + static $bonnie_api = false; /** * Required startup method of a Roundcube plugin @@ -46,6 +46,9 @@ class libkolab extends rcube_plugin $this->add_hook('storage_connect', array($this, 'storage_connect')); $this->add_hook('user_delete', array('kolab_storage', 'delete_user_folders')); + // For Chwala + $this->add_hook('folder_mod', array('kolab_storage', 'folder_mod')); + $rcmail = rcube::get_instance(); try { kolab_format::$timezone = new DateTimeZone($rcmail->config->get('timezone', 'GMT'));