From 26cdc89b577a5af92d04f1fb0d2c9e201bfd2def Mon Sep 17 00:00:00 2001 From: PhilW Date: Sat, 6 May 2017 07:15:45 +0100 Subject: [PATCH] add %i macro to get domain from identity --- CHANGELOG | 2 ++ config.inc.php.dist | 1 + globaladdressbook.php | 22 +++++++++++++++++++--- 3 files changed, 22 insertions(+), 3 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 18353c2..08e6f18 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -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 diff --git a/config.inc.php.dist b/config.inc.php.dist index 9269858..924df0a 100644 --- a/config.inc.php.dist +++ b/config.inc.php.dist @@ -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]'; diff --git a/globaladdressbook.php b/globaladdressbook.php index 12090e5..cf67444 100644 --- a/globaladdressbook.php +++ b/globaladdressbook.php @@ -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(); @@ -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();