using standard emailadmin_account methods for account list and account-name

This commit is contained in:
Ralf Becker 2014-09-08 14:12:14 +00:00
parent a884f3e444
commit f157e4f56c

View File

@ -27,7 +27,7 @@ class mail_activesync implements activesync_plugin_write, activesync_plugin_send
/** /**
* Instance of mail_bo * Instance of mail_bo
* *
* @var mail * @var mail_bo
*/ */
private $mail; private $mail;
@ -126,61 +126,20 @@ class mail_activesync implements activesync_plugin_write, activesync_plugin_send
} }
} }
if ($this->debugLevel>1) error_log(__METHOD__.__LINE__.' Profile Selected (after reading Prefs):'.array2string(self::$profileID)); if ($this->debugLevel>1) error_log(__METHOD__.__LINE__.' Profile Selected (after reading Prefs):'.array2string(self::$profileID));
$params =null;
if (isset($GLOBALS['egw_setup'])) $params['setup']=true;
$identities = $this->getAvailableProfiles($params);
//error_log(__METHOD__.__LINE__.array2string($identities));
if (array_key_exists(self::$profileID,$identities))
{
// everything seems to be in order self::$profileID REMAINS UNCHANGED
}
else
{
foreach (array_keys((array)$identities) as $k => $ident) if ($ident <0) self::$profileID = $ident;
if ($this->debugLevel>1) error_log(__METHOD__.__LINE__.' Profile Selected (after trying to fetch DefaultProfile):'.array2string(self::$profileID));
if (!array_key_exists(self::$profileID,$identities))
{
// everything failed, try first profile found
$keys = array_keys((array)$identities);
if (count($keys)>0) self::$profileID = array_shift($keys);
else self::$profileID = 0;
}
}
if ($this->debugLevel>0) error_log(__METHOD__.'::'.__LINE__.' ProfileSelected:'.self::$profileID.' -> '.$identities[self::$profileID]);
//$this->debugLevel=0;
}
/** // verify we are on an existing profile, if not running in setup (settings can not be static according to interface!)
* fetches available Profiles if (!isset($GLOBALS['egw_setup']))
*
* @return array
*/
function getAvailableProfiles($params = null)
{ {
$allIdentities = mail_bo::getAllIdentities(($params['account_id']?$params['account_id']:null)); try {
$identities = array(); emailadmin_account::read(self::$profileID);
if (!isset($params['setup']))
{
$profileID=(self::$profileID=='G'?emailadmin_account::get_default_acc_id():self::$profileID);
if (!$this->mail) $this->mail = mail_bo::getInstance(true,$profileID,true,false,true);
foreach($allIdentities as $key => $singleIdentity) {
if (isset($identities[$singleIdentity['acc_id']])) continue; // only use the first
$iS = mail_bo::generateIdentityString($singleIdentity);
if (mail_bo::$mailConfig['how2displayIdentities']=='' || count($allIdentities) ==1)
{
$id_prepend ='';
} }
else catch(Exception $e) {
{ unset($e);
$id_prepend = '('.$singleIdentity['ident_id'].') '; self::$profileID = emailadmin_account::get_default_acc_id();
}
if (array_search($id_prepend.$iS,$identities)===false)
{
$identities[$singleIdentity['acc_id']] = $id_prepend.$iS;
} }
} }
} if ($this->debugLevel>0) error_log(__METHOD__.'::'.__LINE__.' ProfileSelected:'.self::$profileID);
return $identities; //$this->debugLevel=0;
} }
/** /**
@ -193,9 +152,9 @@ class mail_activesync implements activesync_plugin_write, activesync_plugin_send
{ {
//error_log(__METHOD__.__LINE__.array2string($hook_data)); //error_log(__METHOD__.__LINE__.array2string($hook_data));
$identities = array(); $identities = array();
if (!isset($hook_data['setup'])) if (!isset($hook_data['setup']) && in_array($hook_data['type'], array('user', 'group')))
{ {
$identities = $this->getAvailableProfiles($hook_data); $identities = iterator_to_array(emailadmin_account::search((int)$hook_data['account_id']));
} }
$identities += array( $identities += array(
'G' => lang('Primary Profile'), 'G' => lang('Primary Profile'),