Allow to provide the context for getting user emails (augmented by kolab_delegation)

This commit is contained in:
Thomas Bruederli 2015-01-21 16:58:09 +01:00
parent d6789046c6
commit d9f69d35c7
2 changed files with 28 additions and 16 deletions

View file

@ -743,6 +743,13 @@ class kolab_delegation_engine
{
$context = $this->delegator_context();
// try to derive context from the given user email
if (!$context && !empty($args['emails'])) {
if (($user = preg_replace('/@.+$/', '', $args['emails'][0])) && isset($_SESSION['delegators'][$user])) {
$context = $user;
}
}
// return delegator's addresses
if ($context) {
$args['emails'] = $_SESSION['delegators'][$context];

View file

@ -361,32 +361,37 @@ class libcalendaring extends rcube_plugin
}
/**
* Get a list of email addresses of the current user (from login and identities)
* Get a list of email addresses of the given user (from login and identities)
*
* @param string User Email (default to current user)
* @return array Email addresses related to the user
*/
public function get_user_emails()
public function get_user_emails($user = null)
{
static $emails;
static $_emails = array();
// return cached result
if (is_array($emails)) {
return $emails;
if (empty($user)) {
$user = $this->rc->user->get_username();
}
$emails = array();
// return cached result
if (is_array($_emails[$user])) {
return $_emails[$user];
}
$emails = array($user);
$plugin = $this->rc->plugins->exec_hook('calendar_user_emails', array('emails' => $emails));
$emails = array_map('strtolower', $plugin['emails']);
if ($plugin['abort']) {
return $emails;
// add all emails from the current user's identities
if (!$plugin['abort'] && ($user == $this->rc->user->get_username())) {
foreach ($this->rc->user->list_emails() as $identity) {
$emails[] = strtolower($identity['email']);
}
}
$emails[] = $this->rc->user->get_username();
foreach ($this->rc->user->list_emails() as $identity) {
$emails[] = strtolower($identity['email']);
}
$emails = array_unique($emails);
return $emails;
$_emails[$user] = array_unique($emails);
return $_emails[$user];
}
/**