From fd5489d4587a047cef29a1c501451261c14463a1 Mon Sep 17 00:00:00 2001 From: Ralf Becker Date: Thu, 19 Aug 2010 18:13:53 +0000 Subject: [PATCH] - moved plugin capabilities from emailadmin_bo to plugins - moved sieve support and configuration from cyrusimap to defaultimap, as there are other imap server supporting Sieve --- emailadmin/inc/class.cyrusimap.inc.php | 62 +- emailadmin/inc/class.dbmaildbmailuser.inc.php | 308 +-- emailadmin/inc/class.dbmailqmailuser.inc.php | 263 +-- emailadmin/inc/class.defaultimap.inc.php | 1165 ++++++----- emailadmin/inc/class.defaultsmtp.inc.php | 5 + emailadmin/inc/class.emailadmin_bo.inc.php | 1791 ++++++++--------- emailadmin/inc/class.emailadmin_ui.inc.php | 1309 ++++-------- .../inc/class.postfixdbmailuser.inc.php | 5 + emailadmin/inc/class.postfixldap.inc.php | 5 + emailadmin/inc/class.smtpplesk.inc.php | 5 + 10 files changed, 2205 insertions(+), 2713 deletions(-) diff --git a/emailadmin/inc/class.cyrusimap.inc.php b/emailadmin/inc/class.cyrusimap.inc.php index 0ad7e89a86..5a4d8cd215 100644 --- a/emailadmin/inc/class.cyrusimap.inc.php +++ b/emailadmin/inc/class.cyrusimap.inc.php @@ -1,6 +1,6 @@ updateAccount($_hookValues); @@ -167,50 +163,4 @@ class cyrusimap extends defaultimap } $this->disconnect(); } - - /** - * Instance of emailadmin_sieve - * - * @var emailadmin_sieve - */ - private $sieve; - - public $scriptName; - public $error; - - //public $error; - - /** - * Proxy former felamimail bosieve methods to internal emailadmin_sieve instance - * - * @param string $name - * @param array $params - */ - public function __call($name,array $params=null) - { - switch($name) - { - case 'installScript': - case 'getScript': - case 'setActive': - case 'setEmailNotification': - case 'getEmailNotification': - case 'setRules': - case 'getRules': - case 'retrieveRules': - case 'getVacation': - case 'setVacation': - case 'setVacationUser': - if (is_null($this->sieve)) - { - $this->sieve = new emailadmin_sieve($this); - $this->scriptName =& $this->sieve->scriptName; - $this->error =& $this->sieve->error; - } - $ret = call_user_func_array(array($this->sieve,$name),$params); - error_log(__CLASS__.'->'.$name.'('.array2string($params).') returns '.array2string($ret)); - return $ret; - } - throw new egw_exception_wrong_parameter("No method '$name' implemented!"); - } } diff --git a/emailadmin/inc/class.dbmaildbmailuser.inc.php b/emailadmin/inc/class.dbmaildbmailuser.inc.php index 68333d8c77..fcb80143d3 100755 --- a/emailadmin/inc/class.dbmaildbmailuser.inc.php +++ b/emailadmin/inc/class.dbmaildbmailuser.inc.php @@ -1,180 +1,182 @@ + * @author Klaus Leithoff + * @author Lars Kneschke + * @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License + * @version $Id$ + */ - include_once(EGW_SERVER_ROOT."/emailadmin/inc/class.defaultimap.inc.php"); +include_once(EGW_SERVER_ROOT."/emailadmin/inc/class.defaultimap.inc.php"); + +/** + * Support for DBMail IMAP with qmailUser LDAP schema + * + * @todo base this class on dbmailqmailuser or the other way around + */ +class dbmaildbmailuser extends defaultimap +{ + /** + * Capabilities of this class (pipe-separated): default, sieve, admin, logintypeemail + */ + const CAPABILITIES = 'default|sieve'; - class dbmaildbmailuser extends defaultimap { - var $enableSieve = false; + function addAccount($_hookValues) { + return $this->updateAccount($_hookValues); + } + + #function deleteAccount($_hookValues) { + #} + function getUserData($_username) { + $userData = array(); - var $sieveHost; + $ds = $GLOBALS['egw']->ldap->ldapConnect( + $GLOBALS['egw_info']['server']['ldap_host'], + $GLOBALS['egw_info']['server']['ldap_root_dn'], + $GLOBALS['egw_info']['server']['ldap_root_pw'] + ); - var $sievePort; - - function addAccount($_hookValues) { - return $this->updateAccount($_hookValues); - } - - #function deleteAccount($_hookValues) { - #} - function getUserData($_username) { - $userData = array(); - - $ds = $GLOBALS['egw']->ldap->ldapConnect( - $GLOBALS['egw_info']['server']['ldap_host'], - $GLOBALS['egw_info']['server']['ldap_root_dn'], - $GLOBALS['egw_info']['server']['ldap_root_pw'] - ); - - if(!is_resource($ds)) { - return false; - } - - $filter = '(&(objectclass=posixaccount)(uid='. $_username .')(dbmailGID='. sprintf("%u", crc32($GLOBALS['egw_info']['server']['install_id'])) .'))'; - $justthese = array('dn', 'objectclass', 'mailQuota'); - if($sri = ldap_search($ds, $GLOBALS['egw_info']['server']['ldap_context'], $filter, $justthese)) { - - if($info = ldap_get_entries($ds, $sri)) { - if(isset($info[0]['mailquota'][0])) { - $userData['quotaLimit'] = $info[0]['mailquota'][0] / 1048576; - } - } - } - return $userData; + if(!is_resource($ds)) { + return false; } - function updateAccount($_hookValues) { - if(!$uidnumber = (int)$_hookValues['account_id']) { - return false; - } - - $ds = $GLOBALS['egw']->ldap->ldapConnect( - $GLOBALS['egw_info']['server']['ldap_host'], - $GLOBALS['egw_info']['server']['ldap_root_dn'], - $GLOBALS['egw_info']['server']['ldap_root_pw'] - ); - - if(!is_resource($ds)) { - return false; - } - - $filter = '(&(objectclass=posixaccount)(uidnumber='. $uidnumber .'))'; - $justthese = array('dn', 'objectclass', 'dbmailUID', 'dbmailGID', 'mail'); - $sri = ldap_search($ds, $GLOBALS['egw_info']['server']['ldap_context'], $filter, $justthese); + $filter = '(&(objectclass=posixaccount)(uid='. $_username .')(dbmailGID='. sprintf("%u", crc32($GLOBALS['egw_info']['server']['install_id'])) .'))'; + $justthese = array('dn', 'objectclass', 'mailQuota'); + if($sri = ldap_search($ds, $GLOBALS['egw_info']['server']['ldap_context'], $filter, $justthese)) { if($info = ldap_get_entries($ds, $sri)) { - if((!in_array('dbmailuser',$info[0]['objectclass']) && !in_array('dbmailUser',$info[0]['objectclass'])) && $info[0]['mail']) { - $newData['objectclass'] = $info[0]['objectclass']; - unset($newData['objectclass']['count']); - $newData['objectclass'][] = 'dbmailuser'; - sort($newData['objectclass']); - $newData['dbmailGID'] = sprintf("%u", crc32($GLOBALS['egw_info']['server']['install_id'])); - $newData['dbmailUID'] = (!empty($this->domainName)) ? $_hookValues['account_lid'] .'@'. $this->domainName : $_hookValues['account_lid']; + if(isset($info[0]['mailquota'][0])) { + $userData['quotaLimit'] = $info[0]['mailquota'][0] / 1048576; + } + } + } + return $userData; + } + + function updateAccount($_hookValues) { + if(!$uidnumber = (int)$_hookValues['account_id']) { + return false; + } + + $ds = $GLOBALS['egw']->ldap->ldapConnect( + $GLOBALS['egw_info']['server']['ldap_host'], + $GLOBALS['egw_info']['server']['ldap_root_dn'], + $GLOBALS['egw_info']['server']['ldap_root_pw'] + ); + + if(!is_resource($ds)) { + return false; + } + + $filter = '(&(objectclass=posixaccount)(uidnumber='. $uidnumber .'))'; + $justthese = array('dn', 'objectclass', 'dbmailUID', 'dbmailGID', 'mail'); + $sri = ldap_search($ds, $GLOBALS['egw_info']['server']['ldap_context'], $filter, $justthese); + + if($info = ldap_get_entries($ds, $sri)) { + if((!in_array('dbmailuser',$info[0]['objectclass']) && !in_array('dbmailUser',$info[0]['objectclass'])) && $info[0]['mail']) { + $newData['objectclass'] = $info[0]['objectclass']; + unset($newData['objectclass']['count']); + $newData['objectclass'][] = 'dbmailuser'; + sort($newData['objectclass']); + $newData['dbmailGID'] = sprintf("%u", crc32($GLOBALS['egw_info']['server']['install_id'])); + $newData['dbmailUID'] = (!empty($this->domainName)) ? $_hookValues['account_lid'] .'@'. $this->domainName : $_hookValues['account_lid']; + + if(!ldap_modify($ds, $info[0]['dn'], $newData)) { + #print ldap_error($ds); + } + + return true; + } else { + $newData = array(); + $newData['dbmailUID'] = (!empty($this->domainName)) ? $_hookValues['account_lid'] .'@'. $this->domainName : $_hookValues['account_lid']; + $newData['dbmailGID'] = sprintf("%u", crc32($GLOBALS['egw_info']['server']['install_id'])); + if(!ldap_modify($ds, $info[0]['dn'], $newData)) { + print ldap_error($ds); + _debug_array($newData); + exit; + #return false; + } + } + } + + return false; + } + + function setUserData($_username, $_quota) { + $ds = $GLOBALS['egw']->ldap->ldapConnect( + $GLOBALS['egw_info']['server']['ldap_host'], + $GLOBALS['egw_info']['server']['ldap_root_dn'], + $GLOBALS['egw_info']['server']['ldap_root_pw'] + ); + + if(!is_resource($ds)) { + return false; + } + + $filter = '(&(objectclass=posixaccount)(uid='. $_username .'))'; + $justthese = array('dn', 'objectclass', 'dbmailGID', 'dbmailUID', 'mail'); + $sri = ldap_search($ds, $GLOBALS['egw_info']['server']['ldap_context'], $filter, $justthese); + + if($info = ldap_get_entries($ds, $sri)) { + $validLDAPConfig = false; + if(in_array('dbmailuser',$info[0]['objectclass']) || in_array('dbmailUser',$info[0]['objectclass'])) { + $validLDAPConfig = true; + } + + if(!in_array('dbmailuser',$info[0]['objectclass']) && !in_array('dbmailUser',$info[0]['objectclass']) && $info[0]['mail']) { + $newData['objectclass'] = $info[0]['objectclass']; + unset($newData['objectclass']['count']); + $newData['objectclass'][] = 'dbmailUser'; + sort($newData['objectclass']); + $newData['dbmailGID'] = sprintf("%u", crc32($GLOBALS['egw_info']['server']['install_id'])); + $newData['dbmailUID'] = (!empty($this->domainName)) ? $_username .'@'. $this->domainName : $_username; + + if(ldap_modify($ds, $info[0]['dn'], $newData)) { + $validLDAPConfig = true; + } + } else { + if ((in_array('dbmailuser',$info[0]['objectclass']) || in_array('dbmailUser',$info[0]['objectclass'])) && !$info[0]['dbmailuid']) { + $newData = array(); + $newData['dbmailUID'] = (!empty($this->domainName)) ? $_username .'@'. $this->domainName : $_username; + if(!ldap_modify($ds, $info[0]['dn'], $newData)) { #print ldap_error($ds); + #return false; } - - return true; - } else { + } + + if ((in_array('dbmailuser',$info[0]['objectclass']) || in_array('dbmailUser',$info[0]['objectclass'])) && !$info[0]['dbmailgid']) { $newData = array(); - $newData['dbmailUID'] = (!empty($this->domainName)) ? $_hookValues['account_lid'] .'@'. $this->domainName : $_hookValues['account_lid']; $newData['dbmailGID'] = sprintf("%u", crc32($GLOBALS['egw_info']['server']['install_id'])); - + if(!ldap_modify($ds, $info[0]['dn'], $newData)) { - print ldap_error($ds); - _debug_array($newData); - exit; + #print ldap_error($ds); #return false; } } } - - return false; - } - - function setUserData($_username, $_quota) { - $ds = $GLOBALS['egw']->ldap->ldapConnect( - $GLOBALS['egw_info']['server']['ldap_host'], - $GLOBALS['egw_info']['server']['ldap_root_dn'], - $GLOBALS['egw_info']['server']['ldap_root_pw'] - ); + + if($validLDAPConfig) { + $newData = array(); - if(!is_resource($ds)) { - return false; - } - - $filter = '(&(objectclass=posixaccount)(uid='. $_username .'))'; - $justthese = array('dn', 'objectclass', 'dbmailGID', 'dbmailUID', 'mail'); - $sri = ldap_search($ds, $GLOBALS['egw_info']['server']['ldap_context'], $filter, $justthese); - - if($info = ldap_get_entries($ds, $sri)) { - $validLDAPConfig = false; - if(in_array('dbmailuser',$info[0]['objectclass']) || in_array('dbmailUser',$info[0]['objectclass'])) { - $validLDAPConfig = true; - } - - if(!in_array('dbmailuser',$info[0]['objectclass']) && !in_array('dbmailUser',$info[0]['objectclass']) && $info[0]['mail']) { - $newData['objectclass'] = $info[0]['objectclass']; - unset($newData['objectclass']['count']); - $newData['objectclass'][] = 'dbmailUser'; - sort($newData['objectclass']); - $newData['dbmailGID'] = sprintf("%u", crc32($GLOBALS['egw_info']['server']['install_id'])); - $newData['dbmailUID'] = (!empty($this->domainName)) ? $_username .'@'. $this->domainName : $_username; - - if(ldap_modify($ds, $info[0]['dn'], $newData)) { - $validLDAPConfig = true; - } + if((int)$_quota >= 0) { + $newData['mailQuota'] = (int)$_quota * 1048576; } else { - if ((in_array('dbmailuser',$info[0]['objectclass']) || in_array('dbmailUser',$info[0]['objectclass'])) && !$info[0]['dbmailuid']) { - $newData = array(); - $newData['dbmailUID'] = (!empty($this->domainName)) ? $_username .'@'. $this->domainName : $_username; - - if(!ldap_modify($ds, $info[0]['dn'], $newData)) { - #print ldap_error($ds); - #return false; - } - } - - if ((in_array('dbmailuser',$info[0]['objectclass']) || in_array('dbmailUser',$info[0]['objectclass'])) && !$info[0]['dbmailgid']) { - $newData = array(); - $newData['dbmailGID'] = sprintf("%u", crc32($GLOBALS['egw_info']['server']['install_id'])); - - if(!ldap_modify($ds, $info[0]['dn'], $newData)) { - #print ldap_error($ds); - #return false; - } - } + $newData['mailQuota'] = array(); } - - if($validLDAPConfig) { - $newData = array(); - - if((int)$_quota >= 0) { - $newData['mailQuota'] = (int)$_quota * 1048576; - } else { - $newData['mailQuota'] = array(); - } - - if(!ldap_modify($ds, $info[0]['dn'], $newData)) { - #print ldap_error($ds); - return false; - } + + if(!ldap_modify($ds, $info[0]['dn'], $newData)) { + #print ldap_error($ds); + return false; } - return true; } - - return false; + return true; } - + return false; } -?> +} diff --git a/emailadmin/inc/class.dbmailqmailuser.inc.php b/emailadmin/inc/class.dbmailqmailuser.inc.php index e2150ad13d..1933778a2a 100644 --- a/emailadmin/inc/class.dbmailqmailuser.inc.php +++ b/emailadmin/inc/class.dbmailqmailuser.inc.php @@ -1,92 +1,137 @@ + * @author Klaus Leithoff + * @author Lars Kneschke + * @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License + * @version $Id$ + */ - include_once(EGW_SERVER_ROOT."/emailadmin/inc/class.defaultimap.inc.php"); +include_once(EGW_SERVER_ROOT."/emailadmin/inc/class.defaultimap.inc.php"); + +/** + * Support for DBMail IMAP with qmailUser LDAP schema + * + * @todo base this class on dbmaildbmailuser or the other way around + */ +class dbmailqmailuser extends defaultimap +{ + /** + * Capabilities of this class (pipe-separated): default, sieve, admin, logintypeemail + */ + const CAPABILITIES = 'default|sieve'; - class dbmailqmailuser extends defaultimap { - var $enableSieve = false; + function addAccount($_hookValues) { + return $this->updateAccount($_hookValues); + } + + #function deleteAccount($_hookValues) { + #} + function getUserData($_username) { + $userData = array(); - var $sieveHost; + $ds = $GLOBALS['egw']->ldap->ldapConnect( + $GLOBALS['egw_info']['server']['ldap_host'], + $GLOBALS['egw_info']['server']['ldap_root_dn'], + $GLOBALS['egw_info']['server']['ldap_root_pw'] + ); - var $sievePort; - - function addAccount($_hookValues) { - return $this->updateAccount($_hookValues); + if(!is_resource($ds)) { + return false; } - - #function deleteAccount($_hookValues) { - #} - function getUserData($_username) { - $userData = array(); - - $ds = $GLOBALS['egw']->ldap->ldapConnect( - $GLOBALS['egw_info']['server']['ldap_host'], - $GLOBALS['egw_info']['server']['ldap_root_dn'], - $GLOBALS['egw_info']['server']['ldap_root_pw'] - ); - - if(!is_resource($ds)) { - return false; - } - $filter = '(&(objectclass=posixaccount)(uid='. $_username .')(qmailGID='. sprintf("%u", crc32($GLOBALS['egw_info']['server']['install_id'])) .'))'; - $justthese = array('dn', 'objectclass', 'mailQuota'); - if($sri = ldap_search($ds, $GLOBALS['egw_info']['server']['ldap_context'], $filter, $justthese)) { + $filter = '(&(objectclass=posixaccount)(uid='. $_username .')(qmailGID='. sprintf("%u", crc32($GLOBALS['egw_info']['server']['install_id'])) .'))'; + $justthese = array('dn', 'objectclass', 'mailQuota'); + if($sri = ldap_search($ds, $GLOBALS['egw_info']['server']['ldap_context'], $filter, $justthese)) { - if($info = ldap_get_entries($ds, $sri)) { - if(isset($info[0]['mailquota'][0])) { - $userData['quotaLimit'] = $info[0]['mailquota'][0] / 1048576; - } + if($info = ldap_get_entries($ds, $sri)) { + if(isset($info[0]['mailquota'][0])) { + $userData['quotaLimit'] = $info[0]['mailquota'][0] / 1048576; } } - return $userData; + } + return $userData; + } + + function updateAccount($_hookValues) { + if(!$uidnumber = (int)$_hookValues['account_id']) { + return false; + } + + $ds = $GLOBALS['egw']->ldap->ldapConnect( + $GLOBALS['egw_info']['server']['ldap_host'], + $GLOBALS['egw_info']['server']['ldap_root_dn'], + $GLOBALS['egw_info']['server']['ldap_root_pw'] + ); + + if(!is_resource($ds)) { + return false; } - function updateAccount($_hookValues) { - if(!$uidnumber = (int)$_hookValues['account_id']) { - return false; - } - - $ds = $GLOBALS['egw']->ldap->ldapConnect( - $GLOBALS['egw_info']['server']['ldap_host'], - $GLOBALS['egw_info']['server']['ldap_root_dn'], - $GLOBALS['egw_info']['server']['ldap_root_pw'] - ); - - if(!is_resource($ds)) { - return false; - } + $filter = '(&(objectclass=posixaccount)(uidnumber='. $uidnumber .'))'; + $justthese = array('dn', 'objectclass', 'qmailUID', 'qmailGID', 'mail'); + $sri = ldap_search($ds, $GLOBALS['egw_info']['server']['ldap_context'], $filter, $justthese); + + if($info = ldap_get_entries($ds, $sri)) { + if(!in_array('qmailuser',$info[0]['objectclass']) && $info[0]['email']) { + $newData['objectclass'] = $info[0]['objectclass']; + unset($newData['objectclass']['count']); + $newData['objectclass'][] = 'qmailuser'; + sort($newData['objectclass']); + $newData['qmailGID'] = sprintf("%u", crc32($GLOBALS['egw_info']['server']['install_id'])); + #$newData['qmailUID'] = (!empty($this->domainName)) ? $_username .'@'. $this->domainName : $_username; + + ldap_modify($ds, $info[0]['dn'], $newData); + + return true; + } else { + $newData = array(); + $newData['qmailGID'] = sprintf("%u", crc32($GLOBALS['egw_info']['server']['install_id'])); + #$newData['qmailUID'] = (!empty($this->domainName)) ? $_username .'@'. $this->domainName : $_username; - $filter = '(&(objectclass=posixaccount)(uidnumber='. $uidnumber .'))'; - $justthese = array('dn', 'objectclass', 'qmailUID', 'qmailGID', 'mail'); - $sri = ldap_search($ds, $GLOBALS['egw_info']['server']['ldap_context'], $filter, $justthese); - - if($info = ldap_get_entries($ds, $sri)) { - if(!in_array('qmailuser',$info[0]['objectclass']) && $info[0]['email']) { - $newData['objectclass'] = $info[0]['objectclass']; - unset($newData['objectclass']['count']); - $newData['objectclass'][] = 'qmailuser'; - sort($newData['objectclass']); - $newData['qmailGID'] = sprintf("%u", crc32($GLOBALS['egw_info']['server']['install_id'])); - #$newData['qmailUID'] = (!empty($this->domainName)) ? $_username .'@'. $this->domainName : $_username; - - ldap_modify($ds, $info[0]['dn'], $newData); - - return true; - } else { + if(!ldap_modify($ds, $info[0]['dn'], $newData)) { + #print ldap_error($ds); + #return false; + } + } + } + + return false; + } + + function setUserData($_username, $_quota) { + $ds = $GLOBALS['egw']->ldap->ldapConnect( + $GLOBALS['egw_info']['server']['ldap_host'], + $GLOBALS['egw_info']['server']['ldap_root_dn'], + $GLOBALS['egw_info']['server']['ldap_root_pw'] + ); + + if(!is_resource($ds)) { + return false; + } + + $filter = '(&(objectclass=posixaccount)(uid='. $_username .'))'; + $justthese = array('dn', 'objectclass', 'qmailGID', 'mail'); + $sri = ldap_search($ds, $GLOBALS['egw_info']['server']['ldap_context'], $filter, $justthese); + + if($info = ldap_get_entries($ds, $sri)) { + #_debug_array($info); + if(!in_array('qmailuser',$info[0]['objectclass']) && $info[0]['email']) { + $newData['objectclass'] = $info[0]['objectclass']; + unset($newData['objectclass']['count']); + $newData['objectclass'][] = 'qmailuser'; + sort($newData['objectclass']); + $newData['qmailGID'] = sprintf("%u", crc32($GLOBALS['egw_info']['server']['install_id'])); + + ldap_modify($ds, $info[0]['dn'], $newData); + } else { + if (in_array('qmailuser',$info[0]['objectclass']) && !$info[0]['qmailgid']) { $newData = array(); $newData['qmailGID'] = sprintf("%u", crc32($GLOBALS['egw_info']['server']['install_id'])); - #$newData['qmailUID'] = (!empty($this->domainName)) ? $_username .'@'. $this->domainName : $_username; if(!ldap_modify($ds, $info[0]['dn'], $newData)) { #print ldap_error($ds); @@ -94,65 +139,23 @@ } } } - - return false; - } - - function setUserData($_username, $_quota) { - $ds = $GLOBALS['egw']->ldap->ldapConnect( - $GLOBALS['egw_info']['server']['ldap_host'], - $GLOBALS['egw_info']['server']['ldap_root_dn'], - $GLOBALS['egw_info']['server']['ldap_root_pw'] - ); + + $newData = array(); - if(!is_resource($ds)) { + if((int)$_quota >= 0) { + $newData['mailQuota'] = (int)$_quota * 1048576; + } else { + $newData['mailQuota'] = array(); + } + + if(!ldap_modify($ds, $info[0]['dn'], $newData)) { + #print ldap_error($ds); return false; } - - $filter = '(&(objectclass=posixaccount)(uid='. $_username .'))'; - $justthese = array('dn', 'objectclass', 'qmailGID', 'mail'); - $sri = ldap_search($ds, $GLOBALS['egw_info']['server']['ldap_context'], $filter, $justthese); - - if($info = ldap_get_entries($ds, $sri)) { - #_debug_array($info); - if(!in_array('qmailuser',$info[0]['objectclass']) && $info[0]['email']) { - $newData['objectclass'] = $info[0]['objectclass']; - unset($newData['objectclass']['count']); - $newData['objectclass'][] = 'qmailuser'; - sort($newData['objectclass']); - $newData['qmailGID'] = sprintf("%u", crc32($GLOBALS['egw_info']['server']['install_id'])); - - ldap_modify($ds, $info[0]['dn'], $newData); - } else { - if (in_array('qmailuser',$info[0]['objectclass']) && !$info[0]['qmailgid']) { - $newData = array(); - $newData['qmailGID'] = sprintf("%u", crc32($GLOBALS['egw_info']['server']['install_id'])); - - if(!ldap_modify($ds, $info[0]['dn'], $newData)) { - #print ldap_error($ds); - #return false; - } - } - } - - $newData = array(); - - if((int)$_quota >= 0) { - $newData['mailQuota'] = (int)$_quota * 1048576; - } else { - $newData['mailQuota'] = array(); - } - - if(!ldap_modify($ds, $info[0]['dn'], $newData)) { - #print ldap_error($ds); - return false; - } - - return true; - } - - return false; + + return true; } + return false; } -?> +} diff --git a/emailadmin/inc/class.defaultimap.inc.php b/emailadmin/inc/class.defaultimap.inc.php index 6b0ac2ea52..7cbbe44371 100644 --- a/emailadmin/inc/class.defaultimap.inc.php +++ b/emailadmin/inc/class.defaultimap.inc.php @@ -1,559 +1,632 @@ + * @author Klaus Leithoff + * @author Lars Kneschke + * @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License + * @version $Id$ + */ - require_once 'Net/IMAP.php'; +require_once 'Net/IMAP.php'; - define('IMAP_NAMESPACE_PERSONAL', 'personal'); - define('IMAP_NAMESPACE_OTHERS' , 'others'); - define('IMAP_NAMESPACE_SHARED' , 'shared'); - define('IMAP_NAMESPACE_ALL' , 'all'); +define('IMAP_NAMESPACE_PERSONAL', 'personal'); +define('IMAP_NAMESPACE_OTHERS' , 'others'); +define('IMAP_NAMESPACE_SHARED' , 'shared'); +define('IMAP_NAMESPACE_ALL' , 'all'); + +/** + * This class holds all information about the imap connection. + * This is the base class for all other imap classes. + * + * Also proxies Sieve calls to emailadmin_sieve (eg. it behaves like the former felamimail bosieve), + * to allow IMAP plugins to also manage Sieve connection. + */ +class defaultimap extends Net_IMAP +{ + /** + * Capabilities of this class (pipe-separated): default, sieve, admin, logintypeemail + */ + const CAPABILITIES = 'default|sieve'; /** - * This class holds all information about the imap connection. - * This is the base class for all other imap classes. + * the password to be used for admin connections * + * @var string */ - class defaultimap extends Net_IMAP - { - /** - * the password to be used for admin connections - * - * @var string - */ - var $adminPassword; - - /** - * the username to be used for admin connections - * - * @var string - */ - var $adminUsername; - - /** - * enable encryption - * - * @var bool - */ - var $encryption; - - /** - * the hostname/ip address of the imap server - * - * @var string - */ - var $host; - - /** - * the password for the user - * - * @var string - */ - var $password; - - /** - * the port of the imap server - * - * @var integer - */ - var $port = 143; - - /** - * the username - * - * @var string - */ - var $username; - - /** - * the domainname to be used for vmailmgr logins - * - * @var string - */ - var $domainName = false; - - /** - * validate ssl certificate - * - * @var bool - */ - var $validatecert; - - /** - * the mailbox delimiter - * - * @var string - */ - var $mailboxDelimiter = '/'; - - /** - * the mailbox prefix. maybe used by uw-imap only? - * - * @var string - */ - var $mailboxPrefix = '~/mail'; - - /** - * is the mbstring extension available - * - * @var unknown_type - */ - var $mbAvailable; - - /** - * Mailboxes which get automatic created for new accounts (INBOX == '') - * - * @var array - */ - var $imapLoginType; - var $defaultDomain; - - - /** - * disable internal conversion from/to ut7 - * get's used by Net_IMAP - * - * @var array - */ - var $_useUTF_7 = false; - - /** - * a debug switch - */ - var $debug = false; - - /** - * the construtor - * - * @return void - */ - function defaultimap() - { - if (function_exists('mb_convert_encoding')) { - $this->mbAvailable = TRUE; - } - - $this->restoreSessionData(); - - // construtor for Net_IMAP stuff - $this->Net_IMAPProtocol(); - } - - /** - * Magic method to re-connect with the imapserver, if the object get's restored from the session - */ - function __wakeup() - { - #$this->openConnection($this->isAdminConnection); // we need to re-connect - } - - /** - * adds a account on the imap server - * - * @param array $_hookValues - * @return bool true on success, false on failure - */ - function addAccount($_hookValues) - { - return true; - } - - /** - * updates a account on the imap server - * - * @param array $_hookValues - * @return bool true on success, false on failure - */ - function updateAccount($_hookValues) - { - return true; - } - - /** - * deletes a account on the imap server - * - * @param array $_hookValues - * @return bool true on success, false on failure - */ - function deleteAccount($_hookValues) - { - return true; - } - - function disconnect() - { - //error_log(__METHOD__.function_backtrace()); - $retval = parent::disconnect(); - if( PEAR::isError($retval)) error_log(__METHOD__.$retval->message); - $this->_connected = false; - } - - /** - * converts a foldername from current system charset to UTF7 - * - * @param string $_folderName - * @return string the encoded foldername - */ - function encodeFolderName($_folderName) - { - if($this->mbAvailable) { - return mb_convert_encoding($_folderName, "UTF7-IMAP", $GLOBALS['egw']->translation->charset()); - } - - // if not - // we can encode only from ISO 8859-1 - return imap_utf7_encode($_folderName); - } - - /** - * returns the supported capabilities of the imap server - * return false if the imap server does not support capabilities - * - * @return array the supported capabilites - */ - function getCapabilities() - { - if(!is_array($this->sessionData['capabilities'][$this->host])) { - return false; - } - - return $this->sessionData['capabilities'][$this->host]; - } - - /** - * return the delimiter used by the current imap server - * - * @return string the delimimiter - */ - function getDelimiter() - { - return isset($this->sessionData['delimiter'][$this->host]) ? $this->sessionData['delimiter'][$this->host] : $this->mailboxDelimiter; - } - - /** - * Create transport string - * - * @return string the transportstring - */ - function _getTransportString() - { - if($this->encryption == 2) { - $connectionString = "tls://". $this->host; - } elseif($this->encryption == 3) { - $connectionString = "ssl://". $this->host; - } else { - // no tls - $connectionString = $this->host; - } - - return $connectionString; - } - - /** - * Create the options array for SSL/TLS connections - * - * @return string the transportstring - */ - function _getTransportOptions() - { - if($this->validatecert === false) { - if($this->encryption == 2) { - return array( - 'tls' => array( - 'verify_peer' => false, - 'allow_self_signed' => true, - ) - ); - } elseif($this->encryption == 3) { - return array( - 'ssl' => array( - 'verify_peer' => false, - 'allow_self_signed' => true, - ) - ); - } - } else { - if($this->encryption == 2) { - return array( - 'tls' => array( - 'verify_peer' => true, - 'allow_self_signed' => false, - ) - ); - } elseif($this->encryption == 3) { - return array( - 'ssl' => array( - 'verify_peer' => true, - 'allow_self_signed' => false, - ) - ); - } - } - - return null; - } - - /** - * get the effective Username for the Mailbox, as it is depending on the loginType - * @param string $_username - * @return string the effective username to be used to access the Mailbox - */ - function getMailBoxUserName($_username) - { - if ($this->loginType == 'email') - { - $_username = $_username; - $accountID = $GLOBALS['egw']->accounts->name2id($_username); - $accountemail = $GLOBALS['egw']->accounts->id2name($accountID,'account_email'); - //$accountemail = $GLOBALS['egw']->accounts->read($GLOBALS['egw']->accounts->name2id($_username,'account_email')); - if (!empty($accountemail)) - { - list($lusername,$domain) = explode('@',$accountemail,2); - if (strtolower($domain) == strtolower($this->domainName) && !empty($lusername)) - { - $_username = $lusername; - } - } - } - return $_username; - } - - /** - * Create mailbox string from given mailbox-name and user-name - * - * @param string $_folderName='' - * @return string utf-7 encoded (done in getMailboxName) - */ - function getUserMailboxString($_username, $_folderName='') - { - $nameSpaces = $this->getNameSpaces(); - - if(!isset($nameSpaces['others'])) { - return false; - } - - $_username = $this->getMailBoxUserName($_username); - if($this->loginType == 'vmailmgr' || $this->loginType == 'email') { - $_username .= '@'. $this->domainName; - } - - $mailboxString = $nameSpaces['others'][0]['name'] . $_username . (!empty($_folderName) ? $nameSpaces['others'][0]['delimiter'] . $_folderName : ''); - - return $mailboxString; - } - /** - * get list of namespaces - * - * @return array array containing information about namespace - */ - function getNameSpaces() - { - if(!$this->_connected) { - return false; - } - $retrieveDefault = false; - if($this->hasCapability('NAMESPACE')) { - $nameSpace = $this->getNamespace(); - if( PEAR::isError($nameSpace)) { - if ($this->debug) error_log("emailadmin::defaultimap->getNameSpaces:".print_r($nameSpace,true)); - $retrieveDefault = true; - } else { - $result = array(); - - $result['personal'] = $nameSpace['personal']; - - if(is_array($nameSpace['others'])) { - $result['others'] = $nameSpace['others']; - } - - if(is_array($nameSpace['shared'])) { - $result['shared'] = $nameSpace['shared']; - } - } - } - if (!$this->hasCapability('NAMESPACE') || $retrieveDefault) { - $delimiter = $this->getHierarchyDelimiter(); - if( PEAR::isError($delimiter)) $delimiter = '/'; + var $adminPassword; - $result['personal'] = array( - 0 => array( - 'name' => '', - 'delimiter' => $delimiter - ) - ); - } - - return $result; - } - - /** - * returns the quota for given foldername - * gets quota for the current user only - * - * @param string $_folderName - * @return string the current quota for this folder - */ - # function getQuota($_folderName) - # { - # if(!is_resource($this->mbox)) { - # $this->openConnection(); - # } - # - # if(function_exists('imap_get_quotaroot') && $this->supportsCapability('QUOTA')) { - # $quota = @imap_get_quotaroot($this->mbox, $this->encodeFolderName($_folderName)); - # if(is_array($quota) && isset($quota['STORAGE'])) { - # return $quota['STORAGE']; - # } - # } - # - # return false; - # } - - /** - * return the quota for another user - * used by admin connections only - * - * @param string $_username - * @return string the quota for specified user - */ - function getQuotaByUser($_username) - { - $mailboxName = $this->getUserMailboxString($_username); - //error_log(__METHOD__.$mailboxName); - $storageQuota = $this->getStorageQuota($mailboxName); - //error_log(__METHOD__.$_username); - //error_log(__METHOD__.$mailboxName); - if ( PEAR::isError($storageQuota)) error_log(__METHOD__.$storageQuota->message); - if(is_array($storageQuota) && isset($storageQuota['QMAX'])) { - return (int)$storageQuota['QMAX']; - } + /** + * the username to be used for admin connections + * + * @var string + */ + var $adminUsername; + + /** + * enable encryption + * + * @var bool + */ + var $encryption; + + /** + * the hostname/ip address of the imap server + * + * @var string + */ + var $host; + + /** + * the password for the user + * + * @var string + */ + var $password; + + /** + * the port of the imap server + * + * @var integer + */ + var $port = 143; + /** + * the username + * + * @var string + */ + var $username; + + /** + * the domainname to be used for vmailmgr logins + * + * @var string + */ + var $domainName = false; + + /** + * validate ssl certificate + * + * @var bool + */ + var $validatecert; + + /** + * the mailbox delimiter + * + * @var string + */ + var $mailboxDelimiter = '/'; + + /** + * the mailbox prefix. maybe used by uw-imap only? + * + * @var string + */ + var $mailboxPrefix = '~/mail'; + + /** + * is the mbstring extension available + * + * @var unknown_type + */ + var $mbAvailable; + + /** + * Mailboxes which get automatic created for new accounts (INBOX == '') + * + * @var array + */ + var $imapLoginType; + var $defaultDomain; + + + /** + * disable internal conversion from/to ut7 + * get's used by Net_IMAP + * + * @var array + */ + var $_useUTF_7 = false; + + /** + * a debug switch + */ + var $debug = false; + + /** + * Sieve available + * + * @var boolean + */ + var $enableSieve = false; + + /** + * Hostname / IP of sieve host + * + * @var string + */ + var $sieveHost; + + /** + * Port of Sieve service + * + * @var int + */ + var $sievePort = 2000; + + /** + * the construtor + * + * @return void + */ + function __construct() + { + if (function_exists('mb_convert_encoding')) { + $this->mbAvailable = TRUE; + } + + $this->restoreSessionData(); + + // construtor for Net_IMAP stuff + $this->Net_IMAPProtocol(); + } + + /** + * Magic method to re-connect with the imapserver, if the object get's restored from the session + */ + function __wakeup() + { + #$this->openConnection($this->isAdminConnection); // we need to re-connect + } + + /** + * adds a account on the imap server + * + * @param array $_hookValues + * @return bool true on success, false on failure + */ + function addAccount($_hookValues) + { + return true; + } + + /** + * updates a account on the imap server + * + * @param array $_hookValues + * @return bool true on success, false on failure + */ + function updateAccount($_hookValues) + { + return true; + } + + /** + * deletes a account on the imap server + * + * @param array $_hookValues + * @return bool true on success, false on failure + */ + function deleteAccount($_hookValues) + { + return true; + } + + function disconnect() + { + //error_log(__METHOD__.function_backtrace()); + $retval = parent::disconnect(); + if( PEAR::isError($retval)) error_log(__METHOD__.$retval->message); + $this->_connected = false; + } + + /** + * converts a foldername from current system charset to UTF7 + * + * @param string $_folderName + * @return string the encoded foldername + */ + function encodeFolderName($_folderName) + { + if($this->mbAvailable) { + return mb_convert_encoding($_folderName, "UTF7-IMAP", $GLOBALS['egw']->translation->charset()); + } + + // if not + // we can encode only from ISO 8859-1 + return imap_utf7_encode($_folderName); + } + + /** + * returns the supported capabilities of the imap server + * return false if the imap server does not support capabilities + * + * @return array the supported capabilites + */ + function getCapabilities() + { + if(!is_array($this->sessionData['capabilities'][$this->host])) { return false; } - /** - * returns information about a user - * currently only supported information is the current quota - * - * @param string $_username - * @return array userdata - */ - function getUserData($_username) - { - if($this->_connected === true) { - //error_log(__METHOD__."try to disconnect"); - $this->disconnect(); - } - - $this->openConnection(true); - $userData = array(); - - if($quota = $this->getQuotaByUser($_username)) { - $userData['quotaLimit'] = $quota / 1024; - } - - $this->disconnect(); - - return $userData; - } - - /** - * opens a connection to a imap server - * - * @param bool $_adminConnection create admin connection if true - * - * @return resource the imap connection - */ - function openConnection($_adminConnection=false) - { - //error_log(__METHOD__.function_backtrace()); - unset($this->_connectionErrorObject); - - if($_adminConnection) { - $username = $this->adminUsername; - $password = $this->adminPassword; - $options = ''; - $this->isAdminConnection = true; - } else { - $username = $this->loginName; - $password = $this->password; - $options = $_options; - $this->isAdminConnection = false; - } - - $this->setStreamContextOptions($this->_getTransportOptions()); - $this->setTimeout(20); - if( PEAR::isError($status = parent::connect($this->_getTransportString(), $this->port, $this->encryption == 1)) ) { - if ($this->debug) error_log(__METHOD__."Could not connect with ".$this->_getTransportString()." on Port ".$this->port." Encryption==1?".$this->encryption); - if ($this->debug) error_log(__METHOD__."Status connect:".$status->message); - $this->_connectionErrorObject = $status; - return false; - } - if(empty($username)) - { - if ($this->debug) error_log(__METHOD__."No username supplied.".function_backtrace()); - return false; - } - if( PEAR::isError($status = parent::login($username, $password, TRUE, !$this->isAdminConnection)) ) { - if ($this->debug) error_log(__METHOD__."Could not log in with ->".$username.":".$password."<- Domain:".$GLOBALS['egw_info']['user']['domain']); - if ($this->debug) error_log(__METHOD__."Status login:".array2string($status->message)); - if ($this->debug) error_log(__METHOD__.'Called from:'.function_backtrace()); - $this->disconnect(); - $this->_connectionErrorObject = $status; - return false; - } - - return true; - } - - /** - * restore session variable - * - */ - function restoreSessionData() - { - $this->sessionData = $GLOBALS['egw']->session->appsession('imap_session_data'); - } - - /** - * save session variable - * - */ - function saveSessionData() - { - $GLOBALS['egw']->session->appsession('imap_session_data','',$this->sessionData); - } - - /** - * set userdata - * - * @param string $_username username of the user - * @param int $_quota quota in bytes - * @return bool true on success, false on failure - */ - function setUserData($_username, $_quota) - { - return true; - } - - /** - * check if imap server supports given capability - * - * @param string $_capability the capability to check for - * @return bool true if capability is supported, false if not - */ - function supportsCapability($_capability) - { - return $this->hasCapability($_capability); - } + return $this->sessionData['capabilities'][$this->host]; } -?> + + /** + * return the delimiter used by the current imap server + * + * @return string the delimimiter + */ + function getDelimiter() + { + return isset($this->sessionData['delimiter'][$this->host]) ? $this->sessionData['delimiter'][$this->host] : $this->mailboxDelimiter; + } + + /** + * Create transport string + * + * @return string the transportstring + */ + function _getTransportString() + { + if($this->encryption == 2) { + $connectionString = "tls://". $this->host; + } elseif($this->encryption == 3) { + $connectionString = "ssl://". $this->host; + } else { + // no tls + $connectionString = $this->host; + } + + return $connectionString; + } + + /** + * Create the options array for SSL/TLS connections + * + * @return string the transportstring + */ + function _getTransportOptions() + { + if($this->validatecert === false) { + if($this->encryption == 2) { + return array( + 'tls' => array( + 'verify_peer' => false, + 'allow_self_signed' => true, + ) + ); + } elseif($this->encryption == 3) { + return array( + 'ssl' => array( + 'verify_peer' => false, + 'allow_self_signed' => true, + ) + ); + } + } else { + if($this->encryption == 2) { + return array( + 'tls' => array( + 'verify_peer' => true, + 'allow_self_signed' => false, + ) + ); + } elseif($this->encryption == 3) { + return array( + 'ssl' => array( + 'verify_peer' => true, + 'allow_self_signed' => false, + ) + ); + } + } + + return null; + } + + /** + * get the effective Username for the Mailbox, as it is depending on the loginType + * @param string $_username + * @return string the effective username to be used to access the Mailbox + */ + function getMailBoxUserName($_username) + { + if ($this->loginType == 'email') + { + $_username = $_username; + $accountID = $GLOBALS['egw']->accounts->name2id($_username); + $accountemail = $GLOBALS['egw']->accounts->id2name($accountID,'account_email'); + //$accountemail = $GLOBALS['egw']->accounts->read($GLOBALS['egw']->accounts->name2id($_username,'account_email')); + if (!empty($accountemail)) + { + list($lusername,$domain) = explode('@',$accountemail,2); + if (strtolower($domain) == strtolower($this->domainName) && !empty($lusername)) + { + $_username = $lusername; + } + } + } + return $_username; + } + + /** + * Create mailbox string from given mailbox-name and user-name + * + * @param string $_folderName='' + * @return string utf-7 encoded (done in getMailboxName) + */ + function getUserMailboxString($_username, $_folderName='') + { + $nameSpaces = $this->getNameSpaces(); + + if(!isset($nameSpaces['others'])) { + return false; + } + + $_username = $this->getMailBoxUserName($_username); + if($this->loginType == 'vmailmgr' || $this->loginType == 'email') { + $_username .= '@'. $this->domainName; + } + + $mailboxString = $nameSpaces['others'][0]['name'] . $_username . (!empty($_folderName) ? $nameSpaces['others'][0]['delimiter'] . $_folderName : ''); + + return $mailboxString; + } + /** + * get list of namespaces + * + * @return array array containing information about namespace + */ + function getNameSpaces() + { + if(!$this->_connected) { + return false; + } + $retrieveDefault = false; + if($this->hasCapability('NAMESPACE')) { + $nameSpace = $this->getNamespace(); + if( PEAR::isError($nameSpace)) { + if ($this->debug) error_log("emailadmin::defaultimap->getNameSpaces:".print_r($nameSpace,true)); + $retrieveDefault = true; + } else { + $result = array(); + + $result['personal'] = $nameSpace['personal']; + + if(is_array($nameSpace['others'])) { + $result['others'] = $nameSpace['others']; + } + + if(is_array($nameSpace['shared'])) { + $result['shared'] = $nameSpace['shared']; + } + } + } + if (!$this->hasCapability('NAMESPACE') || $retrieveDefault) { + $delimiter = $this->getHierarchyDelimiter(); + if( PEAR::isError($delimiter)) $delimiter = '/'; + + $result['personal'] = array( + 0 => array( + 'name' => '', + 'delimiter' => $delimiter + ) + ); + } + + return $result; + } + + /** + * returns the quota for given foldername + * gets quota for the current user only + * + * @param string $_folderName + * @return string the current quota for this folder + */ +# function getQuota($_folderName) +# { +# if(!is_resource($this->mbox)) { +# $this->openConnection(); +# } +# +# if(function_exists('imap_get_quotaroot') && $this->supportsCapability('QUOTA')) { +# $quota = @imap_get_quotaroot($this->mbox, $this->encodeFolderName($_folderName)); +# if(is_array($quota) && isset($quota['STORAGE'])) { +# return $quota['STORAGE']; +# } +# } +# +# return false; +# } + + /** + * return the quota for another user + * used by admin connections only + * + * @param string $_username + * @return string the quota for specified user + */ + function getQuotaByUser($_username) + { + $mailboxName = $this->getUserMailboxString($_username); + //error_log(__METHOD__.$mailboxName); + $storageQuota = $this->getStorageQuota($mailboxName); + //error_log(__METHOD__.$_username); + //error_log(__METHOD__.$mailboxName); + if ( PEAR::isError($storageQuota)) error_log(__METHOD__.$storageQuota->message); + if(is_array($storageQuota) && isset($storageQuota['QMAX'])) { + return (int)$storageQuota['QMAX']; + } + + return false; + } + + /** + * returns information about a user + * currently only supported information is the current quota + * + * @param string $_username + * @return array userdata + */ + function getUserData($_username) + { + if($this->_connected === true) { + //error_log(__METHOD__."try to disconnect"); + $this->disconnect(); + } + + $this->openConnection(true); + $userData = array(); + + if($quota = $this->getQuotaByUser($_username)) { + $userData['quotaLimit'] = $quota / 1024; + } + + $this->disconnect(); + + return $userData; + } + + /** + * opens a connection to a imap server + * + * @param bool $_adminConnection create admin connection if true + * + * @return resource the imap connection + */ + function openConnection($_adminConnection=false) + { + //error_log(__METHOD__.function_backtrace()); + unset($this->_connectionErrorObject); + + if($_adminConnection) { + $username = $this->adminUsername; + $password = $this->adminPassword; + $options = ''; + $this->isAdminConnection = true; + } else { + $username = $this->loginName; + $password = $this->password; + $options = $_options; + $this->isAdminConnection = false; + } + + $this->setStreamContextOptions($this->_getTransportOptions()); + $this->setTimeout(20); + if( PEAR::isError($status = parent::connect($this->_getTransportString(), $this->port, $this->encryption == 1)) ) { + if ($this->debug) error_log(__METHOD__."Could not connect with ".$this->_getTransportString()." on Port ".$this->port." Encryption==1?".$this->encryption); + if ($this->debug) error_log(__METHOD__."Status connect:".$status->message); + $this->_connectionErrorObject = $status; + return false; + } + if(empty($username)) + { + if ($this->debug) error_log(__METHOD__."No username supplied.".function_backtrace()); + return false; + } + if( PEAR::isError($status = parent::login($username, $password, TRUE, !$this->isAdminConnection)) ) { + if ($this->debug) error_log(__METHOD__."Could not log in with ->".$username.":".$password."<-"); + if ($this->debug) error_log(__METHOD__."Status login:".array2string($status->message)); + //error_log(__METHOD__.'Called from:'.function_backtrace()); + $this->disconnect(); + $this->_connectionErrorObject = $status; + return false; + } + + return true; + } + + /** + * restore session variable + * + */ + function restoreSessionData() + { + $this->sessionData = $GLOBALS['egw']->session->appsession('imap_session_data'); + } + + /** + * save session variable + * + */ + function saveSessionData() + { + $GLOBALS['egw']->session->appsession('imap_session_data','',$this->sessionData); + } + + /** + * set userdata + * + * @param string $_username username of the user + * @param int $_quota quota in bytes + * @return bool true on success, false on failure + */ + function setUserData($_username, $_quota) + { + return true; + } + + /** + * check if imap server supports given capability + * + * @param string $_capability the capability to check for + * @return bool true if capability is supported, false if not + */ + function supportsCapability($_capability) + { + return $this->hasCapability($_capability); + } + + /** + * Instance of emailadmin_sieve + * + * @var emailadmin_sieve + */ + private $sieve; + + public $scriptName; + public $error; + + //public $error; + + /** + * Proxy former felamimail bosieve methods to internal emailadmin_sieve instance + * + * @param string $name + * @param array $params + */ + public function __call($name,array $params=null) + { + switch($name) + { + case 'installScript': + case 'getScript': + case 'setActive': + case 'setEmailNotification': + case 'getEmailNotification': + case 'setRules': + case 'getRules': + case 'retrieveRules': + case 'getVacation': + case 'setVacation': + case 'setVacationUser': + if (is_null($this->sieve)) + { + $this->sieve = new emailadmin_sieve($this); + $this->scriptName =& $this->sieve->scriptName; + $this->error =& $this->sieve->error; + } + $ret = call_user_func_array(array($this->sieve,$name),$params); + error_log(__CLASS__.'->'.$name.'('.array2string($params).') returns '.array2string($ret)); + return $ret; + } + throw new egw_exception_wrong_parameter("No method '$name' implemented!"); + } +} diff --git a/emailadmin/inc/class.defaultsmtp.inc.php b/emailadmin/inc/class.defaultsmtp.inc.php index 11973d0270..522e4be6cb 100644 --- a/emailadmin/inc/class.defaultsmtp.inc.php +++ b/emailadmin/inc/class.defaultsmtp.inc.php @@ -13,6 +13,11 @@ class defaultsmtp { + /** + * Capabilities of this class (pipe-separated): default, forward + */ + const CAPABILITIES = 'default'; + var $smtpAuth = false; var $editForwardingAddress = false; diff --git a/emailadmin/inc/class.emailadmin_bo.inc.php b/emailadmin/inc/class.emailadmin_bo.inc.php index 7d9d4cd14d..2d5db879c2 100644 --- a/emailadmin/inc/class.emailadmin_bo.inc.php +++ b/emailadmin/inc/class.emailadmin_bo.inc.php @@ -1,941 +1,930 @@ + * @author Klaus Leithoff + * @author Lars Kneschke + * @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License + * @version $Id$ + */ - class emailadmin_bo extends so_sql - { - /** - * Name of our table - */ - const TABLE = 'egw_emailadmin'; - /** - * Name of app the table is registered - */ - const APP = 'emailadmin'; - /** - * Fields that are numeric - */ - static $numericfields = array( - 'ea_profile_id', - 'ea_smtp_type', - 'ea_smtp_port', - 'ea_smtp_auth', - 'ea_editforwardingaddress', - 'ea_smtp_ldap_use_default', - 'ea_imap_type', - 'ea_imap_port', - 'ea_imap_login_type', - 'ea_imap_tsl_auth', - 'ea_imap_tsl_encryption', - 'ea_imap_enable_cyrus', - 'ea_imap_enable_sieve', - 'ea_imap_sieve_port', - 'ea_user_defined_identities', - 'ea_user_defined_accounts', - 'ea_order', - 'ea_active', - 'ea_group', - 'ea_user', - 'ea_appname', - 'ea_user_defined_signatures', - ); - - static $sessionData = array(); - #var $userSessionData; - var $LDAPData; - - //var $SMTPServerType = array(); // holds a list of config options - static $SMTPServerType = array( - 'defaultsmtp' => array( - 'fieldNames' => array( - 'smtpServer', - 'smtpPort', - 'smtpAuth', - 'ea_smtp_auth_username', - 'ea_smtp_auth_password', - 'smtpType' - ), - 'description' => 'standard SMTP-Server', - 'smtpcapabilities' => 'default', - 'classname' => 'defaultsmtp' - ), - 'postfixldap' => array( - 'fieldNames' => array( - 'smtpServer', - 'smtpPort', - 'smtpAuth', - 'ea_smtp_auth_username', - 'ea_smtp_auth_password', - 'smtpType', - 'editforwardingaddress', - 'smtpLDAPServer', - 'smtpLDAPAdminDN', - 'smtpLDAPAdminPW', - 'smtpLDAPBaseDN', - 'smtpLDAPUseDefault' - ), - 'description' => 'Postfix (qmail Schema)', - 'smtpcapabilities' => 'default|forward', - 'classname' => 'postfixldap' - ), - 'postfixinetorgperson' => array( - 'fieldNames' => array( - 'smtpServer', - 'smtpPort', - 'smtpAuth', - 'ea_smtp_auth_username', - 'ea_smtp_auth_password', - 'smtpType', - ), - 'description' => 'Postfix (inetOrgPerson Schema)', - 'smtpcapabilities' => 'default', - 'classname' => 'postfixinetorgperson' - ), - 'smtpplesk' => array( - 'fieldNames' => array( - 'smtpServer', - 'smtpPort', - 'smtpAuth', - 'ea_smtp_auth_username', - 'ea_smtp_auth_password', - 'smtpType', - 'editforwardingaddress', - ), - 'description' => 'Plesk SMTP-Server (Qmail)', - 'smtpcapabilities' => 'default|forward', - 'classname' => 'smtpplesk' - ), - 'postfixdbmailuser' => array( - 'fieldNames' => array( - 'smtpServer', - 'smtpPort', - 'smtpAuth', - 'ea_smtp_auth_username', - 'ea_smtp_auth_password', - 'smtpType', - 'editforwardingaddress', - 'smtpLDAPServer', - 'smtpLDAPAdminDN', - 'smtpLDAPAdminPW', - 'smtpLDAPBaseDN', - 'smtpLDAPUseDefault' - ), - 'description' => 'Postfix (dbmail Schema)', - 'smtpcapabilities' => 'default|forward', - 'classname' => 'postfixdbmailuser' - ), - 'stylite_postfixmandriva' => array( - 'fieldNames' => array( - 'smtpServer', - 'smtpPort', - 'smtpAuth', - 'ea_smtp_auth_username', - 'ea_smtp_auth_password', - 'smtpType', - 'editforwardingaddress', - 'smtpLDAPServer', - 'smtpLDAPAdminDN', - 'smtpLDAPAdminPW', - 'smtpLDAPBaseDN', - 'smtpLDAPUseDefault' - ), - 'description' => 'Postfix (Mandriva mailAccount schema)', - 'smtpcapabilities' => 'default|forward', - 'classname' => 'stylite_postfixmandriva' - ), - 'stylite_postfixsuse' => array( - 'fieldNames' => array( - 'smtpServer', - 'smtpPort', - 'smtpAuth', - 'ea_smtp_auth_username', - 'ea_smtp_auth_password', - 'smtpType', - 'editforwardingaddress', - 'smtpLDAPServer', - 'smtpLDAPAdminDN', - 'smtpLDAPAdminPW', - 'smtpLDAPBaseDN', - 'smtpLDAPUseDefault' - ), - 'description' => 'Postfix (SuseMailServer schema)', - 'smtpcapabilities' => 'default|forward', - 'classname' => 'stylite_postfixsuse' - ), +/** + * Business logic + */ +class emailadmin_bo extends so_sql +{ + /** + * Name of our table + */ + const TABLE = 'egw_emailadmin'; + /** + * Name of app the table is registered + */ + const APP = 'emailadmin'; + /** + * Fields that are numeric + */ + static $numericfields = array( + 'ea_profile_id', + 'ea_smtp_type', + 'ea_smtp_port', + 'ea_smtp_auth', + 'ea_editforwardingaddress', + 'ea_smtp_ldap_use_default', + 'ea_imap_type', + 'ea_imap_port', + 'ea_imap_login_type', + 'ea_imap_tsl_auth', + 'ea_imap_tsl_encryption', + 'ea_imap_enable_cyrus', + 'ea_imap_enable_sieve', + 'ea_imap_sieve_port', + 'ea_user_defined_identities', + 'ea_user_defined_accounts', + 'ea_order', + 'ea_active', + 'ea_group', + 'ea_user', + 'ea_appname', + 'ea_user_defined_signatures', ); - //var $IMAPServerType = array(); // holds a list of config options - static $IMAPServerType = array( - 'defaultimap' => array( - 'fieldNames' => array( - 'imapServer', - 'imapPort', - 'imapType', - 'imapLoginType', - 'imapTLSEncryption', - 'imapTLSAuthentication', - 'imapAuthUsername', - 'imapAuthPassword' - ), - 'description' => 'standard IMAP server', - 'protocol' => 'imap', - 'imapcapabilities' => 'default', - 'classname' => 'defaultimap' - ), - 'cyrusimap' => array( - 'fieldNames' => array( - 'imapServer', - 'imapPort', - 'imapType', - 'imapLoginType', - 'imapTLSEncryption', - 'imapTLSAuthentication', - 'imapEnableCyrusAdmin', - 'imapAdminUsername', - 'imapAdminPW', - 'imapEnableSieve', - 'imapSieveServer', - 'imapSievePort', - 'imapAuthUsername', - 'imapAuthPassword' - ), - 'description' => 'Cyrus IMAP Server', - 'protocol' => 'imap', - 'imapcapabilities' => 'default|sieve|admin|logintypeemail', - 'classname' => 'cyrusimap' - ), - 'dbmailqmailuser' => array( - 'fieldNames' => array( - 'imapServer', - 'imapPort', - 'imapType', - 'imapLoginType', - 'imapTLSEncryption', - 'imapTLSAuthentication', - 'imapEnableSieve', - 'imapSieveServer', - 'imapSievePort', - 'imapAuthUsername', - 'imapAuthPassword', - ), - 'description' => 'DBMail (qmailUser schema)', - 'protocol' => 'imap', - 'imapcapabilities' => 'default|sieve', - 'classname' => 'dbmailqmailuser' - ), - 'pleskimap' => array( - 'fieldNames' => array( - 'imapServer', - 'imapPort', - 'imapType', - 'imapLoginType', - 'imapTLSEncryption', - 'imapTLSAuthentication', - 'imapAuthUsername', - 'imapAuthPassword' - ), - 'description' => 'Plesk IMAP Server (Courier)', - 'protocol' => 'imap', - 'imapcapabilities' => 'default', - 'classname' => 'pleskimap' - ), - 'dbmaildbmailuser' => array( - 'fieldNames' => array( - 'imapServer', - 'imapPort', - 'imapType', - 'imapLoginType', - 'imapTLSEncryption', - 'imapTLSAuthentication', - 'imapEnableSieve', - 'imapSieveServer', - 'imapSievePort', - 'imapAuthUsername', - 'imapAuthPassword' - ), - 'description' => 'DBMail (dbmailUser schema)', - 'protocol' => 'imap', - 'imapcapabilities' => 'default|sieve', - 'classname' => 'dbmaildbmailuser' - ), - ); - var $imapClass; // holds the imap/pop3 class - var $smtpClass; // holds the smtp class + static $sessionData = array(); + #var $userSessionData; + var $LDAPData; + + //var $SMTPServerType = array(); // holds a list of config options + static $SMTPServerType = array( + 'defaultsmtp' => array( + 'fieldNames' => array( + 'smtpServer', + 'smtpPort', + 'smtpAuth', + 'ea_smtp_auth_username', + 'ea_smtp_auth_password', + 'smtpType' + ), + 'description' => 'standard SMTP-Server', + 'classname' => 'defaultsmtp' + ), + 'postfixldap' => array( + 'fieldNames' => array( + 'smtpServer', + 'smtpPort', + 'smtpAuth', + 'ea_smtp_auth_username', + 'ea_smtp_auth_password', + 'smtpType', + 'editforwardingaddress', + 'smtpLDAPServer', + 'smtpLDAPAdminDN', + 'smtpLDAPAdminPW', + 'smtpLDAPBaseDN', + 'smtpLDAPUseDefault' + ), + 'description' => 'Postfix (qmail Schema)', + 'classname' => 'postfixldap' + ), + 'postfixinetorgperson' => array( + 'fieldNames' => array( + 'smtpServer', + 'smtpPort', + 'smtpAuth', + 'ea_smtp_auth_username', + 'ea_smtp_auth_password', + 'smtpType', + ), + 'description' => 'Postfix (inetOrgPerson Schema)', + 'classname' => 'postfixinetorgperson' + ), + 'smtpplesk' => array( + 'fieldNames' => array( + 'smtpServer', + 'smtpPort', + 'smtpAuth', + 'ea_smtp_auth_username', + 'ea_smtp_auth_password', + 'smtpType', + 'editforwardingaddress', + ), + 'description' => 'Plesk SMTP-Server (Qmail)', + 'classname' => 'smtpplesk' + ), + 'postfixdbmailuser' => array( + 'fieldNames' => array( + 'smtpServer', + 'smtpPort', + 'smtpAuth', + 'ea_smtp_auth_username', + 'ea_smtp_auth_password', + 'smtpType', + 'editforwardingaddress', + 'smtpLDAPServer', + 'smtpLDAPAdminDN', + 'smtpLDAPAdminPW', + 'smtpLDAPBaseDN', + 'smtpLDAPUseDefault' + ), + 'description' => 'Postfix (dbmail Schema)', + 'classname' => 'postfixdbmailuser' + ), + 'stylite_postfixmandriva' => array( + 'fieldNames' => array( + 'smtpServer', + 'smtpPort', + 'smtpAuth', + 'ea_smtp_auth_username', + 'ea_smtp_auth_password', + 'smtpType', + 'editforwardingaddress', + 'smtpLDAPServer', + 'smtpLDAPAdminDN', + 'smtpLDAPAdminPW', + 'smtpLDAPBaseDN', + 'smtpLDAPUseDefault' + ), + 'description' => 'Postfix (Mandriva mailAccount schema)', + 'classname' => 'stylite_postfixmandriva' + ), + 'stylite_postfixsuse' => array( + 'fieldNames' => array( + 'smtpServer', + 'smtpPort', + 'smtpAuth', + 'ea_smtp_auth_username', + 'ea_smtp_auth_password', + 'smtpType', + 'editforwardingaddress', + 'smtpLDAPServer', + 'smtpLDAPAdminDN', + 'smtpLDAPAdminPW', + 'smtpLDAPBaseDN', + 'smtpLDAPUseDefault' + ), + 'description' => 'Postfix (SuseMailServer schema)', + 'classname' => 'stylite_postfixsuse' + ), + ); + //var $IMAPServerType = array(); // holds a list of config options + static $IMAPServerType = array( + 'defaultimap' => array( + 'fieldNames' => array( + 'imapServer', + 'imapPort', + 'imapType', + 'imapLoginType', + 'imapTLSEncryption', + 'imapTLSAuthentication', + 'imapAuthUsername', + 'imapAuthPassword' + ), + 'description' => 'standard IMAP server', + 'protocol' => 'imap', + 'classname' => 'defaultimap' + ), + 'cyrusimap' => array( + 'fieldNames' => array( + 'imapServer', + 'imapPort', + 'imapType', + 'imapLoginType', + 'imapTLSEncryption', + 'imapTLSAuthentication', + 'imapEnableCyrusAdmin', + 'imapAdminUsername', + 'imapAdminPW', + 'imapEnableSieve', + 'imapSieveServer', + 'imapSievePort', + 'imapAuthUsername', + 'imapAuthPassword' + ), + 'description' => 'Cyrus IMAP Server', + 'protocol' => 'imap', + 'classname' => 'cyrusimap' + ), + 'dbmailqmailuser' => array( + 'fieldNames' => array( + 'imapServer', + 'imapPort', + 'imapType', + 'imapLoginType', + 'imapTLSEncryption', + 'imapTLSAuthentication', + 'imapEnableSieve', + 'imapSieveServer', + 'imapSievePort', + 'imapAuthUsername', + 'imapAuthPassword', + ), + 'description' => 'DBMail (qmailUser schema)', + 'protocol' => 'imap', + 'classname' => 'dbmailqmailuser' + ), + 'pleskimap' => array( + 'fieldNames' => array( + 'imapServer', + 'imapPort', + 'imapType', + 'imapLoginType', + 'imapTLSEncryption', + 'imapTLSAuthentication', + 'imapAuthUsername', + 'imapAuthPassword' + ), + 'description' => 'Plesk IMAP Server (Courier)', + 'protocol' => 'imap', + 'classname' => 'pleskimap' + ), + 'dbmaildbmailuser' => array( + 'fieldNames' => array( + 'imapServer', + 'imapPort', + 'imapType', + 'imapLoginType', + 'imapTLSEncryption', + 'imapTLSAuthentication', + 'imapEnableSieve', + 'imapSieveServer', + 'imapSievePort', + 'imapAuthUsername', + 'imapAuthPassword' + ), + 'description' => 'DBMail (dbmailUser schema)', + 'protocol' => 'imap', + 'classname' => 'dbmaildbmailuser' + ), + ); + + var $imapClass; // holds the imap/pop3 class + var $smtpClass; // holds the smtp class - function __construct($_profileID=-1,$_restoreSesssion=true) + function __construct($_profileID=-1,$_restoreSesssion=true) + { + parent::__construct(self::APP,self::TABLE,null,'',true); + + if (!is_object($GLOBALS['emailadmin_bo'])) { - - parent::__construct(self::APP,self::TABLE,null,'',true); - - if (!is_object($GLOBALS['emailadmin_bo'])) - { - $GLOBALS['emailadmin_bo'] = $this; - } - $this->soemailadmin = new emailadmin_so(); - //translate the standard entry description - self::$SMTPServerType['defaultsmtp']['description'] = lang('standard SMTP-Server'); - self::$IMAPServerType['defaultimap']['description'] = lang('standard IMAP Server'); - if ($_restoreSesssion) // && !(is_array(self::$sessionData) && (count(self::$sessionData)>0)) ) - { - $this->restoreSessionData(); - } - if ($_restoreSesssion===false) // && (is_array(self::$sessionData) && (count(self::$sessionData)>0)) ) - { - // make sure session data will be created new - self::$sessionData = array(); - self::saveSessionData(); - } - #_debug_array(self::$sessionData); - if($_profileID >= 0) - { - $this->profileID = $_profileID; - - $this->profileData = $this->getProfile($_profileID); - - // try autoloading class, if that fails include it from emailadmin - if (!class_exists($class = self::$IMAPServerType[$this->profileData['imapType']]['classname'])) - { - include_once(EGW_INCLUDE_ROOT.'/emailadmin/inc/class.'.$class.'.inc.php'); - } - $this->imapClass = new $class; - - if (!class_exists($class = self::$SMTPServerType[$this->profileData['smtpType']]['classname'])) - { - include_once(EGW_INCLUDE_ROOT.'/emailadmin/inc/class.'.$class.'.inc.php'); - } - $this->smtpClass = new $class; - } + $GLOBALS['emailadmin_bo'] = $this; } - - function addAccount($_hookValues) + $this->soemailadmin = new emailadmin_so(); + //translate the standard entry description + self::$SMTPServerType['defaultsmtp']['description'] = lang('standard SMTP-Server'); + self::$IMAPServerType['defaultimap']['description'] = lang('standard IMAP Server'); + if ($_restoreSesssion) // && !(is_array(self::$sessionData) && (count(self::$sessionData)>0)) ) { - if (is_object($this->imapClass)) - { - #ExecMethod("emailadmin.".$this->imapClass.".addAccount",$_hookValues,3,$this->profileData); - $this->imapClass->addAccount($_hookValues); - } - - if (is_object($this->smtpClass)) - { - #ExecMethod("emailadmin.".$this->smtpClass.".addAccount",$_hookValues,3,$this->profileData); - $this->smtpClass->addAccount($_hookValues); - } - self::$sessionData =array(); - $this->saveSessionData(); + $this->restoreSessionData(); } - - function deleteAccount($_hookValues) + if ($_restoreSesssion===false) // && (is_array(self::$sessionData) && (count(self::$sessionData)>0)) ) { - if (is_object($this->imapClass)) - { - #ExecMethod("emailadmin.".$this->imapClass.".deleteAccount",$_hookValues,3,$this->profileData); - $this->imapClass->deleteAccount($_hookValues); - } - - if (is_object($this->smtpClass)) - { - #ExecMethod("emailadmin.".$this->smtpClass.".deleteAccount",$_hookValues,3,$this->profileData); - $this->smtpClass->deleteAccount($_hookValues); - } + // make sure session data will be created new self::$sessionData = array(); - $this->saveSessionData(); + self::saveSessionData(); } - - function getAccountEmailAddress($_accountName, $_profileID) + #_debug_array(self::$sessionData); + if($_profileID >= 0) { - $profileData = $this->getProfile($_profileID); + $this->profileID = $_profileID; - #$smtpClass = self::$SMTPServerType[$profileData['smtpType']]['classname']; - $smtpClass = CreateObject('emailadmin.'.self::$SMTPServerType[$profileData['smtpType']]['classname']); + $this->profileData = $this->getProfile($_profileID); - #return empty($smtpClass) ? False : ExecMethod("emailadmin.$smtpClass.getAccountEmailAddress",$_accountName,3,$profileData); - return is_object($smtpClass) ? $smtpClass->getAccountEmailAddress($_accountName) : False; - } - - function getFieldNames($_serverTypeID, $_class) - { - switch($_class) + // try autoloading class, if that fails include it from emailadmin + if (!class_exists($class = self::$IMAPServerType[$this->profileData['imapType']]['classname'])) { - case 'imap': - return self::$IMAPServerType[$_serverTypeID]['fieldNames']; - break; - case 'smtp': - return self::$SMTPServerType[$_serverTypeID]['fieldNames']; + include_once(EGW_INCLUDE_ROOT.'/emailadmin/inc/class.'.$class.'.inc.php'); + } + $this->imapClass = new $class; + + if (!class_exists($class = self::$SMTPServerType[$this->profileData['smtpType']]['classname'])) + { + include_once(EGW_INCLUDE_ROOT.'/emailadmin/inc/class.'.$class.'.inc.php'); + } + $this->smtpClass = new $class; + } + } + + function addAccount($_hookValues) + { + if (is_object($this->imapClass)) + { + #ExecMethod("emailadmin.".$this->imapClass.".addAccount",$_hookValues,3,$this->profileData); + $this->imapClass->addAccount($_hookValues); + } + + if (is_object($this->smtpClass)) + { + #ExecMethod("emailadmin.".$this->smtpClass.".addAccount",$_hookValues,3,$this->profileData); + $this->smtpClass->addAccount($_hookValues); + } + self::$sessionData =array(); + $this->saveSessionData(); + } + + function deleteAccount($_hookValues) + { + if (is_object($this->imapClass)) + { + #ExecMethod("emailadmin.".$this->imapClass.".deleteAccount",$_hookValues,3,$this->profileData); + $this->imapClass->deleteAccount($_hookValues); + } + + if (is_object($this->smtpClass)) + { + #ExecMethod("emailadmin.".$this->smtpClass.".deleteAccount",$_hookValues,3,$this->profileData); + $this->smtpClass->deleteAccount($_hookValues); + } + self::$sessionData = array(); + $this->saveSessionData(); + } + + function getAccountEmailAddress($_accountName, $_profileID) + { + $profileData = $this->getProfile($_profileID); + + #$smtpClass = self::$SMTPServerType[$profileData['smtpType']]['classname']; + $smtpClass = CreateObject('emailadmin.'.self::$SMTPServerType[$profileData['smtpType']]['classname']); + + #return empty($smtpClass) ? False : ExecMethod("emailadmin.$smtpClass.getAccountEmailAddress",$_accountName,3,$profileData); + return is_object($smtpClass) ? $smtpClass->getAccountEmailAddress($_accountName) : False; + } + + function getFieldNames($_serverTypeID, $_class) + { + switch($_class) + { + case 'imap': + return self::$IMAPServerType[$_serverTypeID]['fieldNames']; + break; + case 'smtp': + return self::$SMTPServerType[$_serverTypeID]['fieldNames']; + break; + } + } + + function getLDAPStorageData($_serverid) + { + $storageData = $this->soemailadmin->getLDAPStorageData($_serverid); + return $storageData; + } + + function getMailboxString($_folderName) + { + if (is_object($this->imapClass)) + { + return ExecMethod("emailadmin.".$this->imapClass.".getMailboxString",$_folderName,3,$this->profileData); + return $this->imapClass->getMailboxString($_folderName); + } + else + { + return false; + } + } + + function getProfile($_profileID) + { + if (!(is_array(self::$sessionData) && (count(self::$sessionData)>0))) $this->restoreSessionData(); + if (is_array(self::$sessionData) && (count(self::$sessionData)>0) && self::$sessionData['profile'][$_profileID]) { + #error_log("sessionData Restored for Profile $_profileID
"); + return self::$sessionData['profile'][$_profileID]; + } + $profileData = $this->soemailadmin->getProfileList($_profileID); + $found = false; + if (is_array($profileData) && count($profileData)) + { + foreach($profileData as $n => $data) + { + if ($data['ProfileID'] == $_profileID) + { + $found = $n; break; + } } } - - function getLDAPStorageData($_serverid) + if ($found === false) // no existing profile selected { - $storageData = $this->soemailadmin->getLDAPStorageData($_serverid); - return $storageData; + if (is_array($profileData) && count($profileData)) { // if we have a profile use that + reset($profileData); + list($found,$data) = each($profileData); + $this->profileID = $_profileID = $data['profileID']; + } elseif ($GLOBALS['egw_info']['server']['smtp_server']) { // create a default profile, from the data in the api config + $this->profileID = $_profileID = $this->soemailadmin->addProfile(array( + 'description' => $GLOBALS['egw_info']['server']['smtp_server'], + 'defaultDomain' => $GLOBALS['egw_info']['server']['mail_suffix'], + 'organisationName' => '', + 'userDefinedAccounts' => '', + 'userDefinedIdentities' => '', + ),array( + 'smtpServer' => $GLOBALS['egw_info']['server']['smtp_server'], + 'smtpPort' => $GLOBALS['egw_info']['server']['smtp_port'], + 'smtpAuth' => '', + 'smtpType' => 'defaultsmtp', + ),array( + 'imapServer' => $GLOBALS['egw_info']['server']['mail_server'] ? + $GLOBALS['egw_info']['server']['mail_server'] : $GLOBALS['egw_info']['server']['smtp_server'], + 'imapPort' => '143', + 'imapType' => 'defaultimap', // imap + 'imapLoginType' => $GLOBALS['egw_info']['server']['mail_login_type'] ? + $GLOBALS['egw_info']['server']['mail_login_type'] : 'standard', + 'imapTLSEncryption' => '0', + 'imapTLSAuthentication' => '', + )); + $profileData[$found = 0] = array( + 'smtpType' => 'defaultsmtp', + 'imapType' => 'defaultimap', + ); + } } - - function getMailboxString($_folderName) + $fieldNames = array(); + if (isset($profileData[$found])) { - if (is_object($this->imapClass)) + $fieldNames = array_merge(self::$SMTPServerType[$profileData[$found]['smtpType']]['fieldNames'], + self::$IMAPServerType[$profileData[$found]['imapType']]['fieldNames']); + } + $fieldNames[] = 'description'; + $fieldNames[] = 'defaultDomain'; + $fieldNames[] = 'profileID'; + $fieldNames[] = 'organisationName'; + $fieldNames[] = 'userDefinedAccounts'; + $fieldNames[] = 'userDefinedIdentities'; + $fieldNames[] = 'ea_appname'; + $fieldNames[] = 'ea_group'; + $fieldNames[] = 'ea_user'; + $fieldNames[] = 'ea_active'; + $fieldNames[] = 'ea_user_defined_signatures'; + $fieldNames[] = 'ea_default_signature'; + $fieldNames[] = 'ea_stationery_active_templates'; + + $profileData = $this->soemailadmin->getProfile($_profileID, $fieldNames); + $profileData['imapTLSEncryption'] = ($profileData['imapTLSEncryption'] == 'yes' ? 1 : (int)$profileData['imapTLSEncryption']); + if(strlen($profileData['ea_stationery_active_templates']) > 0) + { + $profileData['ea_stationery_active_templates'] = unserialize($profileData['ea_stationery_active_templates']); + } + self::$sessionData['profile'][$_profileID] = $profileData; + $this->saveSessionData(); + return $profileData; + } + + function getProfileList($_profileID='',$_appName=false,$_groupID=false,$_accountID=false) + { + if ($_appName!==false ||$_groupID!==false ||$_accountID!==false) { + return $this->soemailadmin->getProfileList($_profileID,false,$_appName,$_groupID,$_accountID); + } else { + return $this->soemailadmin->getProfileList($_profileID); + } + } + + /** + * Get a list of supported SMTP servers + * + * Calls hook "smtp_server_types" to allow applications to supply own server-types + * + * @return array classname => label pairs + */ + static public function getSMTPServerTypes() + { + $retData = array(); + foreach(self::$SMTPServerType as $key => $value) + { + $retData[$key] = $value['description']; + } + foreach($GLOBALS['egw']->hooks->process('smtp_server_types',array(),true) as $app => $data) + { + if ($data) $retData += $data; + } + return $retData; + } + + /** + * Get a list of supported SMTP servers + * + * Calls hook "imap_server_types" to allow applications to supply own server-types + * + * @param boolean $extended=true + * @return array classname => label pairs + */ + static public function getIMAPServerTypes($extended=true) + { + $retData = array(); + foreach(self::$IMAPServerType as $key => $value) + { + if ($extended) { - return ExecMethod("emailadmin.".$this->imapClass.".getMailboxString",$_folderName,3,$this->profileData); - return $this->imapClass->getMailboxString($_folderName); + $retData[$key]['description'] = $value['description']; + $retData[$key]['protocol'] = $value['protocol']; } else { - return false; + $retData[$key] = $value['description']; } } - - function getProfile($_profileID) + foreach($GLOBALS['egw']->hooks->process(array( + 'location' => 'imap_server_types', + 'extended' => $extended, + ),array(),true) as $app => $data) { - if (!(is_array(self::$sessionData) && (count(self::$sessionData)>0))) $this->restoreSessionData(); - if (is_array(self::$sessionData) && (count(self::$sessionData)>0) && self::$sessionData['profile'][$_profileID]) { - #error_log("sessionData Restored for Profile $_profileID
"); - return self::$sessionData['profile'][$_profileID]; - } - $profileData = $this->soemailadmin->getProfileList($_profileID); - $found = false; - if (is_array($profileData) && count($profileData)) + if ($data) $retData += $data; + } + return $retData; + } + + /** + * Get EMailAdmin profile for a user + * + * @param string $_appName='' + * @param int|array $_groups='' + * @return ea_preferences + */ + function getUserProfile($_appName='', $_groups='') + { + if (!(is_array(self::$sessionData) && (count(self::$sessionData)>0))) $this->restoreSessionData(); + if (is_array(self::$sessionData) && count(self::$sessionData)>0 && self::$sessionData['ea_preferences']) + { + //error_log("sessionData Restored for UserProfile
"); + return self::$sessionData['ea_preferences']; + } + $appName = ($_appName != '' ? $_appName : $GLOBALS['egw_info']['flags']['currentapp']); + if(!is_array($_groups)) { + // initialize with 0 => means no group id + $groups = array(0); + // set the second entry to the users primary group + $groups[] = $GLOBALS['egw_info']['user']['account_primary_group']; + $userGroups = $GLOBALS['egw']->accounts->membership($GLOBALS['egw_info']['user']['account_id']); + foreach((array)$userGroups as $groupInfo) { + $groups[] = $groupInfo['account_id']; + } + } else { + $groups = $_groups; + } + + if($data = $this->soemailadmin->getUserProfile($appName, $groups,$GLOBALS['egw_info']['user']['account_id'])) + { + $eaPreferences = CreateObject('emailadmin.ea_preferences'); + + // fetch the IMAP / incomming server data + if (!class_exists($icClass=$data['imapType'])) { - foreach($profileData as $n => $data) + if (!file_exists($file=EGW_INCLUDE_ROOT.'/emailadmin/inc/class.'.$icClass.'.inc.php')) { - if ($data['ProfileID'] == $_profileID) + $file = EGW_INCLUDE_ROOT.'/emailadmin/inc/class.'.($icClass='defaultimap').'.inc.php'; + } + include_once($file); + } + $icServer = new $icClass; + $icServer->encryption = ($data['imapTLSEncryption'] == 'yes' ? 1 : (int)$data['imapTLSEncryption']); + $icServer->host = $data['imapServer']; + $icServer->port = $data['imapPort']; + $icServer->validatecert = $data['imapTLSAuthentication'] == 'yes'; + $icServer->username = $GLOBALS['egw_info']['user']['account_lid']; + $icServer->password = $GLOBALS['egw_info']['user']['passwd']; + // restore the default loginType and check if there are forced/predefined user access Data ($imapAuthType may be set to admin) + list($data['imapLoginType'],$imapAuthType) = explode('#',$data['imapLoginType'],2); + $icServer->loginType = $data['imapLoginType']; + $icServer->domainName = $data['defaultDomain']; + $icServer->loginName = $data['imapLoginType'] == 'standard' ? $GLOBALS['egw_info']['user']['account_lid'] : $GLOBALS['egw_info']['user']['account_lid'].'@'.$data['defaultDomain']; + $icServer->enableCyrusAdmin = ($data['imapEnableCyrusAdmin'] == 'yes'); + $icServer->adminUsername = $data['imapAdminUsername']; + $icServer->adminPassword = $data['imapAdminPW']; + $icServer->enableSieve = ($data['imapEnableSieve'] == 'yes'); + $icServer->sievePort = $data['imapSievePort']; + if ($imapAuthType == 'admin') { + if (!empty($data['imapAuthUsername'])) $icServer->username = $icServer->loginName = $data['imapAuthUsername']; + if (!empty($data['imapAuthPassword'])) $icServer->password = $data['imapAuthPassword']; + } + if ($imapAuthType == 'email' || $icServer->loginType == 'email') { + $icServer->username = $icServer->loginName = $GLOBALS['egw_info']['user']['account_email']; + } + if (method_exists($icServer,'init')) $icServer->init(); + $eaPreferences->setIncomingServer($icServer); + + // fetch the SMTP / outgoing server data + if (!class_exists($ogClass=$data['smtpType'])) + { + if (!file_exists($file=EGW_INCLUDE_ROOT.'/emailadmin/inc/class.'.$ogClass.'.inc.php')) + { + $file = EGW_INCLUDE_ROOT.'/emailadmin/inc/class.'.($ogClass='defaultsmtp').'.inc.php'; + } + include_once($file); + } + $ogServer = new $ogClass($icServer->domainName); + $ogServer->host = $data['smtpServer']; + $ogServer->port = $data['smtpPort']; + $ogServer->editForwardingAddress = ($data['editforwardingaddress'] == 'yes'); + $ogServer->smtpAuth = $data['smtpAuth'] == 'yes'; + if($ogServer->smtpAuth) { + if(!empty($data['ea_smtp_auth_username'])) { + $ogServer->username = $data['ea_smtp_auth_username']; + } else { + // if we use special logintypes for IMAP, we assume this to be used for SMTP too + if ($imapAuthType == 'email' || $icServer->loginType == 'email') { + $ogServer->username = $GLOBALS['egw_info']['user']['account_email']; + } elseif ($icServer->loginType == 'vmailmgr') { + $ogServer->username = $GLOBALS['egw_info']['user']['account_lid'].'@'.$icServer->domainName; + } else { + $ogServer->username = $GLOBALS['egw_info']['user']['account_lid']; + } + } + if(!empty($data['ea_smtp_auth_password'])) { + $ogServer->password = $data['ea_smtp_auth_password']; + } else { + $ogServer->password = $GLOBALS['egw_info']['user']['passwd']; + } + } + if (method_exists($ogServer,'init')) $ogServer->init(); + $eaPreferences->setOutgoingServer($ogServer); + + foreach($ogServer->getAccountEmailAddress($GLOBALS['egw_info']['user']['account_lid']) as $emailAddresses) + { + $identity = CreateObject('emailadmin.ea_identity'); + $identity->emailAddress = $emailAddresses['address']; + $identity->realName = $emailAddresses['name']; + $identity->default = ($emailAddresses['type'] == 'default'); + $identity->organization = $data['organisationName']; + + $eaPreferences->setIdentity($identity); + } + + $eaPreferences->userDefinedAccounts = ($data['userDefinedAccounts'] == 'yes'); + $eaPreferences->userDefinedIdentities = ($data['userDefinedIdentities'] == 'yes'); + $eaPreferences->ea_user_defined_signatures = ($data['ea_user_defined_signatures'] == 'yes'); + $eaPreferences->ea_default_signature = $data['ea_default_signature']; + if(strlen($data['ea_stationery_active_templates']) > 0) + { + $eaPreferences->ea_stationery_active_templates = unserialize($data['ea_stationery_active_templates']); + } + self::$sessionData['ea_preferences'] = $eaPreferences; + $this->saveSessionData(); + return $eaPreferences; + } + + return false; + } + + function getUserData($_accountID) + { + + if($userProfile = $this->getUserProfile('felamimail')) { + $icServer = $userProfile->getIncomingServer(0); + if(is_a($icServer, 'defaultimap') && $username = $GLOBALS['egw']->accounts->id2name($_accountID)) { + $icUserData = $icServer->getUserData($username); + } + + $ogServer = $userProfile->getOutgoingServer(0); + if(is_a($ogServer, 'defaultsmtp')) { + $ogUserData = $ogServer->getUserData($_accountID); + } + + return (array)$icUserData + (array)$ogUserData; + + } + + return false; + } + + function restoreSessionData() + { + $GLOBALS['egw_info']['flags']['autoload'] = array(__CLASS__,'autoload'); + + //echo function_backtrace()."
"; + //unserializing the sessiondata, since they are serialized for objects sake + self::$sessionData = (array) unserialize($GLOBALS['egw']->session->appsession('session_data','emailadmin')); + } + + /** + * Autoload classes from emailadmin, 'til they get autoloading conform names + * + * @param string $class + */ + static function autoload($class) + { + if (file_exists($file=EGW_INCLUDE_ROOT.'/emailadmin/inc/class.'.$class.'.inc.php')) + { + include_once($file); + } + } + + function saveSMTPForwarding($_accountID, $_forwardingAddress, $_keepLocalCopy) + { + if (is_object($this->smtpClass)) + { + #$smtpClass = CreateObject('emailadmin.'.$this->smtpClass,$this->profileID); + #$smtpClass->saveSMTPForwarding($_accountID, $_forwardingAddress, $_keepLocalCopy); + $this->smtpClass->saveSMTPForwarding($_accountID, $_forwardingAddress, $_keepLocalCopy); + } + + } + + /** + * called by the validation hook in setup + * + * @param array $settings following keys: mail_server, mail_server_type {IMAP|IMAPS|POP-3|POP-3S}, + * mail_login_type {standard|vmailmgr}, mail_suffix (domain), smtp_server, smpt_port, smtp_auth_user, smtp_auth_passwd + */ + function setDefaultProfile($settings) + { + if (($profiles = $this->soemailadmin->getProfileList(0,true))) + { + $profile = array_shift($profiles); + } + else + { + $profile = array( + 'smtpType' => 'defaultsmtp', + 'description' => 'default profile (created by setup)', + 'ea_appname' => '', + 'ea_group' => 0, + 'ea_user' => 0, + 'ea_active' => 1, + ); + + if (empty($settings['mail_server'])) $profile['userDefinedAccounts'] = 'yes'; + if (empty($settings['mail_server'])) $profile['userDefinedIdentities'] == 'yes'; + if (empty($settings['mail_server'])) $profile['ea_user_defined_signatures'] == 'yes'; + + } + foreach($to_parse = array( + 'mail_server' => 'imapServer', + 'mail_server_type' => array( + 'imap' => array( + 'imapType' => 'defaultimap', + 'imapPort' => 143, + 'imapTLSEncryption' => 0, + ), + 'imaps' => array( + 'imapType' => 'defaultimap', + 'imapPort' => 993, + 'imapTLSEncryption' => '3', + ), + ), + 'mail_login_type' => 'imapLoginType', + 'mail_suffix' => 'defaultDomain', + 'smtp_server' => 'smtpServer', + 'smpt_port' => 'smtpPort', + 'smtp_auth_user' => 'ea_smtp_auth_username', + 'smtp_auth_passwd' => 'ea_smtp_auth_password', + ) as $setup_name => $ea_name_data) + { + if (!is_array($ea_name_data)) + { + $profile[$ea_name_data] = $settings[$setup_name]; + if ($setup_name == 'smtp_auth_user') $profile['stmpAuth'] = !empty($settings['smtp_auth_user']); + } + else + { + foreach($ea_name_data as $setup_val => $ea_data) + { + if ($setup_val == $settings[$setup_name]) { - $found = $n; + foreach($ea_data as $var => $val) + { + if ($var != 'imapType' || $val != 'defaultimap') // old code: || $profile[$var] < 3) // dont kill special imap server types + { + $profile[$var] = $val; + } + } break; } } } - if ($found === false) // no existing profile selected - { - if (is_array($profileData) && count($profileData)) { // if we have a profile use that - reset($profileData); - list($found,$data) = each($profileData); - $this->profileID = $_profileID = $data['profileID']; - } elseif ($GLOBALS['egw_info']['server']['smtp_server']) { // create a default profile, from the data in the api config - $this->profileID = $_profileID = $this->soemailadmin->addProfile(array( - 'description' => $GLOBALS['egw_info']['server']['smtp_server'], - 'defaultDomain' => $GLOBALS['egw_info']['server']['mail_suffix'], - 'organisationName' => '', - 'userDefinedAccounts' => '', - 'userDefinedIdentities' => '', - ),array( - 'smtpServer' => $GLOBALS['egw_info']['server']['smtp_server'], - 'smtpPort' => $GLOBALS['egw_info']['server']['smtp_port'], - 'smtpAuth' => '', - 'smtpType' => 'defaultsmtp', - ),array( - 'imapServer' => $GLOBALS['egw_info']['server']['mail_server'] ? - $GLOBALS['egw_info']['server']['mail_server'] : $GLOBALS['egw_info']['server']['smtp_server'], - 'imapPort' => '143', - 'imapType' => 'defaultimap', // imap - 'imapLoginType' => $GLOBALS['egw_info']['server']['mail_login_type'] ? - $GLOBALS['egw_info']['server']['mail_login_type'] : 'standard', - 'imapTLSEncryption' => '0', - 'imapTLSAuthentication' => '', - )); - $profileData[$found = 0] = array( - 'smtpType' => 'defaultsmtp', - 'imapType' => 'defaultimap', - ); - } - } - $fieldNames = array(); - if (isset($profileData[$found])) - { - $fieldNames = array_merge(self::$SMTPServerType[$profileData[$found]['smtpType']]['fieldNames'], - self::$IMAPServerType[$profileData[$found]['imapType']]['fieldNames']); - } - $fieldNames[] = 'description'; - $fieldNames[] = 'defaultDomain'; - $fieldNames[] = 'profileID'; - $fieldNames[] = 'organisationName'; - $fieldNames[] = 'userDefinedAccounts'; - $fieldNames[] = 'userDefinedIdentities'; - $fieldNames[] = 'ea_appname'; - $fieldNames[] = 'ea_group'; - $fieldNames[] = 'ea_user'; - $fieldNames[] = 'ea_active'; - $fieldNames[] = 'ea_user_defined_signatures'; - $fieldNames[] = 'ea_default_signature'; - $fieldNames[] = 'ea_stationery_active_templates'; - - $profileData = $this->soemailadmin->getProfile($_profileID, $fieldNames); - $profileData['imapTLSEncryption'] = ($profileData['imapTLSEncryption'] == 'yes' ? 1 : (int)$profileData['imapTLSEncryption']); - if(strlen($profileData['ea_stationery_active_templates']) > 0) - { - $profileData['ea_stationery_active_templates'] = unserialize($profileData['ea_stationery_active_templates']); - } - self::$sessionData['profile'][$_profileID] = $profileData; - $this->saveSessionData(); - return $profileData; } + // merge the other not processed values unchanged + $profile = array_merge($profile,array_diff_assoc($settings,$to_parse)); - function getProfileList($_profileID='',$_appName=false,$_groupID=false,$_accountID=false) - { - if ($_appName!==false ||$_groupID!==false ||$_accountID!==false) { - return $this->soemailadmin->getProfileList($_profileID,false,$_appName,$_groupID,$_accountID); - } else { - return $this->soemailadmin->getProfileList($_profileID); - } - } - - /** - * Get a list of supported SMTP servers - * - * Calls hook "smtp_server_types" to allow applications to supply own server-types - * - * @return array classname => label pairs - */ - static public function getSMTPServerTypes() - { - $retData = array(); - foreach(self::$SMTPServerType as $key => $value) - { - $retData[$key] = $value['description']; - } - foreach($GLOBALS['egw']->hooks->process('smtp_server_types',array(),true) as $app => $data) - { - if ($data) $retData += $data; - } - return $retData; - } - - /** - * Get a list of supported SMTP servers - * - * Calls hook "imap_server_types" to allow applications to supply own server-types - * - * @param boolean $extended=true - * @return array classname => label pairs - */ - static public function getIMAPServerTypes($extended=true) - { - $retData = array(); - foreach(self::$IMAPServerType as $key => $value) - { - if ($extended) - { - $retData[$key]['description'] = $value['description']; - $retData[$key]['protocol'] = $value['protocol']; - } - else - { - $retData[$key] = $value['description']; - } - } - foreach($GLOBALS['egw']->hooks->process(array( - 'location' => 'imap_server_types', - 'extended' => $extended, - ),array(),true) as $app => $data) - { - if ($data) $retData += $data; - } - return $retData; - } - - /** - * Get EMailAdmin profile for a user - * - * @param string $_appName='' - * @param int|array $_groups='' - * @return ea_preferences - */ - function getUserProfile($_appName='', $_groups='') - { - if (!(is_array(self::$sessionData) && (count(self::$sessionData)>0))) $this->restoreSessionData(); - if (is_array(self::$sessionData) && count(self::$sessionData)>0 && self::$sessionData['ea_preferences']) - { - //error_log("sessionData Restored for UserProfile
"); - return self::$sessionData['ea_preferences']; - } - $appName = ($_appName != '' ? $_appName : $GLOBALS['egw_info']['flags']['currentapp']); - if(!is_array($_groups)) { - // initialize with 0 => means no group id - $groups = array(0); - // set the second entry to the users primary group - $groups[] = $GLOBALS['egw_info']['user']['account_primary_group']; - $userGroups = $GLOBALS['egw']->accounts->membership($GLOBALS['egw_info']['user']['account_id']); - foreach((array)$userGroups as $groupInfo) { - $groups[] = $groupInfo['account_id']; - } - } else { - $groups = $_groups; - } - - if($data = $this->soemailadmin->getUserProfile($appName, $groups,$GLOBALS['egw_info']['user']['account_id'])) - { - $eaPreferences = CreateObject('emailadmin.ea_preferences'); - - // fetch the IMAP / incomming server data - if (!class_exists($icClass=$data['imapType'])) - { - if (!file_exists($file=EGW_INCLUDE_ROOT.'/emailadmin/inc/class.'.$icClass.'.inc.php')) - { - $file = EGW_INCLUDE_ROOT.'/emailadmin/inc/class.'.($icClass='defaultimap').'.inc.php'; - } - include_once($file); - } - $icServer = new $icClass; - $icServer->encryption = ($data['imapTLSEncryption'] == 'yes' ? 1 : (int)$data['imapTLSEncryption']); - $icServer->host = $data['imapServer']; - $icServer->port = $data['imapPort']; - $icServer->validatecert = $data['imapTLSAuthentication'] == 'yes'; - $icServer->username = $GLOBALS['egw_info']['user']['account_lid']; - $icServer->password = $GLOBALS['egw_info']['user']['passwd']; - // restore the default loginType and check if there are forced/predefined user access Data ($imapAuthType may be set to admin) - list($data['imapLoginType'],$imapAuthType) = explode('#',$data['imapLoginType'],2); - $icServer->loginType = $data['imapLoginType']; - $icServer->domainName = $data['defaultDomain']; - $icServer->loginName = $data['imapLoginType'] == 'standard' ? $GLOBALS['egw_info']['user']['account_lid'] : $GLOBALS['egw_info']['user']['account_lid'].'@'.$data['defaultDomain']; - $icServer->enableCyrusAdmin = ($data['imapEnableCyrusAdmin'] == 'yes'); - $icServer->adminUsername = $data['imapAdminUsername']; - $icServer->adminPassword = $data['imapAdminPW']; - $icServer->enableSieve = ($data['imapEnableSieve'] == 'yes'); - $icServer->sievePort = $data['imapSievePort']; - if ($imapAuthType == 'admin') { - if (!empty($data['imapAuthUsername'])) $icServer->username = $icServer->loginName = $data['imapAuthUsername']; - if (!empty($data['imapAuthPassword'])) $icServer->password = $data['imapAuthPassword']; - } - if ($imapAuthType == 'email' || $icServer->loginType == 'email') { - $icServer->username = $icServer->loginName = $GLOBALS['egw_info']['user']['account_email']; - } - if (method_exists($icServer,'init')) $icServer->init(); - $eaPreferences->setIncomingServer($icServer); - - // fetch the SMTP / outgoing server data - if (!class_exists($ogClass=$data['smtpType'])) - { - if (!file_exists($file=EGW_INCLUDE_ROOT.'/emailadmin/inc/class.'.$ogClass.'.inc.php')) - { - $file = EGW_INCLUDE_ROOT.'/emailadmin/inc/class.'.($ogClass='defaultsmtp').'.inc.php'; - } - include_once($file); - } - $ogServer = new $ogClass($icServer->domainName); - $ogServer->host = $data['smtpServer']; - $ogServer->port = $data['smtpPort']; - $ogServer->editForwardingAddress = ($data['editforwardingaddress'] == 'yes'); - $ogServer->smtpAuth = $data['smtpAuth'] == 'yes'; - if($ogServer->smtpAuth) { - if(!empty($data['ea_smtp_auth_username'])) { - $ogServer->username = $data['ea_smtp_auth_username']; - } else { - // if we use special logintypes for IMAP, we assume this to be used for SMTP too - if ($imapAuthType == 'email' || $icServer->loginType == 'email') { - $ogServer->username = $GLOBALS['egw_info']['user']['account_email']; - } elseif ($icServer->loginType == 'vmailmgr') { - $ogServer->username = $GLOBALS['egw_info']['user']['account_lid'].'@'.$icServer->domainName; - } else { - $ogServer->username = $GLOBALS['egw_info']['user']['account_lid']; - } - } - if(!empty($data['ea_smtp_auth_password'])) { - $ogServer->password = $data['ea_smtp_auth_password']; - } else { - $ogServer->password = $GLOBALS['egw_info']['user']['passwd']; - } - } - if (method_exists($ogServer,'init')) $ogServer->init(); - $eaPreferences->setOutgoingServer($ogServer); - - foreach($ogServer->getAccountEmailAddress($GLOBALS['egw_info']['user']['account_lid']) as $emailAddresses) - { - $identity = CreateObject('emailadmin.ea_identity'); - $identity->emailAddress = $emailAddresses['address']; - $identity->realName = $emailAddresses['name']; - $identity->default = ($emailAddresses['type'] == 'default'); - $identity->organization = $data['organisationName']; - - $eaPreferences->setIdentity($identity); - } - - $eaPreferences->userDefinedAccounts = ($data['userDefinedAccounts'] == 'yes'); - $eaPreferences->userDefinedIdentities = ($data['userDefinedIdentities'] == 'yes'); - $eaPreferences->ea_user_defined_signatures = ($data['ea_user_defined_signatures'] == 'yes'); - $eaPreferences->ea_default_signature = $data['ea_default_signature']; - if(strlen($data['ea_stationery_active_templates']) > 0) - { - $eaPreferences->ea_stationery_active_templates = unserialize($data['ea_stationery_active_templates']); - } - self::$sessionData['ea_preferences'] = $eaPreferences; - $this->saveSessionData(); - return $eaPreferences; - } - - return false; - } - - function getUserData($_accountID) - { - - if($userProfile = $this->getUserProfile('felamimail')) { - $icServer = $userProfile->getIncomingServer(0); - if(is_a($icServer, 'defaultimap') && $username = $GLOBALS['egw']->accounts->id2name($_accountID)) { - $icUserData = $icServer->getUserData($username); - } - - $ogServer = $userProfile->getOutgoingServer(0); - if(is_a($ogServer, 'defaultsmtp')) { - $ogUserData = $ogServer->getUserData($_accountID); - } - - return (array)$icUserData + (array)$ogUserData; - - } - - return false; - } - - function restoreSessionData() - { - $GLOBALS['egw_info']['flags']['autoload'] = array(__CLASS__,'autoload'); - - //echo function_backtrace()."
"; - //unserializing the sessiondata, since they are serialized for objects sake - self::$sessionData = (array) unserialize($GLOBALS['egw']->session->appsession('session_data','emailadmin')); - } - - /** - * Autoload classes from emailadmin, 'til they get autoloading conform names - * - * @param string $class - */ - static function autoload($class) - { - if (file_exists($file=EGW_INCLUDE_ROOT.'/emailadmin/inc/class.'.$class.'.inc.php')) - { - include_once($file); - } - } - - function saveSMTPForwarding($_accountID, $_forwardingAddress, $_keepLocalCopy) - { - if (is_object($this->smtpClass)) - { - #$smtpClass = CreateObject('emailadmin.'.$this->smtpClass,$this->profileID); - #$smtpClass->saveSMTPForwarding($_accountID, $_forwardingAddress, $_keepLocalCopy); - $this->smtpClass->saveSMTPForwarding($_accountID, $_forwardingAddress, $_keepLocalCopy); - } - - } - - /** - * called by the validation hook in setup - * - * @param array $settings following keys: mail_server, mail_server_type {IMAP|IMAPS|POP-3|POP-3S}, - * mail_login_type {standard|vmailmgr}, mail_suffix (domain), smtp_server, smpt_port, smtp_auth_user, smtp_auth_passwd - */ - function setDefaultProfile($settings) - { - if (($profiles = $this->soemailadmin->getProfileList(0,true))) - { - $profile = array_shift($profiles); - } - else - { - $profile = array( - 'smtpType' => 'defaultsmtp', - 'description' => 'default profile (created by setup)', - 'ea_appname' => '', - 'ea_group' => 0, - 'ea_user' => 0, - 'ea_active' => 1, - ); - - if (empty($settings['mail_server'])) $profile['userDefinedAccounts'] = 'yes'; - if (empty($settings['mail_server'])) $profile['userDefinedIdentities'] == 'yes'; - if (empty($settings['mail_server'])) $profile['ea_user_defined_signatures'] == 'yes'; - - } - foreach($to_parse = array( - 'mail_server' => 'imapServer', - 'mail_server_type' => array( - 'imap' => array( - 'imapType' => 'defaultimap', - 'imapPort' => 143, - 'imapTLSEncryption' => 0, - ), - 'imaps' => array( - 'imapType' => 'defaultimap', - 'imapPort' => 993, - 'imapTLSEncryption' => '3', - ), - ), - 'mail_login_type' => 'imapLoginType', - 'mail_suffix' => 'defaultDomain', - 'smtp_server' => 'smtpServer', - 'smpt_port' => 'smtpPort', - 'smtp_auth_user' => 'ea_smtp_auth_username', - 'smtp_auth_passwd' => 'ea_smtp_auth_password', - ) as $setup_name => $ea_name_data) - { - if (!is_array($ea_name_data)) - { - $profile[$ea_name_data] = $settings[$setup_name]; - if ($setup_name == 'smtp_auth_user') $profile['stmpAuth'] = !empty($settings['smtp_auth_user']); - } - else - { - foreach($ea_name_data as $setup_val => $ea_data) - { - if ($setup_val == $settings[$setup_name]) - { - foreach($ea_data as $var => $val) - { - if ($var != 'imapType' || $val != 'defaultimap') // old code: || $profile[$var] < 3) // dont kill special imap server types - { - $profile[$var] = $val; - } - } - break; - } - } - } - } - // merge the other not processed values unchanged - $profile = array_merge($profile,array_diff_assoc($settings,$to_parse)); - - $this->soemailadmin->updateProfile($profile); - self::$sessionData['profile'] = array(); - $this->saveSessionData(); - //echo "

EMailAdmin profile update: ".print_r($profile,true)."

\n"; exit; - } - - function saveProfile($_globalSettings, $_smtpSettings, $_imapSettings) - { - if(!isset($_imapSettings['imapTLSAuthentication'])) { - $_imapSettings['imapTLSAuthentication'] = true; - } - - if(is_array($_globalSettings['ea_stationery_active_templates']) && count($_globalSettings['ea_stationery_active_templates']) > 0) - { - $_globalSettings['ea_stationery_active_templates'] = serialize($_globalSettings['ea_stationery_active_templates']); - } - else - { - $_globalSettings['ea_stationery_active_templates'] = null; - } - - if(!isset($_globalSettings['profileID'])) { - $_globalSettings['ea_order'] = count($this->getProfileList()) + 1; - $this->soemailadmin->addProfile($_globalSettings, $_smtpSettings, $_imapSettings); - } else { - $this->soemailadmin->updateProfile($_globalSettings, $_smtpSettings, $_imapSettings); - } - $all = $_globalSettings+$_smtpSettings+$_imapSettings; - if (!$all['ea_user'] && !$all['ea_group'] && !$all['ea_application']) // standard profile update eGW config - { - $new_config = array(); - foreach(array( - 'imapServer' => 'mail_server', - 'imapType' => 'mail_server_type', - 'imapLoginType' => 'mail_login_type', - 'defaultDomain' => 'mail_suffix', - 'smtpServer' => 'smtp_server', - 'smtpPort' => 'smpt_port', - )+($all['smtpAuth'] ? array( - 'ea_smtp_auth_username' => 'smtp_auth_user', - 'ea_smtp_auth_password' => 'smtp_auth_passwd', - ) : array()) as $ea_name => $config_name) - { - if (isset($all[$ea_name])) - { - if ($ea_name != 'imapType') - { - $new_config[$config_name] = $all[$ea_name]; - } - else // imap type, no pop3 code anymore - { - $new_config[$config_name] = 'imap'.($all['imapTLSEncryption'] ? 's' : ''); - } - } - } - if (count($new_config)) - { - $config = CreateObject('phpgwapi.config','phpgwapi'); - - foreach($new_config as $name => $value) - { - $config->save_value($name,$value,'phpgwapi'); - } - //echo "

eGW configuration update: ".print_r($new_config,true)."

\n"; - } - } - self::$sessionData = array(); - $this->saveSessionData(); - } - - function saveSessionData() - { - // serializing the session data, for the sake of objects - if (is_object($GLOBALS['egw']->session)) // otherwise setup(-cli) fails - { - $GLOBALS['egw']->session->appsession('session_data','emailadmin',serialize(self::$sessionData)); - } - #$GLOBALS['egw']->session->appsession('user_session_data','',$this->userSessionData); - } - - function saveUserData($_accountID, $_formData) { - - if($userProfile = $this->getUserProfile('felamimail')) { - $ogServer = $userProfile->getOutgoingServer(0); - if(is_a($ogServer, 'defaultsmtp')) { - $ogServer->setUserData($_accountID, - (array)$_formData['mailAlternateAddress'], - (array)$_formData['mailForwardingAddress'], - $_formData['deliveryMode'], - $_formData['accountStatus'], - $_formData['mailLocalAddress'] - ); - } - - $icServer = $userProfile->getIncomingServer(0); - if(is_a($icServer, 'defaultimap') && $username = $GLOBALS['egw']->accounts->id2name($_accountID)) { - $icServer->setUserData($username, $_formData['quotaLimit']); - } - - // calling a hook to allow other apps to monitor the changes - $_formData['account_id'] = $_accountID; - $_formData['location'] = 'editaccountemail'; - $GLOBALS['egw']->hooks->process($_formData); - - return true; - self::$sessionData = array(); - $this->saveSessionData(); - } - - return false; - } - - function setOrder($_order) { - if(is_array($_order)) { - $this->soemailadmin->setOrder($_order); - } - self::$sessionData = array(); - $this->saveSessionData(); - } - - function updateAccount($_hookValues) { - if (is_object($this->imapClass)) { - #ExecMethod("emailadmin.".$this->imapClass.".updateAccount",$_hookValues,3,$this->profileData); - $this->imapClass->updateAccount($_hookValues); - } - - if (is_object($this->smtpClass)) { - #ExecMethod("emailadmin.".$this->smtpClass.".updateAccount",$_hookValues,3,$this->profileData); - $this->smtpClass->updateAccount($_hookValues); - } - self::$sessionData = array(); - $this->saveSessionData(); - } + $this->soemailadmin->updateProfile($profile); + self::$sessionData['profile'] = array(); + $this->saveSessionData(); + //echo "

EMailAdmin profile update: ".print_r($profile,true)."

\n"; exit; } + + function saveProfile($_globalSettings, $_smtpSettings, $_imapSettings) + { + if(!isset($_imapSettings['imapTLSAuthentication'])) { + $_imapSettings['imapTLSAuthentication'] = true; + } + + if(is_array($_globalSettings['ea_stationery_active_templates']) && count($_globalSettings['ea_stationery_active_templates']) > 0) + { + $_globalSettings['ea_stationery_active_templates'] = serialize($_globalSettings['ea_stationery_active_templates']); + } + else + { + $_globalSettings['ea_stationery_active_templates'] = null; + } + + if(!isset($_globalSettings['profileID'])) { + $_globalSettings['ea_order'] = count($this->getProfileList()) + 1; + $this->soemailadmin->addProfile($_globalSettings, $_smtpSettings, $_imapSettings); + } else { + $this->soemailadmin->updateProfile($_globalSettings, $_smtpSettings, $_imapSettings); + } + $all = $_globalSettings+$_smtpSettings+$_imapSettings; + if (!$all['ea_user'] && !$all['ea_group'] && !$all['ea_application']) // standard profile update eGW config + { + $new_config = array(); + foreach(array( + 'imapServer' => 'mail_server', + 'imapType' => 'mail_server_type', + 'imapLoginType' => 'mail_login_type', + 'defaultDomain' => 'mail_suffix', + 'smtpServer' => 'smtp_server', + 'smtpPort' => 'smpt_port', + )+($all['smtpAuth'] ? array( + 'ea_smtp_auth_username' => 'smtp_auth_user', + 'ea_smtp_auth_password' => 'smtp_auth_passwd', + ) : array()) as $ea_name => $config_name) + { + if (isset($all[$ea_name])) + { + if ($ea_name != 'imapType') + { + $new_config[$config_name] = $all[$ea_name]; + } + else // imap type, no pop3 code anymore + { + $new_config[$config_name] = 'imap'.($all['imapTLSEncryption'] ? 's' : ''); + } + } + } + if (count($new_config)) + { + $config = CreateObject('phpgwapi.config','phpgwapi'); + + foreach($new_config as $name => $value) + { + $config->save_value($name,$value,'phpgwapi'); + } + //echo "

eGW configuration update: ".print_r($new_config,true)."

\n"; + } + } + self::$sessionData = array(); + $this->saveSessionData(); + } + + function saveSessionData() + { + // serializing the session data, for the sake of objects + if (is_object($GLOBALS['egw']->session)) // otherwise setup(-cli) fails + { + $GLOBALS['egw']->session->appsession('session_data','emailadmin',serialize(self::$sessionData)); + } + #$GLOBALS['egw']->session->appsession('user_session_data','',$this->userSessionData); + } + + function saveUserData($_accountID, $_formData) { + + if($userProfile = $this->getUserProfile('felamimail')) { + $ogServer = $userProfile->getOutgoingServer(0); + if(is_a($ogServer, 'defaultsmtp')) { + $ogServer->setUserData($_accountID, + (array)$_formData['mailAlternateAddress'], + (array)$_formData['mailForwardingAddress'], + $_formData['deliveryMode'], + $_formData['accountStatus'], + $_formData['mailLocalAddress'] + ); + } + + $icServer = $userProfile->getIncomingServer(0); + if(is_a($icServer, 'defaultimap') && $username = $GLOBALS['egw']->accounts->id2name($_accountID)) { + $icServer->setUserData($username, $_formData['quotaLimit']); + } + + // calling a hook to allow other apps to monitor the changes + $_formData['account_id'] = $_accountID; + $_formData['location'] = 'editaccountemail'; + $GLOBALS['egw']->hooks->process($_formData); + + return true; + self::$sessionData = array(); + $this->saveSessionData(); + } + + return false; + } + + function setOrder($_order) { + if(is_array($_order)) { + $this->soemailadmin->setOrder($_order); + } + self::$sessionData = array(); + $this->saveSessionData(); + } + + function updateAccount($_hookValues) { + if (is_object($this->imapClass)) { + #ExecMethod("emailadmin.".$this->imapClass.".updateAccount",$_hookValues,3,$this->profileData); + $this->imapClass->updateAccount($_hookValues); + } + + if (is_object($this->smtpClass)) { + #ExecMethod("emailadmin.".$this->smtpClass.".updateAccount",$_hookValues,3,$this->profileData); + $this->smtpClass->updateAccount($_hookValues); + } + self::$sessionData = array(); + $this->saveSessionData(); + } +} diff --git a/emailadmin/inc/class.emailadmin_ui.inc.php b/emailadmin/inc/class.emailadmin_ui.inc.php index b100ea5989..137cccf425 100644 --- a/emailadmin/inc/class.emailadmin_ui.inc.php +++ b/emailadmin/inc/class.emailadmin_ui.inc.php @@ -1,962 +1,417 @@ - * @copyright (c) 2009-10 by Klaus Leithoff - * @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License - \***************************************************************************/ - /* $Id$ */ +/** + * EGroupware EMailAdmin: User interface + * + * @link http://www.stylite.de + * @package emailadmin + * @author Klaus Leithoff + * @copyright (c) 2009-10 by Klaus Leithoff + * @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License + * @version $Id$ + */ - class emailadmin_ui extends emailadmin_bo - { - var $public_functions = array - ( - 'index' => True, - 'add' => True, - 'delete' => True, - 'edit' => True, - 'save' => True, - 'listProfiles' => True, - ); - - function __construct() - { - parent::__construct(); - } +/** + * User interface + */ +class emailadmin_ui extends emailadmin_bo +{ + var $public_functions = array + ( + 'index' => True, + 'add' => True, + 'delete' => True, + 'edit' => True, + 'save' => True, + 'listProfiles' => True, + ); + + function __construct() + { + parent::__construct(); + } - /** - * Main emailadmin page - * - * @param array $content=null - * @param string $msg=null - */ - function index(array $content=null,$msg=null) + /** + * Main emailadmin page + * + * @param array $content=null + * @param string $msg=null + */ + function index(array $content=null,$msg=null) + { + $accountID = false; + $groupID = false; + $filter = ''; + $rowsfound = 0; + if(is_int(intval($_GET['account_id'])) && !empty($_GET['account_id'])) { - $accountID = false; - $groupID = false; - $filter = ''; - $rowsfound = 0; - if(is_int(intval($_GET['account_id'])) && !empty($_GET['account_id'])) - { - if ( intval($_GET['account_id']) < 0 ) { - $groupID = intval($_GET['account_id']); - $filter['ea_group'] = intval($_GET['account_id']); - } else { - $accountID = intval($_GET['account_id']); - $filter['ea_user'] = intval($_GET['account_id']); - } - $r = parent::search($filter); - $rowsfound = count($r); - } - if ($rowsfound) - { - if (($accountID || !empty($groupID)) && $rowsfound == 1) - { - $linkData = array - ( - 'menuaction' => 'emailadmin.emailadmin_ui.edit', - 'profileid' => $r[0]['ea_profile_id'] - ); - $addJavaScript = "'; - } + if ( intval($_GET['account_id']) < 0 ) { + $groupID = intval($_GET['account_id']); + $filter['ea_group'] = intval($_GET['account_id']); } else { - if ($accountID || !empty($groupID)) { - $linkData = array - ( - 'menuaction' => 'emailadmin.emailadmin_ui.edit', - 'account_id' => ($accountID ? $accountID : $groupID) - ); - $addJavaScript = "'; - } + $accountID = intval($_GET['account_id']); + $filter['ea_user'] = intval($_GET['account_id']); } + $r = parent::search($filter); + $rowsfound = count($r); + } + if ($rowsfound) + { + if (($accountID || !empty($groupID)) && $rowsfound == 1) + { + $linkData = array + ( + 'menuaction' => 'emailadmin.emailadmin_ui.edit', + 'profileid' => $r[0]['ea_profile_id'] + ); + $addJavaScript = "'; + } + } else { if ($accountID || !empty($groupID)) { $linkData = array ( - 'menuaction' => 'emailadmin.emailadmin_ui.index', + 'menuaction' => 'emailadmin.emailadmin_ui.edit', + 'account_id' => ($accountID ? $accountID : $groupID) ); - $listLink = ''. - lang('reset filter').''; - - if ($GLOBALS['egw_info']['user']['apps']['admin']) { - $linkData = array - ( - 'menuaction' => 'admin.uiaccounts.list_'.($accountID ? 'users' : 'groups'), - ); - $listLink2 = ''.($accountID ? lang('Back to Admin/Userlist'): lang('Back to Admin/Grouplist')).''; - } - unset($r); - $subtitle = ($accountID || !empty($groupID) ? ' '.($accountID ? lang('filtered by Account') : lang('filtered by Group')).' ['.$listLink.']'.' ['.$listLink2.']': ''); + $addJavaScript = "'; } - //_debug_array($content); - $tpl = new etemplate('emailadmin.index'); - if (!is_array($content)) - { - $content = array( - 'nm' => $GLOBALS['egw']->session->appsession('index',parent::APP), - ); - if (!is_array($content['nm'])) - { - $content['nm'] = array( - 'get_rows' => 'emailadmin.emailadmin_ui.get_rows', // I method/callback to request the data for the rows - 'no_filter' => True, // nofilter - 'no_filter2' => True, // I disable the 2. filter (params are the same as for filter) - 'no_cat' => True, // I disable the cat-selectbox - 'lettersearch' => True, // I show a lettersearch - 'searchletter' => false, // I0 active letter of the lettersearch or false for [all] - 'start' => 0, // IO position in list - 'order' => 'ea_order, ea_profile_id', // IO name of the column to sort after (optional for the sortheaders) - 'sort' => 'ASC', // IO direction of the sort: 'ASC' or 'DESC' - //'default_cols' => '!comment,ctime', // I columns to use if there's no user or default pref (! as first char uses all but the columns listed) - 'csv_fields' => false, // I false=disable csv export, true or unset=enable it with auto-detected fieldnames, - //or array with name=>label or name=>array('label'=>label,'type'=>type) pairs (type is a eT widget-type) - ); - } - } - elseif(isset($content['nm']['rows']['delete'])) - { - list($profileids) = each($content['nm']['rows']['delete']); - unset($content['nm']['rows']['delete']); - if ($profileids && self::delete($profileids)) - { - $content['msg'] = lang('%1 entries deleted.',1); - } - else - { - $content['msg'] = lang('Error deleting entry!'); - } - } - elseif(isset($content['delete'])) - { - unset($content['delete']); - if (($deleted = self::delete($content['nm']['rows']['selected']))) - { - $content['msg'] = lang('%1 entries deleted.',$deleted); - } - else - { - $content['msg'] = lang('Error deleting entry!'); - } - } - - if (isset($_GET['msg'])) $msg = $_GET['msg']; - $content['msg'] .= $msg; - /* - if ($content['action'] || $content['nm']['rows']) - { - if ($content['action']) - { - // SOME ACTION AS EDIT, DELETE, ... - $content['msg'] = self::action($content['action'],$content['nm']['rows']['checked']); - unset($content['action']); - } - elseif($content['nm']['rows']['delete']) - { - $content['msg'] = self::action('delete',array_keys($content['nm']['rows']['delete'])); - } - unset($content['nm']['rows']); - } - */ - if ($content['AddProfile']) - { - unset($content['AddProfile']); - } - if ($content['button']) - { - if ($content['button']) - { - list($button) = each($content['button']); - unset($content['button']); - } - switch($button) - { - default: - break; - } - } - $sel_options['ea_smtp_type']=parent::getSMTPServerTypes(); - $sel_options['ea_imap_type']=parent::getIMAPServerTypes(false); - $sel_options['ea_appname'] =self::getAllowedApps(); - // setting for the top of the app, etc. - $content['addJavaScript'] = $addJavaScript; - $content['subtitle'] = $subtitle; - if (!empty($filter)) foreach ($filter as $fk => $fv) $content['nm']['col_filter'][$fk] = $fv; - // seTting the Title of the app - $GLOBALS['egw_info']['flags']['app_header'] = lang('emailadmin'); - $tpl->exec('emailadmin.emailadmin_ui.index',$content,$sel_options,$readonlys,array('nm' => $content['nm'])); } - - /** - * query the table - * - * reimplemented from so_sql to disable action-buttons based on the acl and make some modification on the data - * - * @param array &$query - * @param array &$rows returned rows/cups - * @param array &$readonlys eg. to disable buttons based on acl - * @param boolean $id_only=false if true only return (via $rows) an array of ids, dont save state to session - * @return int total number of rows matching the selection - */ - function get_rows(&$query_in,&$rows,&$readonlys,$id_only=false) - { - $query = $query_in; - $filteredby = ''; - if ($query['searchletter']) // only show rows if the order-criteria starts with the given letter - { - $query['col_filter'][] = (in_array($query['order'],parent::$numericfields) || (is_string($query['order']) && !(strpos($query['order'],',')===false)) ? 'ea_description' : $query['order']).' '. - $GLOBALS['egw']->db->capabilities['case_insensitive_like'].' '.$GLOBALS['egw']->db->quote($query['searchletter'].'%'); - if (in_array($query['order'],parent::$numericfields)) $query_in['order'] = $query['order'] = 'ea_description'; - $filteredby = $query['order'].' '.lang('starts with').' '.$query['searchletter']; - } - $GLOBALS['egw_info']['flags']['app_header'] = lang('emailadmin').($filteredby? ' - '.$filteredby:''); - $total = parent::get_rows($query,$rows,$readonlys); - return $total; - } - - static function getAllowedApps() - { - $applications = array( - 'calendar' => $GLOBALS['egw_info']['apps']['calendar']['title'], - 'felamimail' => $GLOBALS['egw_info']['apps']['felamimail']['title'], - ); - asort($applications); - return $applications = array_merge(array('' => lang('any application')),$applications); - } - - static function getIMAPLoginTypes($serverclass='defaultimap') - { - //error_log(__METHOD__.' called with:'.$serverclass." with capabilities:".parent::$IMAPServerType[$serverclass]['imapcapabilities']); - $returnval = array( - 'standard' =>lang('username (standard)'), - 'vmailmgr' =>lang('username@domainname (Virtual MAIL ManaGeR)'), - 'admin' =>lang('Username/Password defined by admin'), - ); - if (!(stripos(parent::$IMAPServerType[$serverclass]['imapcapabilities'],'logintypeemail') === false)) $returnval['email'] = lang('use Users eMail-Address (as seen in Useraccount)'); - return $returnval; - } - - function edit($content=null) - { - //$this->editProfile($profileid); - $etpl = new etemplate(parent::APP.'.edit'); - if(!is_array($content)) - { - $rowfound = false; - $filter = array(); - if(is_int(intval($_GET['account_id'])) && !empty($_GET['account_id'])) - { - if ( intval($_GET['account_id']) < 0 ) { - $groupID = intval($_GET['account_id']); - $content['ea_group'] = $filter['ea_group'] = $groupID; - - } else { - $accountID = intval($_GET['account_id']); - $content['ea_user'] = $filter['ea_user'] = $accountID; - } - } - if (!empty($_GET['profileid'])) - { - $profileID = intval($_GET['profileid']); - $filter['ea_profile_id'] = $profileID; - $rowfound = parent::read($filter); - } - else - { - $content['ea_user_defined_accounts'] = "yes"; - } - } - else - { - $rowfound = true; - // handle action/submit buttons - if (isset($content['delete'])) - { - unset($content['delete']); - $button = 'delete'; - } - if (isset($content['cancel'])) - { - unset($content['cancel']); - $button = 'cancel'; - } - if (isset($content['apply'])) - { - unset($content['apply']); - $button = 'apply'; - } - if (isset($content['save'])) - { - unset($content['save']); - $button = 'save'; - } - unset($content['manage_stationery_templates']); - //unset($content['tabs']); - if (!empty($content['smtp_senders_email'])) - { - $content['ea_smtp_auth_username'] = $content['ea_smtp_auth_username'].';'.$content['smtp_senders_email']; - unset($content['smtp_senders_email']); - } - $this->data = $content; - switch ($button) - { - case 'delete': - if (($deleted = self::delete($content['ea_profile_id']))) - { - $msg = lang('%1 entries deleted.',$deleted); - } - else - { - $msg = lang('Error deleting entry!'); - } - $js = "opener.location.href='".$GLOBALS['egw']->link('/index.php',array( - 'menuaction' => parent::APP.'.emailadmin_ui.index', - 'msg' => $msg, - ))."';"; - $js .= 'window.close();'; - echo "\n\n\n\n\n"; - $GLOBALS['egw']->common->egw_exit(); - break; - case 'cancel': - $js .= 'window.close();'; - echo "\n\n\n\n\n"; - $GLOBALS['egw']->common->egw_exit(); - break; - case 'apply': - case 'save': - if ($etpl->validation_errors()) break; // the user need to fix the error, before we can save the entry - //_debug_array($this->data); - if (parent::save() != 0) - { - $msg = lang('Error saving the entry!!!'); - $button = ''; - } - else - { - $msg = lang('Entry saved'); - } - $js = "opener.location.href='".$GLOBALS['egw']->link('/index.php',array( - 'menuaction' => parent::APP.'.emailadmin_ui.index', - 'msg' => $msg, - ))."';"; - if ($button == 'save') - { - $js .= 'window.close();'; - echo "\n\n\n\n\n"; - $GLOBALS['egw']->common->egw_exit(); - break; - } - $row; - } - } - if ($rowfound) $content = array_merge($this->data,array()); - $content['smtpcapabilities'] = parent::$SMTPServerType[(!empty($content['ea_smtp_type'])?$content['ea_smtp_type']:'defaultsmtp')]['smtpcapabilities']; - $content['imapcapabilities'] = parent::$IMAPServerType[(!empty($content['ea_imap_type'])?$content['ea_imap_type']:'defaultimap')]['imapcapabilities']; - if (!empty($msg)) $content['msg'] = $msg; - list($content['ea_smtp_auth_username'],$content['smtp_senders_email']) = explode(';',$content['ea_smtp_auth_username']); - $preserv['ea_profile_id'] = $content['ea_profile_id']; - $preserv['smtpcapabilities'] = $content['smtpcapabilities']; - $preserv['imapcapabilities'] = $content['imappcapabilities']; - //$preserv['ea_stationery_active_templates'] = $content['ea_stationery_active_templates']; - $sel_options['ea_smtp_type']=parent::getSMTPServerTypes(); - $sel_options['ea_imap_type']=parent::getIMAPServerTypes(false); - $sel_options['ea_appname'] =self::getAllowedApps(); - $sel_options['ea_imap_login_type'] = self::getIMAPLoginTypes($content['ea_imap_type']); - // Stationery settings - $bostationery = new felamimail_bostationery(); - $sel_options['ea_stationery_active_templates'] = $bostationery->get_stored_templates(); - /* - $content['stored_templates'] = html::checkbox_multiselect( - 'ea_stationery_active_templates',$content['ea_stationery_active_templates'] - ,$bostationery->get_stored_templates(),true,'',3,true,'width: 100%;'); - - $content['manage_stationery_templates'] = - html::a_href( - lang('manage stationery templates'), - '/index.php?menuaction=etemplate.editor.edit', - array('name' => 'felamimail.stationery'), - 'target="_blank"' - ); - */ - //_debug_array($this->data); - return $etpl->exec(parent::APP.'.emailadmin_ui.edit',$content,$sel_options,$readonlys,$preserv,2); - } - - function add() - { - $this->edit(); - } - - function delete($profileid=null) - { - $_profileID = ($profileid ? $profileid : (int)$_GET['profileid']); - if (empty($_profileID)) return 0; - $deleted = parent::delete(array('ea_profile_id' => $_profileID)); - if (!is_array($_profileID)) $_profileID = (array)$_profileID; - foreach ($_profileID as $tk => $pid) - { - parent::$sessionData['profile'][$pid] = array(); - } - parent::saveSessionData(); - return $deleted; - } - - function listProfiles() - { - $GLOBALS['egw']->hooks->register_all_hooks(); - self::index(); - } - -/* - function deleteProfile() - { - $deleted = self::delete((int)$_GET['profileid']); - $this->listProfiles(); - } - - function display_app_header() - { - $GLOBALS['egw']->js->validate_file('tabs','tabs'); - $GLOBALS['egw_info']['flags']['include_xajax'] = True; - - switch($_GET['menuaction']) - { - case 'emailadmin.emailadmin_ui.add': - case 'emailadmin.emailadmin_ui.edit': - case 'emailadmin.emailadmin_ui.AddOrEdit': - case 'emailadmin.emailadmin_ui.addProfile': - case 'emailadmin.emailadmin_ui.editProfile': - $GLOBALS['egw_info']['nofooter'] = true; - $GLOBALS['egw']->js->validate_file('jscode','editProfile','emailadmin'); - $GLOBALS['egw']->js->set_onload('javascript:initAll();'); - #$GLOBALS['egw']->js->set_onload('smtp.init();'); - - break; - - case 'emailadmin.emailadmin_ui.listProfiles': - $GLOBALS['egw']->js->validate_file('jscode','listProfile','emailadmin'); - - break; - } - $GLOBALS['egw']->common->egw_header(); - - if($_GET['menuaction'] == 'emailadmin.emailadmin_ui.listProfiles' || $_GET['menuaction'] == 'emailadmin.emailadmin_ui.deleteProfile') - echo parse_navbar(); - } - - function editProfile($_profileID='') { - $allGroups = self:: getAllGroups(); - $allUsers = self::getAllUsers(); - $applications = self::getAllApps(); - - if($_profileID != '') - { - $profileID = $_profileID; - } - elseif(is_int(intval($_GET['profileid'])) && !empty($_GET['profileid'])) - { - $profileID = intval($_GET['profileid']); - } - else - { - return false; - } - - $profileList = parent::getProfileList($profileID); - $profileData = parent::getProfile($profileID); - $this->display_app_header(); - - $this->t->set_file(array("body" => "editprofile.tpl")); - $this->t->set_block('body','main'); - - $this->translate(); - - foreach((array)$profileData as $key => $value) { - #print "$key $value
"; - switch($key) { - case 'ea_default_signature': - // nothing to do here - break; - case 'ea_stationery_active_templates': - $activeTemplates = $value; - case 'imapTLSEncryption': - $this->t->set_var('checked_'. $key .'_'. $value,'checked="1"'); - break; - case 'imapTLSAuthentication': - if(!$value) { - $this->t->set_var('selected_'.$key,'checked="1"'); - } - break; - case 'imapEnableCyrusAdmin': - case 'imapEnableSieve': - case 'smtpAuth': - case 'smtpLDAPUseDefault': - case 'userDefinedAccounts': - case 'userDefinedIdentities': - case 'ea_user_defined_signatures': - case 'ea_active': - case 'editforwardingaddress': - if($value == 'yes' || $value == 1) { - $this->t->set_var('selected_'.$key,'checked="1"'); - } - break; - case 'imapType': - case 'smtpType': - case 'imapLoginType': - $this->t->set_var('selected_'.$key.'_'.$value,'selected="1"'); - break; - case 'ea_appname': - $this->t->set_var('application_select_box', html::select('globalsettings[ea_appname]',$value,$applications, true, "style='width: 250px;'")); - break; - case 'ea_group': - $this->t->set_var('group_select_box', html::select('globalsettings[ea_group]',$value,$allGroups, true, "style='width: 250px;'")); - break; - case 'ea_user': - $this->t->set_var('user_select_box', html::select('globalsettings[ea_user]',$value,$allUsers, true, "style='width: 250px;'")); - break; - case 'ea_smtp_auth_username': - #echo "
value_$key,$value"; - list($username,$senderadress) = explode(';',$value,2); - if (!empty($senderadress)) $this->t->set_var('value_smtp_senderadress',$senderadress); - $this->t->set_var('value_'.$key,$username); - break; - default: - $this->t->set_var('value_'.$key,$value); - break; - } - } - + if ($accountID || !empty($groupID)) { $linkData = array ( - 'menuaction' => 'emailadmin.emailadmin_ui.saveProfile', - 'profileID' => $profileID + 'menuaction' => 'emailadmin.emailadmin_ui.index', ); - $this->t->set_var('action_url',$GLOBALS['egw']->link('/index.php',$linkData)); - - $linkData = array - ( - 'menuaction' => 'emailadmin.emailadmin_ui.listProfiles' - ); - $this->t->set_var('back_url',$GLOBALS['egw']->link('/index.php',$linkData)); + $listLink = ''. + lang('reset filter').''; - $this->t->set_var('smtptype',html::select( - 'smtpsettings[smtpType]', - $profileData['smtpType'], - parent::getSMTPServerTypes(), - true, - 'style="width: 250px;" id="smtpselector" onchange="smtp.display(this.value);"' - )); - $selectFrom = html::select( - 'imapsettings[imapType]', - $profileData['imapType'], - parent::getIMAPServerTypes(false), - true, - // stupid tabs javascript assumes value=position in selectbox, here's a littel workaround ;-) - "style='width: 250px;' id='imapselector' onchange='var v = this.value; imap.display(this.value); this.value=v;'" - ); - $this->t->set_var('imaptype', $selectFrom); - - $style="width:100%; border:0px; height:150px;"; - $this->t->set_var('signature', html::fckEditorQuick( - 'globalsettings[ea_default_signature]', 'simple', - $profileData['ea_default_signature'], '150px') - ); - - // Stationery settings - $bostationery = new felamimail_bostationery(); - $activeTemplates = is_array($activeTemplates) ? $activeTemplates : array(); - $this->t->set_var('stored_templates', html::checkbox_multiselect( - 'globalsettings[ea_stationery_active_templates]',$activeTemplates - ,$bostationery->get_stored_templates(),true,'',3,true,'width: 100%;')); - $this->t->set_var( - 'link_manage_templates', - html::a_href( - lang('manage stationery templates'), - '/index.php?menuaction=etemplate.editor.edit', - array('name' => 'felamimail.stationery'), - 'target="_blank"' - ) - ); - - $this->t->parse("out","main"); - print $this->t->get('out','main'); - } - - function listProfiles() - { - $accountID = false; - $groupID = false; - $appName = ''; - $profileID = ''; - if(is_int(intval($_GET['account_id'])) && !empty($_GET['account_id'])) - { - if ( intval($_GET['account_id']) < 0 ) { - $groupID = intval($_GET['account_id']); - } else { - $accountID = intval($_GET['account_id']); - } - } - - $this->display_app_header(); - - $this->t->set_file(array("body" => "listprofiles.tpl")); - $this->t->set_block('body','main'); - - $this->translate(); - - $profileList = parent::getProfileList($profileID,$appName,$groupID,$accountID); - - // create the data array - if ($profileList) - { - for ($i=0; $i < count($profileList); $i++) - { - $linkData = array - ( - 'menuaction' => 'emailadmin.emailadmin_ui.editProfile', - 'nocache' => '1', - 'tabpage' => '3', - 'profileid' => $profileList[$i]['profileID'] - ); - $imapServerLink = ''.$profileList[$i]['imapServer'].''; - - $linkData = array - ( - 'menuaction' => 'emailadmin.emailadmin_ui.editProfile', - 'nocache' => '1', - 'tabpage' => '1', - 'profileid' => $profileList[$i]['profileID'] - ); - $descriptionLink = ''.$profileList[$i]['description'].''; - - $linkData = array - ( - 'menuaction' => 'emailadmin.emailadmin_ui.editProfile', - 'nocache' => '1', - 'tabpage' => '2', - 'profileid' => $profileList[$i]['profileID'] - ); - $smtpServerLink = ''.$profileList[$i]['smtpServer'].''; - - $linkData = array - ( - 'menuaction' => 'emailadmin.emailadmin_ui.deleteProfile', - 'profileid' => $profileList[$i]['profileID'] - ); - $deleteLink = ''. - lang('delete').''; - - $application = (empty($profileList[$i]['ea_appname']) ? lang('any application') : $GLOBALS['egw_info']['apps'][$profileList[$i]['ea_appname']]['title']); - $linkData = array - ( - 'menuaction' => 'emailadmin.emailadmin_ui.editProfile', - 'nocache' => '1', - 'tabpage' => '1', - 'profileid' => $profileList[$i]['profileID'] - ); - $applicationLink = ''.$application.''; - - $group = (empty($profileList[$i]['ea_group']) ? lang('any group') : $GLOBALS['egw']->accounts->id2name($profileList[$i]['ea_group'])); - $user = (empty($profileList[$i]['ea_user']) ? lang('any user') : $GLOBALS['egw']->accounts->id2name($profileList[$i]['ea_user'])); - $isactive = (empty($profileList[$i]['ea_active']) ? lang('inactive') : ($profileList[$i]['ea_active']>0 ? lang('active') : lang('inactive'))); - $linkData = array - ( - 'menuaction' => 'emailadmin.emailadmin_ui.editProfile', - 'nocache' => '1', - 'tabpage' => '1', - 'profileid' => $profileList[$i]['profileID'] - ); - $groupLink = ''.$group.''; - $userLink = ''.$user.''; - $activeLink = ''.$isactive.''; - $moveButtons = ' '. - ''; - - $data['profile_'.$profileList[$i]['profileID']] = array( - $descriptionLink, - $smtpServerLink, - $imapServerLink, - $applicationLink, - $groupLink, - $userLink, - $activeLink, - $deleteLink, - $moveButtons, - - ); - } - if (($accountID || !empty($groupID)) && count($profileList)==1) - { - $linkData = array - ( - 'menuaction' => 'emailadmin.emailadmin_ui.editProfile', - 'nocache' => '1', - 'tabpage' => '1', - 'profileid' => $profileList[0]['profileID'] - ); - print "'; - } - } else { - if ($accountID || !empty($groupID)) { - $linkData = array - ( - 'menuaction' => 'emailadmin.emailadmin_ui.addProfile', - 'nocache' => '1', - 'tabpage' => '1', - 'account_id' => ($accountID ? $accountID : $groupID) - ); - print "'; - - } - } - - // create the array containing the table header - $rows = array( - lang('description'), - lang('smtp server name'), - lang('imap server name'), - lang('application'), - lang('group'), - lang('user'), - lang('active'), - lang('delete'), - lang('order'), - ); - if ($accountID || !empty($groupID)) { + if ($GLOBALS['egw_info']['user']['apps']['admin']) { $linkData = array ( - 'menuaction' => 'emailadmin.emailadmin_ui.listProfiles', + 'menuaction' => 'admin.uiaccounts.list_'.($accountID ? 'users' : 'groups'), ); - $listLink = ''. - lang('reset filter').''; - - if ($GLOBALS['egw_info']['user']['apps']['admin']) { - $linkData = array - ( - 'menuaction' => 'admin.uiaccounts.list_'.($accountID ? 'users' : 'groups'), - ); - $listLink2 = ''.($accountID ? lang('Back to Admin/Userlist'): lang('Back to Admin/Grouplist')).''; - } + $listLink2 = ''.($accountID ? lang('Back to Admin/Userlist'): lang('Back to Admin/Grouplist')).''; } - - // create the table html code - $this->t->set_var('server_next_match',$this->nextMatchTable( - $rows, - $data, - lang('profile list').($accountID || !empty($groupID) ? ' '.($accountID ? lang('filtered by Account') : lang('filtered by Group')).' ['.$listLink.']'.' ['.$listLink2.']': ''), - $_start, - $_total, - $_menuAction) - ); - - $linkData = array - ( - 'menuaction' => 'emailadmin.emailadmin_ui.addProfile' - ); - $this->t->set_var('add_link',$GLOBALS['egw']->link('/index.php',$linkData)); - - $this->t->parse("out","main"); - - print $this->t->get('out','main'); - + unset($r); + $subtitle = ($accountID || !empty($groupID) ? ' '.($accountID ? lang('filtered by Account') : lang('filtered by Group')).' ['.$listLink.']'.' ['.$listLink2.']': ''); } - - function nextMatchTable($_rows, $_data, $_description, $_start, $_total, $_menuAction) + //_debug_array($content); + $tpl = new etemplate('emailadmin.index'); + if (!is_array($content)) { - $template =& CreateObject('phpgwapi.Template',EGW_APP_TPL); - $template->set_file(array("body" => "nextMatch.tpl")); - $template->set_block('body','row_list','rowList'); - $template->set_block('body','header_row','headerRow'); - - $var = Array( - 'th_bg' => $GLOBALS['egw_info']['theme']['th_bg'], - 'left_next_matchs' => $this->nextmatchs->left('/index.php',$start,$total,'menuaction=emailadmin.emailadmin_ui.listServers'), - 'right_next_matchs' => $this->nextmatchs->right('/admin/groups.php',$start,$total,'menuaction=emailadmin.emailadmin_ui.listServers'), - 'lang_groups' => lang('user groups'), - 'sort_name' => $this->nextmatchs->show_sort_order($sort,'account_lid',$order,'/index.php',lang('name'),'menuaction=emailadmin.emailadmin_ui.listServers'), - 'description' => $_description, - 'header_edit' => lang('Edit'), - 'header_delete' => lang('Delete') + $content = array( + 'nm' => $GLOBALS['egw']->session->appsession('index',parent::APP), ); - $template->set_var($var); - - $data = ''; - if(is_array($_rows)) + if (!is_array($content['nm'])) { - foreach($_rows as $value) - { - $data .= "$value"; - } - $template->set_var('header_row_data', $data); - $template->fp('headerRow','header_row',True); - #$template->fp('header_row','header_row',True); + $content['nm'] = array( + 'get_rows' => 'emailadmin.emailadmin_ui.get_rows', // I method/callback to request the data for the rows + 'no_filter' => True, // nofilter + 'no_filter2' => True, // I disable the 2. filter (params are the same as for filter) + 'no_cat' => True, // I disable the cat-selectbox + 'lettersearch' => True, // I show a lettersearch + 'searchletter' => false, // I0 active letter of the lettersearch or false for [all] + 'start' => 0, // IO position in list + 'order' => 'ea_order, ea_profile_id', // IO name of the column to sort after (optional for the sortheaders) + 'sort' => 'ASC', // IO direction of the sort: 'ASC' or 'DESC' + //'default_cols' => '!comment,ctime', // I columns to use if there's no user or default pref (! as first char uses all but the columns listed) + 'csv_fields' => false, // I false=disable csv export, true or unset=enable it with auto-detected fieldnames, + //or array with name=>label or name=>array('label'=>label,'type'=>type) pairs (type is a eT widget-type) + ); } - - if(is_array($_data)) + } + elseif(isset($content['nm']['rows']['delete'])) + { + list($profileids) = each($content['nm']['rows']['delete']); + unset($content['nm']['rows']['delete']); + if ($profileids && self::delete($profileids)) { - foreach($_data as $rowID => $value) - { - $data = ''; - foreach($value as $rowData) - { - $data .= "$rowData"; - } - $template->set_var('row_data', $data); - $template->set_var('row_id', $rowID); - $template->fp('rowList','row_list',True); - } + $content['msg'] = lang('%1 entries deleted.',1); + } + else + { + $content['msg'] = lang('Error deleting entry!'); + } + } + elseif(isset($content['delete'])) + { + unset($content['delete']); + if (($deleted = self::delete($content['nm']['rows']['selected']))) + { + $content['msg'] = lang('%1 entries deleted.',$deleted); + } + else + { + $content['msg'] = lang('Error deleting entry!'); } - - return $template->fp('out','body'); - } - function saveProfile() + if (isset($_GET['msg'])) $msg = $_GET['msg']; + $content['msg'] .= $msg; + /* + if ($content['action'] || $content['nm']['rows']) { - $globalSettings = array(); - $smtpSettings = array(); - $imapSettings = array(); - - // try to get the profileID - if(is_int(intval($_GET['profileID'])) && !empty($_GET['profileID'])) { - $globalSettings['profileID'] = intval($_GET['profileID']); + if ($content['action']) + { + // SOME ACTION AS EDIT, DELETE, ... + $content['msg'] = self::action($content['action'],$content['nm']['rows']['checked']); + unset($content['action']); } - - $globalSettings['description'] = $_POST['globalsettings']['description']; - $globalSettings['defaultDomain'] = $_POST['globalsettings']['defaultDomain']; - $globalSettings['organisationName'] = $_POST['globalsettings']['organisationName']; - $globalSettings['userDefinedAccounts'] = ($_POST['globalsettings']['userDefinedAccounts'] == 'yes' ? 'yes' : 'no' ); - $globalSettings['userDefinedIdentities'] = ($_POST['globalsettings']['userDefinedIdentities'] == 'yes' ? 'yes' : 'no' ); - $globalSettings['ea_active'] = ($_POST['globalsettings']['ea_active'] == 'yes' ? 1 : 0 ); - $globalSettings['ea_user_defined_signatures'] = ($_POST['globalsettings']['ea_user_defined_signatures'] == 'yes' ? 'yes' : 'no' ); - $globalSettings['ea_default_signature'] = $_POST['globalsettings']['ea_default_signature']; - $globalSettings['ea_appname'] = ($_POST['globalsettings']['ea_appname'] == 'any' ? '' : $_POST['globalsettings']['ea_appname']); - $globalSettings['ea_group'] = ($_POST['globalsettings']['ea_group'] == 'any' ? '' : (int)$_POST['globalsettings']['ea_group']); - $globalSettings['ea_user'] = ($_POST['globalsettings']['ea_user'] == 'any' ? '' : (int)$_POST['globalsettings']['ea_user']); - $globalSettings['ea_stationery_active_templates'] = $_POST['globalsettings']['ea_stationery_active_templates']; - - // get the settings for the smtp server - $smtpType = $_POST['smtpsettings']['smtpType']; - foreach(parent::getFieldNames($smtpType,'smtp') as $key) { - $smtpSettings[$key] = $_POST['smtpsettings'][$smtpType][$key]; + elseif($content['nm']['rows']['delete']) + { + $content['msg'] = self::action('delete',array_keys($content['nm']['rows']['delete'])); } - // append the email to be used as sender adress(, if set) - if (!empty($smtpSettings['ea_smtp_auth_username']) && isset($_POST['smtpsettings'][$smtpType]['smtp_senderadress']) && !empty($_POST['smtpsettings'][$smtpType]['smtp_senderadress'])) { - $smtpSettings['ea_smtp_auth_username'] .= ";".$_POST['smtpsettings'][$smtpType]['smtp_senderadress']; - } - $smtpSettings['smtpType'] = $smtpType; - - #_debug_array($smtpSettings); exit; - - // get the settings for the imap/pop3 server - $imapType = $_POST['imapsettings']['imapType']; - foreach(parent::getFieldNames($imapType,'imap') as $key) { - switch($key) { - case 'imapTLSAuthentication': - $imapSettings[$key] = !isset($_POST['imapsettings'][$imapType][$key]); - break; - default: - $imapSettings[$key] = $_POST['imapsettings'][$imapType][$key]; - break; - } - } - $imapSettings['imapType'] = $imapType; - - #_debug_array($imapSettings); - - parent::saveProfile($globalSettings, $smtpSettings, $imapSettings); - - print ""; - $GLOBALS['egw']->common->egw_exit(); - exit; - } - - function translate() - { - # skeleton - # $this->t->set_var('',lang('')); - $this->t->set_var('lang_server_name',lang('server name')); - $this->t->set_var('lang_server_description',lang('description')); - $this->t->set_var('lang_edit',lang('edit')); - $this->t->set_var('lang_save',lang('save')); - $this->t->set_var('lang_delete',lang('delete')); - $this->t->set_var('lang_back',lang('back')); - $this->t->set_var('lang_remove',lang('remove')); - $this->t->set_var('lang_ldap_server',lang('LDAP server')); - $this->t->set_var('lang_ldap_basedn',lang('LDAP basedn')); - $this->t->set_var('lang_ldap_server_admin',lang('admin dn')); - $this->t->set_var('lang_ldap_server_password',lang('admin password')); - $this->t->set_var('lang_add_profile',lang('add profile')); - $this->t->set_var('lang_domain_name',lang('domainname')); - $this->t->set_var('lang_SMTP_server_hostname_or_IP_address',lang('SMTP-Server hostname or IP address')); - $this->t->set_var('lang_SMTP_server_port',lang('SMTP-Server port')); - $this->t->set_var('lang_Use_SMTP_auth',lang('Use SMTP auth')); - $this->t->set_var('lang_Select_type_of_SMTP_Server',lang('Select type of SMTP Server')); - $this->t->set_var('lang_profile_name',lang('Profile Name')); - $this->t->set_var('lang_default_domain',lang('enter your default mail domain (from: user@domain)')); - $this->t->set_var('lang_organisation_name',lang('name of organisation')); - $this->t->set_var('lang_user_defined_accounts',lang('users can define their own emailaccounts')); - $this->t->set_var('lang_user_defined_identities',lang('users can define their own identities')); - $this->t->set_var('lang_user_defined_signatures',lang('users can define their own signatures')); - $this->t->set_var('lang_LDAP_server_hostname_or_IP_address',lang('LDAP server hostname or ip address')); - $this->t->set_var('lang_LDAP_server_admin_dn',lang('LDAP server admin DN')); - $this->t->set_var('lang_LDAP_server_admin_pw',lang('LDAP server admin password')); - $this->t->set_var('lang_LDAP_server_base_dn',lang('LDAP server accounts DN')); - $this->t->set_var('lang_use_LDAP_defaults',lang('use LDAP defaults')); - $this->t->set_var('lang_LDAP_settings',lang('LDAP settings')); - $this->t->set_var('lang_select_type_of_imap/pop3_server',lang('select type of IMAP server')); - $this->t->set_var('lang_pop3_server_hostname_or_IP_address',lang('POP3 server hostname or ip address')); - $this->t->set_var('lang_pop3_server_port',lang('POP3 server port')); - $this->t->set_var('lang_imap_server_hostname_or_IP_address',lang('IMAP server hostname or ip address')); - $this->t->set_var('lang_imap_server_port',lang('IMAP server port')); - $this->t->set_var('lang_use_tls_encryption',lang('use tls encryption')); - $this->t->set_var('lang_use_tls_authentication',lang('use tls authentication')); - $this->t->set_var('lang_sieve_settings',lang('Sieve settings')); - $this->t->set_var('lang_enable_sieve',lang('enable Sieve')); - $this->t->set_var('lang_sieve_server_hostname_or_ip_address',lang('Sieve server hostname or ip address')); - $this->t->set_var('lang_sieve_server_port',lang('Sieve server port')); - $this->t->set_var('lang_enable_cyrus_imap_administration',lang('enable Cyrus IMAP server administration')); - $this->t->set_var('lang_cyrus_imap_administration',lang('Cyrus IMAP server administration')); - $this->t->set_var('lang_admin_username',lang('admin username')); - $this->t->set_var('lang_admin_password',lang('admin password')); - $this->t->set_var('lang_imap_server_logintyp',lang('imap server logintyp')); - $this->t->set_var('lang_standard',lang('username (standard)')); - $this->t->set_var('lang_vmailmgr',lang('username@domainname (Virtual MAIL ManaGeR)')); - $this->t->set_var('lang_pre_2001_c_client',lang('IMAP C-Client Version < 2001')); - $this->t->set_var('lang_user_can_edit_forwarding_address',lang('user can edit forwarding address')); - $this->t->set_var('lang_can_be_used_by_application',lang('can be used by application')); - $this->t->set_var('lang_can_be_used_by_group',lang('can be used by group')); - $this->t->set_var('lang_smtp_auth',lang('smtp authentication')); - $this->t->set_var('lang_sender',lang('send using this eMail-Address')); - $this->t->set_var('lang_username',lang('username')); - $this->t->set_var('lang_password',lang('password')); - $this->t->set_var('lang_smtp_settings',lang('smtp settings')); - $this->t->set_var('lang_smtp_options',lang('smtp options')); - $this->t->set_var('lang_profile_access_rights',lang('profile access rights')); - $this->t->set_var('lang_global_settings',lang('')); - $this->t->set_var('lang_organisation',lang('organisation')); - $this->t->set_var('lang_global_options',lang('global options')); - $this->t->set_var('lang_server_settings',lang('server settings')); - $this->t->set_var('lang_encryption_settings',lang('encryption settings')); - $this->t->set_var('lang_no_encryption',lang('no encryption')); - $this->t->set_var('lang_encrypted_connection',lang('encrypted connection')); - $this->t->set_var('lang_do_not_validate_certificate',lang('do not validate certificate')); - $this->t->set_var('lang_vacation_requires_admin',lang('Vaction messages with start- and end-date require an admin account to be set!')); - $this->t->set_var('lang_can_be_used_by_user',lang('can be used by user')); - $this->t->set_var('lang_profile_isactive',lang('profile is active')); - $this->t->set_var('lang_defined_by_admin',lang('Username/Password defined by admin')); - $this->t->set_var('lang_Use_IMAP_auth', lang('Use predefined username and password defined below')); - $this->t->set_var('lang_stationery', lang('stationery')); - $this->t->set_var('lang_active_templates', lang('active templates')); - $this->t->set_var('lang_active_templates_description', lang('users can utilize these stationery templates')); - $this->t->set_var('lang_email',lang('use Users eMail-Address (as seen in Useraccount)')); - $this->t->set_var('',lang('')); - # $this->t->set_var('',lang('')); - + unset($content['nm']['rows']); } */ + if ($content['AddProfile']) + { + unset($content['AddProfile']); + } + if ($content['button']) + { + if ($content['button']) + { + list($button) = each($content['button']); + unset($content['button']); + } + switch($button) + { + default: + break; + } + } + $sel_options['ea_smtp_type']=parent::getSMTPServerTypes(); + $sel_options['ea_imap_type']=parent::getIMAPServerTypes(false); + $sel_options['ea_appname'] =self::getAllowedApps(); + // setting for the top of the app, etc. + $content['addJavaScript'] = $addJavaScript; + $content['subtitle'] = $subtitle; + if (!empty($filter)) foreach ($filter as $fk => $fv) $content['nm']['col_filter'][$fk] = $fv; + // seTting the Title of the app + $GLOBALS['egw_info']['flags']['app_header'] = lang('emailadmin'); + $tpl->exec('emailadmin.emailadmin_ui.index',$content,$sel_options,$readonlys,array('nm' => $content['nm'])); } -?> + + /** + * query the table + * + * reimplemented from so_sql to disable action-buttons based on the acl and make some modification on the data + * + * @param array &$query + * @param array &$rows returned rows/cups + * @param array &$readonlys eg. to disable buttons based on acl + * @param boolean $id_only=false if true only return (via $rows) an array of ids, dont save state to session + * @return int total number of rows matching the selection + */ + function get_rows(&$query_in,&$rows,&$readonlys,$id_only=false) + { + $query = $query_in; + $filteredby = ''; + if ($query['searchletter']) // only show rows if the order-criteria starts with the given letter + { + $query['col_filter'][] = (in_array($query['order'],parent::$numericfields) || (is_string($query['order']) && !(strpos($query['order'],',')===false)) ? 'ea_description' : $query['order']).' '. + $GLOBALS['egw']->db->capabilities['case_insensitive_like'].' '.$GLOBALS['egw']->db->quote($query['searchletter'].'%'); + if (in_array($query['order'],parent::$numericfields)) $query_in['order'] = $query['order'] = 'ea_description'; + $filteredby = $query['order'].' '.lang('starts with').' '.$query['searchletter']; + } + $GLOBALS['egw_info']['flags']['app_header'] = lang('emailadmin').($filteredby? ' - '.$filteredby:''); + $total = parent::get_rows($query,$rows,$readonlys); + return $total; + } + + static function getAllowedApps() + { + $applications = array( + 'calendar' => $GLOBALS['egw_info']['apps']['calendar']['title'], + 'felamimail' => $GLOBALS['egw_info']['apps']['felamimail']['title'], + ); + asort($applications); + return $applications = array_merge(array('' => lang('any application')),$applications); + } + + static function getIMAPLoginTypes($serverclass='defaultimap') + { + //error_log(__METHOD__.' called with:'.$serverclass." with capabilities:".parent::$IMAPServerType[$serverclass]['imapcapabilities']); + $returnval = array( + 'standard' =>lang('username (standard)'), + 'vmailmgr' =>lang('username@domainname (Virtual MAIL ManaGeR)'), + 'admin' =>lang('Username/Password defined by admin'), + ); + if (!empty($serverclass) && stripos(constant($serverclass.'::CAPABILITIES'),'logintypeemail') !== false) + { + $returnval['email'] = lang('use Users eMail-Address (as seen in Useraccount)'); + } + return $returnval; + } + + function edit($content=null) + { + //$this->editProfile($profileid); + $etpl = new etemplate(parent::APP.'.edit'); + if(!is_array($content)) + { + $rowfound = false; + $filter = array(); + if(is_int(intval($_GET['account_id'])) && !empty($_GET['account_id'])) + { + if ( intval($_GET['account_id']) < 0 ) { + $groupID = intval($_GET['account_id']); + $content['ea_group'] = $filter['ea_group'] = $groupID; + + } else { + $accountID = intval($_GET['account_id']); + $content['ea_user'] = $filter['ea_user'] = $accountID; + } + } + if (!empty($_GET['profileid'])) + { + $profileID = intval($_GET['profileid']); + $filter['ea_profile_id'] = $profileID; + $rowfound = parent::read($filter); + } + else + { + $content['ea_user_defined_accounts'] = "yes"; + } + } + else + { + $rowfound = true; + // handle action/submit buttons + if (isset($content['delete'])) + { + unset($content['delete']); + $button = 'delete'; + } + if (isset($content['cancel'])) + { + unset($content['cancel']); + $button = 'cancel'; + } + if (isset($content['apply'])) + { + unset($content['apply']); + $button = 'apply'; + } + if (isset($content['save'])) + { + unset($content['save']); + $button = 'save'; + } + unset($content['manage_stationery_templates']); + //unset($content['tabs']); + if (!empty($content['smtp_senders_email'])) + { + $content['ea_smtp_auth_username'] = $content['ea_smtp_auth_username'].';'.$content['smtp_senders_email']; + unset($content['smtp_senders_email']); + } + $this->data = $content; + switch ($button) + { + case 'delete': + if (($deleted = self::delete($content['ea_profile_id']))) + { + $msg = lang('%1 entries deleted.',$deleted); + } + else + { + $msg = lang('Error deleting entry!'); + } + $js = "opener.location.href='".$GLOBALS['egw']->link('/index.php',array( + 'menuaction' => parent::APP.'.emailadmin_ui.index', + 'msg' => $msg, + ))."';"; + $js .= 'window.close();'; + echo "\n\n\n\n\n"; + $GLOBALS['egw']->common->egw_exit(); + break; + case 'cancel': + $js .= 'window.close();'; + echo "\n\n\n\n\n"; + $GLOBALS['egw']->common->egw_exit(); + break; + case 'apply': + case 'save': + if ($etpl->validation_errors()) break; // the user need to fix the error, before we can save the entry + //_debug_array($this->data); + if (parent::save() != 0) + { + $msg = lang('Error saving the entry!!!'); + $button = ''; + } + else + { + $msg = lang('Entry saved'); + } + $js = "opener.location.href='".$GLOBALS['egw']->link('/index.php',array( + 'menuaction' => parent::APP.'.emailadmin_ui.index', + 'msg' => $msg, + ))."';"; + if ($button == 'save') + { + $js .= 'window.close();'; + echo "\n\n\n\n\n"; + $GLOBALS['egw']->common->egw_exit(); + break; + } + $row; + } + } + if ($rowfound) $content = array_merge($this->data,array()); + $preserv['smtpcapabilities'] = $content['smtpcapabilities'] = + constant((!empty($content['ea_smtp_type'])?$content['ea_smtp_type']:'defaultsmtp').'::CAPABILITIES'); + $preserv['imapcapabilities'] = $content['imapcapabilities'] = + constant((!empty($content['ea_imap_type'])?$content['ea_imap_type']:'defaultimap').'::CAPABILITIES'); + if (!empty($msg)) $content['msg'] = $msg; + list($content['ea_smtp_auth_username'],$content['smtp_senders_email']) = explode(';',$content['ea_smtp_auth_username']); + $preserv['ea_profile_id'] = $content['ea_profile_id']; + //$preserv['ea_stationery_active_templates'] = $content['ea_stationery_active_templates']; + $sel_options['ea_smtp_type']=parent::getSMTPServerTypes(); + $sel_options['ea_imap_type']=parent::getIMAPServerTypes(false); + $sel_options['ea_appname'] =self::getAllowedApps(); + $sel_options['ea_imap_login_type'] = self::getIMAPLoginTypes($content['ea_imap_type']); + // Stationery settings + $bostationery = new felamimail_bostationery(); + $sel_options['ea_stationery_active_templates'] = $bostationery->get_stored_templates(); + /* + $content['stored_templates'] = html::checkbox_multiselect( + 'ea_stationery_active_templates',$content['ea_stationery_active_templates'] + ,$bostationery->get_stored_templates(),true,'',3,true,'width: 100%;'); + + $content['manage_stationery_templates'] = + html::a_href( + lang('manage stationery templates'), + '/index.php?menuaction=etemplate.editor.edit', + array('name' => 'felamimail.stationery'), + 'target="_blank"' + ); + */ + //_debug_array($this->data); + return $etpl->exec(parent::APP.'.emailadmin_ui.edit',$content,$sel_options,$readonlys,$preserv,2); + } + + function add() + { + $this->edit(); + } + + function delete($profileid=null) + { + $_profileID = ($profileid ? $profileid : (int)$_GET['profileid']); + if (empty($_profileID)) return 0; + $deleted = parent::delete(array('ea_profile_id' => $_profileID)); + if (!is_array($_profileID)) $_profileID = (array)$_profileID; + foreach ($_profileID as $tk => $pid) + { + parent::$sessionData['profile'][$pid] = array(); + } + parent::saveSessionData(); + return $deleted; + } + + function listProfiles() + { + $GLOBALS['egw']->hooks->register_all_hooks(); + self::index(); + } +} diff --git a/emailadmin/inc/class.postfixdbmailuser.inc.php b/emailadmin/inc/class.postfixdbmailuser.inc.php index df75f21471..96b32a7e3e 100755 --- a/emailadmin/inc/class.postfixdbmailuser.inc.php +++ b/emailadmin/inc/class.postfixdbmailuser.inc.php @@ -16,6 +16,11 @@ class postfixdbmailuser extends emailadmin_smtp_ldap //class emailadmin_smtp_dbmailuser extends emailadmin_smtp_ldap { + /** + * Capabilities of this class (pipe-separated): default, forward + */ + const CAPABILITIES = 'default|forward'; + /** * Name of schema, has to be the correct case! */ diff --git a/emailadmin/inc/class.postfixldap.inc.php b/emailadmin/inc/class.postfixldap.inc.php index 67ad589eef..62f85ad007 100644 --- a/emailadmin/inc/class.postfixldap.inc.php +++ b/emailadmin/inc/class.postfixldap.inc.php @@ -16,6 +16,11 @@ class postfixldap extends emailadmin_smtp_ldap //class emailadmin_smtp_qmailuser extends emailadmin_smtp_ldap { + /** + * Capabilities of this class (pipe-separated): default, forward + */ + const CAPABILITIES = 'default|forward'; + /** * Name of schema, has to be in the right case! */ diff --git a/emailadmin/inc/class.smtpplesk.inc.php b/emailadmin/inc/class.smtpplesk.inc.php index 50c07525a5..da4dcbcd91 100644 --- a/emailadmin/inc/class.smtpplesk.inc.php +++ b/emailadmin/inc/class.smtpplesk.inc.php @@ -25,6 +25,11 @@ include_once(EGW_SERVER_ROOT."/emailadmin/inc/class.pleskimap.inc.php"); class smtpplesk extends defaultsmtp { + /** + * Capabilities of this class (pipe-separated): default, forward + */ + const CAPABILITIES = 'default|forward'; + /** * @var string/boolean $error string with last error-message or false */