Skip to content

Commit

Permalink
add %i macro to get domain from identity
Browse files Browse the repository at this point in the history
  • Loading branch information
johndoh committed May 6, 2017
1 parent cdc95ca commit 26cdc89
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 3 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
Roundcube Webmail GlobalAddressbook
===================================

* Add %i macro to get domain from default identity

Version 1.9 (2014-08-31, rc-1.0)
=================================================
* Replace globaladdressbook_readonly option with globaladdressbook_perms
Expand Down
1 change: 1 addition & 0 deletions config.inc.php.dist
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
// the name of the dummy user which holds the global address book, if the user does not exist it will be created
// the name can contain the following macros that will be expanded as follows:
// %d is replaced with the domain part of the username (if the username is an email address or default mail domain if not)
// %i is replaced with the domain part of the email address from the user's default identity
// %h is replaced with the imap host (from the session info)
// eg. to create one global address book per domain: global_addressbook@%d
$config['globaladdressbook_user'] = '[global_addressbook_user]';
Expand Down
22 changes: 19 additions & 3 deletions globaladdressbook.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,7 @@ public function init()
$this->load_config();
$this->add_texts('localization/');

$this->user_name = $rcmail->config->get('globaladdressbook_user', '[global_addressbook_user]');
$this->user_name = str_replace('%d', $rcmail->user->get_username('domain'), $this->user_name);
$this->user_name = str_replace('%h', $_SESSION['storage_host'], $this->user_name);
$this->user_name = globaladdressbook::parse_user($rcmail->config->get('globaladdressbook_user', '[global_addressbook_user]'));
$this->groups = $rcmail->config->get('globaladdressbook_groups', false);
$this->name = $this->gettext('globaladdressbook');
$this->_set_permissions();
Expand Down Expand Up @@ -120,6 +118,24 @@ public function check_known_senders($args)
return $args;
}

public static function parse_user($name)
{
$user = rcube::get_instance()->user;

// %h - IMAP host
$h = $_SESSION['storage_host'];
// %d - domain name after the '@' from username
$d = $user->get_username('domain');
// %i - domain name after the '@' from e-mail address of default identity
if (strpos($name, '%i') !== false) {
$user_ident = $user->list_emails(true);
list($local, $domain) = explode('@', $user_ident['email']);
$i = $domain;
}

return str_replace(array('%h', '%d', '%i'), array($h, $d, $i), $name);
}

private function _set_permissions()
{
$rcmail = rcube::get_instance();
Expand Down

0 comments on commit 26cdc89

Please sign in to comment.