From de0c3bdcd4167d2cdcec1f5281896912d767418f Mon Sep 17 00:00:00 2001 From: Ralf Becker Date: Tue, 31 Aug 2010 10:16:57 +0000 Subject: [PATCH] rest to implement support for different mailbox names types / mail_login_types --- .../inc/class.emailadmin_smtp_ldap.inc.php | 20 +++++++++----- emailadmin/inc/class.emailadmin_ui.inc.php | 4 +++ setup/inc/class.setup_cmd_config.inc.php | 1 + setup/inc/class.setup_cmd_ldap.inc.php | 27 ++++++------------- setup/inc/hook_config.inc.php | 26 ++++++++++++++++++ setup/templates/default/config.tpl | 6 +---- 6 files changed, 54 insertions(+), 30 deletions(-) diff --git a/emailadmin/inc/class.emailadmin_smtp_ldap.inc.php b/emailadmin/inc/class.emailadmin_smtp_ldap.inc.php index b43570bebf..1efc82807f 100644 --- a/emailadmin/inc/class.emailadmin_smtp_ldap.inc.php +++ b/emailadmin/inc/class.emailadmin_smtp_ldap.inc.php @@ -423,6 +423,8 @@ class emailadmin_smtp_ldap extends defaultsmtp /** * Build mailbox address for given account and mail_addr_type * + * If $account is an array (with values for keys account_(id|lid|email), it does NOT call accounts class + * * @param int|array $account account_id or whole account array with values for keys * @param string $domain=null domain, default use $this->defaultDomain * @param string $mail_login_type=null standard(uid), vmailmgr(uid@domain), email or uidNumber, @@ -437,20 +439,26 @@ class emailadmin_smtp_ldap extends defaultsmtp switch($mail_login_type) { case 'email': - return is_array($account) ? $account['account_email'] : $GLOBALS['egw']->accounts->id2name($account,'account_email'); + $mbox = is_array($account) ? $account['account_email'] : $GLOBALS['egw']->accounts->id2name($account,'account_email'); + break; case 'uidNumber': if (is_array($account)) $account = $account['account_id']; - return 'u'.$account.'@'.$domain; + $mbox = 'u'.$account.'@'.$domain; + break; case 'standard': - if (is_array($account)) $account = $account['account_id']; - return $GLOBALS['egw']->accounts->id2name($account); + $mbox = is_array($account) ? $account['account_lid'] : $GLOBALS['egw']->accounts->id2name($account); + break; case 'vmailmgr': default: - if (is_array($account)) $account = $account['account_id']; - return $GLOBALS['egw']->accounts->id2name($account).'@'.$domain; + $mbox = is_array($account) ? $account['account_lid'] : $GLOBALS['egw']->accounts->id2name($account); + $mbox .= '@'.$domain; + break; } + $mbox = strtolower($mbox); + + return $mbox; } } diff --git a/emailadmin/inc/class.emailadmin_ui.inc.php b/emailadmin/inc/class.emailadmin_ui.inc.php index 17455799a0..93a03e6913 100644 --- a/emailadmin/inc/class.emailadmin_ui.inc.php +++ b/emailadmin/inc/class.emailadmin_ui.inc.php @@ -238,6 +238,10 @@ class emailadmin_ui extends emailadmin_bo 'admin' => lang('Username/Password defined by admin'), 'uidNumber' => lang('UserId@domain eg. u1234@domain'), ); + if (strpos($serverclass,'_') === false) + { + include_once(EGW_INCLUDE_ROOT.'/emailadmin/inc/class.'.$serverclass.'.inc.php'); + } if (!empty($serverclass) && stripos(constant($serverclass.'::CAPABILITIES'),'logintypeemail') !== false) { $returnval['email'] = lang('use Users eMail-Address (as seen in Useraccount)'); diff --git a/setup/inc/class.setup_cmd_config.inc.php b/setup/inc/class.setup_cmd_config.inc.php index ca7eff2629..d1c41f6304 100644 --- a/setup/inc/class.setup_cmd_config.inc.php +++ b/setup/inc/class.setup_cmd_config.inc.php @@ -141,6 +141,7 @@ class setup_cmd_config extends setup_cmd 'username (standard)' => 'standard', 'username@domain (virtual mail manager)' => 'vmailmgr', 'Username/Password defined by admin' => 'admin', + 'userId@domain eg. u123@domain' => 'uidNumber', 'email (Standard Maildomain should be set)' => 'email', ),'default'=>'standard'), ), diff --git a/setup/inc/class.setup_cmd_ldap.inc.php b/setup/inc/class.setup_cmd_ldap.inc.php index 93a6230feb..a18b9340db 100644 --- a/setup/inc/class.setup_cmd_ldap.inc.php +++ b/setup/inc/class.setup_cmd_ldap.inc.php @@ -512,7 +512,7 @@ class setup_cmd_ldap extends setup_cmd * * @param string $this->object_class='qmailUser' * @param string $this->mbox_attr='mailmessagestore' lowercase!!! - * @param string $this->mail_login_format='email' 'email', 'vmailmgr', 'standard' or 'uidNumber' + * @param string $this->mail_login_type='email' 'email', 'vmailmgr', 'standard' or 'uidNumber' * @return string with success message N entries modified * @throws egw_exception if dn not found, not listable or delete fails */ @@ -532,17 +532,7 @@ class setup_cmd_ldap extends setup_cmd } $object_class = $this->object_class ? $this->object_class : 'qmailUser'; $mbox_attr = $this->mbox_attr ? $this->mbox_attr : 'mailmessagestore'; - $mail_login_format = $this->mail_login_format ? $this->mail_login_format : 'email'; - - // translate EGroupware mail_login_format into ldap attribute names - switch($mail_login_format) - { - case 'email': $mbox_format = 'mail'; break; - case 'vmailmgr': $mbox_format = 'uid@domain'; break; - case 'standard': $mbox_format = 'uid'; break; - case 'uidNumber': $mbox_format = 'uuidnumber@domain'; break; // uu to get u123 - default: throw new egw_exception('Unknown mail_login_format "%1"!',$mail_login_format); - } + $mail_login_type = $this->mail_login_type ? $this->mail_login_type : 'email'; if (!($sr = ldap_search($this->test_ldap->ds,$this->ldap_base, 'objectClass='.$object_class,array('mail','uidNumber','uid',$mbox_attr))) || @@ -555,13 +545,12 @@ class setup_cmd_ldap extends setup_cmd { if ($n === 'count') continue; - $replace = array( - 'mail' => $entry['mail'][0], - 'uidnumber' => $entry['uidnumber'][0], - 'uid' => $entry['uid'][0], - 'domain' => $this->domain, - ); - $mbox = strtolower(str_replace(array_keys($replace),$replace,$mbox_format)); + $mbox = emailadmin_smtp_ldap::mailbox_addr(array( + 'account_id' => $entry['uidnumber'][0], + 'account_lid' => $entry['uid'][0], + 'account_email' => $entry['mail'][0], + ),$mail_login_type,$this->domain); + if ($mbox === $entry[$mbox_attr][0]) continue; // nothing to change if (!$this->test && !ldap_modify($this->test_ldap->ds,$entry['dn'],array( diff --git a/setup/inc/hook_config.inc.php b/setup/inc/hook_config.inc.php index 59f892e105..4c2321b2b0 100644 --- a/setup/inc/hook_config.inc.php +++ b/setup/inc/hook_config.inc.php @@ -230,3 +230,29 @@ function sql_passwdhashes($config) } return $out; } + +/** + * Make mail-login-types from emailadmin available to config template + * + * @param array $config + * @return string + */ +function mail_login_type($config) +{ + $types = emailadmin_ui::getIMAPLoginTypes('cyrusimap'); + unset($types['admin']); + + foreach($types as $value => $label) + { + if($config['mail_login_type'] == $value) + { + $selected = ' selected="selected"'; + } + else + { + $selected = ''; + } + $out .= '' . "\n"; + } + return $out; +} diff --git a/setup/templates/default/config.tpl b/setup/templates/default/config.tpl index f5af32b85f..79a3d0835e 100644 --- a/setup/templates/default/config.tpl +++ b/setup/templates/default/config.tpl @@ -176,11 +176,7 @@ {lang_Mail_server_login_type}: - +