diff --git a/felamimail/inc/class.felamimail_bo.inc.php b/felamimail/inc/class.felamimail_bo.inc.php index 9fce005e2d..07340ed3d4 100644 --- a/felamimail/inc/class.felamimail_bo.inc.php +++ b/felamimail/inc/class.felamimail_bo.inc.php @@ -470,11 +470,24 @@ class felamimail_bo return $bofelamimail; } - public static function forcePrefReload() + public static function forcePrefReload($hook_data=null) { // unset the fm_preferences session object, to force the reload/rebuild $GLOBALS['egw']->session->appsession('fm_preferences','felamimail',serialize(array())); $GLOBALS['egw']->session->appsession('session_data','emailadmin',serialize(array())); + // this section takes care for setting the ActiveProfileID accordingly + if (!empty($hook_data) && $hook_data['type']=='user') + { + if (isset($hook_data['prefs']['ActiveProfileID']) && $hook_data['prefs']['ActiveProfileID'] != $GLOBALS['egw_info']['user']['preferences']['felamimail']['ActiveProfileID']) + { + //error_log(__METHOD__.__LINE__.array2string(array_keys($hook_data['prefs']))); + $icServerID = $hook_data['prefs']['ActiveProfileID']; + $bopreferences = CreateObject('felamimail.bopreferences',true); + $bopreferences->setProfileActive(false); + if ($icServerID>0) $bopreferences->setProfileActive(true,$icServerID); + } + if (empty($hook_data['prefs']['ActiveProfileID'])) return lang('Error').': '.lang("Active ProfileID should not be empty"); + } } function _getNameSpaces() diff --git a/felamimail/inc/class.felamimail_hooks.inc.php b/felamimail/inc/class.felamimail_hooks.inc.php index e1cecb0a73..3966de9962 100644 --- a/felamimail/inc/class.felamimail_hooks.inc.php +++ b/felamimail/inc/class.felamimail_hooks.inc.php @@ -118,7 +118,40 @@ class felamimail_hooks $profileID = (int)$GLOBALS['egw_info']['user']['preferences']['felamimail']['ActiveProfileID']; $bofelamimail = felamimail_bo::getInstance(true,$profileID); + $identities = array(); + if ($GLOBALS['type'] === 'user') + { + // gather profile data + $imapServer =& $bofelamimail->icServer; + //error_log(__METHOD__.__LINE__.array2string($imapServer)); + // account select box + $selectedID = $bofelamimail->getIdentitiesWithAccounts($identities); + } $profileID = $GLOBALS['egw_info']['user']['preferences']['felamimail']['ActiveProfileID'] = $bofelamimail->profileID; + if ($GLOBALS['type'] === 'user') + { + $preferences =& $bofelamimail->mailPreferences; + $activeIdentity =& $preferences->getIdentity($profileID, true); + //error_log(__METHOD__.__LINE__.' ActiveIdentity for profileID'.$icServerID.'->'.array2string($activeIdentity)); + // the data needed here are collected at the start of this function + if (!isset($activeIdentity->id) && $selectedID == $profileID) { + $identities[$profileID] = $activeIdentity->realName.' '.$activeIdentity->organization.' <'.$activeIdentity->emailAddress.'>'; + } + // if you use user defined accounts you may want to access the profile defined with the emailadmin available to the user + if ($activeIdentity->id) { + $boemailadmin = new emailadmin_bo(); + $defaultProfile = $boemailadmin->getUserProfile() ; + //error_log(__METHOD__.__LINE__.array2string($defaultProfile)); + $identitys =& $defaultProfile->identities; + $icServers =& $defaultProfile->ic_server; + foreach ($identitys as $tmpkey => $identity) + { + if (empty($icServers[$tmpkey]->host)) continue; + $identities[$identity->id] = $identity->realName.' '.$identity->organization.' <'.$identity->emailAddress.'>'; + } + //$identities[0] = $defaultIdentity->realName.' '.$defaultIdentity->organization.' <'.$defaultIdentity->emailAddress.'>'; + } + } if($bofelamimail->openConnection($profileID)) { $folderObjects = $bofelamimail->getFolderObjects(true, false); foreach($folderObjects as $folderName => $folderInfo) { @@ -322,6 +355,16 @@ class felamimail_hooks 'xmlrpc' => False, 'admin' => False ), + 'ActiveProfileID' => array( + 'type' => 'select', + 'label' => 'Active Mail Profile', + 'help' => 'view / select your currently active mailprofile (this is a user only setting)', + 'name' => 'ActiveProfileID', + 'values' => $identities, + 'xmlrpc' => True, + 'admin' => False, + 'default'=> $profileID, + ), 'message_forwarding' => array( 'type' => 'select', 'label' => 'how to forward messages', @@ -718,6 +761,7 @@ class felamimail_hooks ), ); if (!$GLOBALS['egw_info']['apps']['stylite']) unset($settingsArray['attachVCardAtCompose']); + if (!($GLOBALS['type'] === 'user')) unset($settingsArray['ActiveProfileID']); return $settingsArray; }