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(); $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 // return delegator's addresses
if ($context) { if ($context) {
$args['emails'] = $_SESSION['delegators'][$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 (empty($user)) {
if (is_array($emails)) { $user = $this->rc->user->get_username();
return $emails;
} }
$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)); $plugin = $this->rc->plugins->exec_hook('calendar_user_emails', array('emails' => $emails));
$emails = array_map('strtolower', $plugin['emails']); $emails = array_map('strtolower', $plugin['emails']);
if ($plugin['abort']) { // add all emails from the current user's identities
return $emails; if (!$plugin['abort'] && ($user == $this->rc->user->get_username())) {
}
$emails[] = $this->rc->user->get_username();
foreach ($this->rc->user->list_emails() as $identity) { foreach ($this->rc->user->list_emails() as $identity) {
$emails[] = strtolower($identity['email']); $emails[] = strtolower($identity['email']);
} }
}
$emails = array_unique($emails); $_emails[$user] = array_unique($emails);
return $emails; return $_emails[$user];
} }
/** /**