steps to get back to a working list in ui

This commit is contained in:
Klaus Leithoff 2013-10-29 16:16:56 +00:00
parent 4ac778c4d9
commit 4bd8d43318
4 changed files with 160 additions and 236 deletions

View File

@ -31,13 +31,6 @@ class mail_bo
static $folderStatusCache; static $folderStatusCache;
/**
* Instance of bopreference
*
* @var bopreferences object
*/
var $bopreferences;
/** /**
* Active preferences * Active preferences
* *
@ -175,6 +168,7 @@ class mail_bo
*/ */
public static function getInstance($_restoreSession=true, $_profileID=0, $_validate=true) public static function getInstance($_restoreSession=true, $_profileID=0, $_validate=true)
{ {
$_restoreSession=false;
//error_log(__METHOD__.__LINE__.' RestoreSession:'.$_restoreSession.' ProfileId:'.$_profileID.' called from:'.function_backtrace()); //error_log(__METHOD__.__LINE__.' RestoreSession:'.$_restoreSession.' ProfileId:'.$_profileID.' called from:'.function_backtrace());
if ($_profileID == 0) if ($_profileID == 0)
{ {
@ -184,7 +178,7 @@ class mail_bo
} }
else else
{ {
$profileID = emailadmin_bo::getUserDefaultProfileID(); $profileID = emailadmin_bo::getUserDefaultAccID();
} }
if ($profileID!=$_profileID) $_restoreSession==false; if ($profileID!=$_profileID) $_restoreSession==false;
$_profileID=$profileID; $_profileID=$profileID;
@ -192,7 +186,7 @@ class mail_bo
} }
if ($_profileID != 0 && $_validate) if ($_profileID != 0 && $_validate)
{ {
$profileID = self::validateProfileID($_restoreSession, $_profileID); $profileID = self::validateProfileID($_profileID);
if ($profileID != $_profileID) if ($profileID != $_profileID)
{ {
if (self::$debug) if (self::$debug)
@ -214,43 +208,19 @@ class mail_bo
} }
else else
{ {
// make sure the prefs are up to date for the profile to load //refresh objects
$loadfailed = $alreadytriedreloading = false; try
self::$instances[$_profileID]->mailPreferences = self::$instances[$_profileID]->bopreferences->getPreferences(true,$_profileID);
//error_log(__METHOD__.__LINE__." ReRead the Prefs for ProfileID ".$_profileID.' called from:'.function_backtrace());
if (self::$instances[$_profileID]->mailPreferences)
{ {
self::$instances[$_profileID]->icServer = self::$instances[$_profileID]->mailPreferences->getIncomingServer($_profileID); self::$instances[$this->profileID]->icServer = emailadmin_account::read($this->profileID)->imapServer();
// if we do not get an icServer object, session restore failed on bopreferences->getPreferences self::$instances[$this->profileID]->ogServer = emailadmin_account::read($this->profileID)->smtpServer();
if (!self::$instances[$_profileID]->icServer) $loadfailed=true; // TODO: merge mailprefs into userprefs, for easy treatment
if ($_profileID != 0) self::$instances[$_profileID]->mailPreferences->setIncomingServer(self::$instances[$_profileID]->icServer,0); self::$instances[$this->profileID]->mailPreferences = $GLOBALS['egw_info']['user']['preferences']['mail'];
self::$instances[$_profileID]->ogServer = self::$instances[$_profileID]->mailPreferences->getOutgoingServer($_profileID); self::$instances[$this->profileID]->htmlOptions = self::$instances[$this->profileID]->mailPreferences['htmlOptions'];
if ($_profileID != 0) self::$instances[$_profileID]->mailPreferences->setOutgoingServer(self::$instances[$_profileID]->ogServer,0); } catch (egw_exception $e)
self::$instances[$_profileID]->htmlOptions = self::$instances[$_profileID]->mailPreferences->preferences['htmlOptions'];
}
else
{ {
// first try reloading without restore $newprofileID = emailadmin_bo::getUserDefaultAccID();
if ($_restoreSession==true) self::$instances[$_profileID] = new mail_bo('utf-8',false,$_profileID);
if (!self::$instances[$_profileID]->mailPreferences) {
if (self::$debug) error_log(__METHOD__.__LINE__.' something wrong:'.array2string($_restoreSession).' mailPreferences could not be loaded!');
$loadfailed=$alreadytriedreloading=true;
}
}
if ($_profileID>0 && empty(self::$instances[$_profileID]->icServer->host)&&$alreadytriedreloading==false)
{
if ($_restoreSession==true) self::$instances[$_profileID] = new mail_bo('utf-8',false,$_profileID);
if (empty(self::$instances[$_profileID]->icServer->host))
{
if (self::$debug) error_log(__METHOD__.__LINE__.' something critically wrong for '.$_profileID.' RestoreSession:'.array2string($_restoreSession).'->'.array2string(self::$instances[$_profileID]->icServer).' No Server host set!');
$loadfailed=$alreadytriedreloading=true;
}
}
if ($loadfailed)
{
$newprofileID = ($alreadytriedreloading ? emailadmin_bo::getUserDefaultProfileID():$_profileID);
if ($alreadytriedreloading) error_log(__METHOD__.__LINE__." Loading the Profile for ProfileID ".$_profileID.' failed for icServer; trigger new instance for Default-Profile '.$newprofileID.'. called from:'.function_backtrace());
// try loading the default profile for the user // try loading the default profile for the user
error_log(__METHOD__.__LINE__." Loading the Profile for ProfileID ".$_profileID.' failed for icServer; '.$e->getMessage().' Trigger new instance for Default-Profile '.$newprofileID.'. called from:'.function_backtrace());
self::$instances[$newprofileID] = new mail_bo('utf-8',false,$newprofileID); self::$instances[$newprofileID] = new mail_bo('utf-8',false,$newprofileID);
$_profileID = $newprofileID; $_profileID = $newprofileID;
} }
@ -265,58 +235,43 @@ class mail_bo
/** /**
* validate the given profileId to make sure it is valid for the active user * validate the given profileId to make sure it is valid for the active user
* *
* @param boolean $_restoreSession=true - needed to pass on to getInstance
* @param int $_profileID=0 * @param int $_profileID=0
* @return int validated profileID -> either the profileID given, or a valid one * @return int validated profileID -> either the profileID given, or a valid one
*/ */
public static function validateProfileID($_restoreSession=true, $_profileID=0) public static function validateProfileID($_profileID=0)
{ {
$identities = array(); $availableServers = array();
$mail = mail_bo::getInstance($_restoreSession, $_profileID, $validate=false); // we need an instance of mail_bo
$selectedID = $mail->getIdentitiesWithAccounts($identities);
if (is_object($mail->mailPreferences)) $activeIdentity =& $mail->mailPreferences->getIdentity($_profileID, true);
// if you use user defined accounts you may want to access the profile defined with the emailadmin available to the user // if you use user defined accounts you may want to access the profile defined with the emailadmin available to the user
// as we validate the profile in question and may need to return an emailadminprofile, we fetch this one all the time // as we validate the profile in question and may need to return an emailadminprofile, we fetch this one all the time
$boemailadmin = new emailadmin_bo(); $icServers = emailadmin_account::search($only_current_user=true, $just_name=false, $order_by=null);
$defaultProfile = $boemailadmin->getUserProfile() ; $_profileIDs = array_keys($icServers);
$defaultProfileID = $_profileIDs[0];
$defaultProfile = $icServers[$defaultProfileID];
//error_log(__METHOD__.__LINE__.array2string($defaultProfile)); //error_log(__METHOD__.__LINE__.array2string($defaultProfile));
$identitys =& $defaultProfile->identities; $profiles = emailadmin_account::search($only_current_user=true, $just_name=true, $order_by=null);
$icServers =& $defaultProfile->ic_server; foreach ($profiles as $tmpkey => $prof)
foreach ($identitys as $tmpkey => $identity)
{ {
if (empty($icServers[$tmpkey]->host)) continue; //error_log(__METHOD__.__LINE__.' Key:'.$tmpkey.'->'.array2string($icServers[$tmpkey]->acc_imap_host));
$identities[$identity->id] = $identity->realName.' '.$identity->organization.' <'.$identity->emailAddress.'>'; $host = $icServers[$tmpkey]->acc_imap_host;
if (empty($host)) continue;
$availableServers[$icServers[$tmpkey]->acc_id] = $icServers[$tmpkey]->ident_realname.' '.$icServers[$tmpkey]->ident_org.' <'.$icServers[$tmpkey]->ident_email.'>';
} }
//error_log(__METHOD__.__LINE__.array2string($identities)); //error_log(__METHOD__.__LINE__.array2string($identities));
if (array_key_exists($_profileID,$identities)) if (array_key_exists($_profileID,$availableServers))
{ {
// everything seems to be in order self::$profileID REMAINS UNCHANGED // everything seems to be in order self::$profileID REMAINS UNCHANGED
} }
else else
{ {
if (array_key_exists($selectedID,$identities)) if (self::$debug) error_log(__METHOD__.__LINE__.' Profile Selected (after trying to fetch DefaultProfile):'.array2string($_profileID));
if (!array_key_exists($_profileID,$availableServers))
{ {
$_profileID = $selectedID; // everything failed, try first profile found
} $_profileID = $defaultProfileID;
else
{
foreach (array_keys((array)$identities) as $k => $ident)
{
//error_log(__METHOD__.__LINE__.' Testing Identity with ID:'.$ident.' for being provided by emailadmin.');
if ($ident <0) $_profileID = $ident;
}
if (self::$debug) error_log(__METHOD__.__LINE__.' Profile Selected (after trying to fetch DefaultProfile):'.array2string($_profileID));
if (!array_key_exists($_profileID,$identities))
{
// everything failed, try first profile found
$keys = array_keys((array)$identities);
if (count($keys)>0) $_profileID = array_shift($keys);
else $_profileID = 0;
}
} }
} }
if (self::$debug) error_log(__METHOD__.'::'.__LINE__.' ProfileSelected:'.$_profileID.' -> '.$identities[$_profileID]); if (self::$debug) error_log(__METHOD__.'::'.__LINE__.' ProfileSelected:'.$_profileID.' -> '.$availableServers[$_profileID]);
return $_profileID; return $_profileID;
} }
@ -346,23 +301,20 @@ class mail_bo
$this->sessionData = array(); $this->sessionData = array();
$this->forcePrefReload(); $this->forcePrefReload();
} }
$this->profileID = self::validateProfileID($_profileID);
$this->accountid = $GLOBALS['egw_info']['user']['account_id']; $this->accountid = $GLOBALS['egw_info']['user']['account_id'];
$this->bopreferences = CreateObject('mail.mail_bopreferences',$_restoreSession);
$this->mailPreferences = $this->bopreferences->getPreferences(true,$this->profileID);
//error_log(__METHOD__.__LINE__." ProfileID ".$this->profileID.' called from:'.function_backtrace()); //error_log(__METHOD__.__LINE__." ProfileID ".$this->profileID.' called from:'.function_backtrace());
if ($this->mailPreferences) { $acc = emailadmin_account::read($this->profileID);
$this->icServer = $this->mailPreferences->getIncomingServer($this->profileID); error_log(__METHOD__.__LINE__.array2string($acc->imapServer()));
if ($this->profileID != 0) $this->mailPreferences->setIncomingServer($this->icServer,0); $this->icServer = $acc->imapServer();
$this->ogServer = $this->mailPreferences->getOutgoingServer($this->profileID); $this->ogServer = $acc->smtpServer();
if ($this->profileID != 0) $this->mailPreferences->setOutgoingServer($this->ogServer,0); // TODO: merge mailprefs into userprefs, for easy treatment
$this->htmlOptions = $this->mailPreferences->preferences['htmlOptions']; $this->mailPreferences = $GLOBALS['egw_info']['user']['preferences']['mail'];
if (isset($this->icServer->ImapServerId) && !empty($this->icServer->ImapServerId)) $this->htmlOptions = $this->mailPreferences['htmlOptions'];
{ if (isset($this->icServer->ImapServerId) && !empty($this->icServer->ImapServerId))
$_profileID = $this->profileID = $GLOBALS['egw_info']['user']['preferences']['mail']['ActiveProfileID'] = $this->icServer->ImapServerId; {
} $_profileID = $this->profileID = $GLOBALS['egw_info']['user']['preferences']['mail']['ActiveProfileID'] = $this->icServer->ImapServerId;
} }
if (is_null(self::$mailConfig)) self::$mailConfig = config::read('mail'); if (is_null(self::$mailConfig)) self::$mailConfig = config::read('mail');
@ -379,9 +331,9 @@ class mail_bo
{ {
$mail = mail_bo::getInstance(false, $_profile_id,false); $mail = mail_bo::getInstance(false, $_profile_id,false);
//_debug_array( $_profile_id); //_debug_array( $_profile_id);
$mail->mailPreferences = $mail->bopreferences->getPreferences(false,$_profile_id,'mail',$_profile_id); //$mail->mailPreferences = $mail->bopreferences->getPreferences($_profile_id,1);
$mail->icServer = $mail->mailPreferences->getIncomingServer($_profile_id); $this->icServer = emailadmin_account::read($_profile_id)->imapServer();
$mail->ogServer = $mail->mailPreferences->getOutgoingServer($_profile_id); $this->ogServer = emailadmin_account::read($_profile_id)->smtpServer();
return $mail; return $mail;
} }
@ -539,22 +491,21 @@ class mail_bo
{ {
// account select box // account select box
$selectedID = $this->profileID; $selectedID = $this->profileID;
if($this->mailPreferences->userDefinedAccounts) $allAccountData = $this->bopreferences->getAllAccountData($this->mailPreferences); $allAccountData = emailadmin_account::search($only_current_user=true, $just_name=false, $order_by=null);
if ($allAccountData) { if ($allAccountData) {
foreach ($allAccountData as $tmpkey => $accountData) $rememberFirst=$selectedFound=null;
foreach ($allAccountData as $tmpkey => $prof)
{ {
$identity =& $accountData['identity']; if (is_null($rememberFirst)) $rememberFirst = $tmpkey;
$icServer =& $accountData['icServer']; if ($tmpkey == $selectedID) $selectedFound=true;
//_debug_array($identity); //error_log(__METHOD__.__LINE__.' Key:'.$tmpkey.'->'.array2string($icServers[$tmpkey]->acc_imap_host));
//_debug_array($icServer); $host = $icServers[$tmpkey]->acc_imap_host;
if (empty($icServer->host)) continue; if (empty($host)) continue;
$identities[$identity->id]=$identity->realName.' '.$identity->organization.' <'.$identity->emailAddress.'>'; $identities[$icServers[$tmpkey]->acc_id] = $icServers[$tmpkey]->ident_realname.' '.$icServers[$tmpkey]->ident_org.' <'.$icServers[$tmpkey]->ident_email.'>';
if (!empty($identity->default)) $selectedID = $identity->id;
} }
} }
return $selectedID; return ($selectedFound?$selectedID:$rememberFirst);
} }
/** /**
@ -594,7 +545,7 @@ class mail_bo
*/ */
function closeConnection() { function closeConnection() {
//if ($icServer->_connected) error_log(__METHOD__.__LINE__.' disconnect from Server'); //if ($icServer->_connected) error_log(__METHOD__.__LINE__.' disconnect from Server');
if ($this->icServer->_connected) $this->icServer->disconnect(); $this->icServer->disconnect();
} }
/** /**
@ -612,11 +563,8 @@ class mail_bo
//{ //{
//error_log( __METHOD__.__LINE__." $_foldername ".function_backtrace()); //error_log( __METHOD__.__LINE__." $_foldername ".function_backtrace());
//error_log(__METHOD__.__LINE__.' Connected with icServer for Profile:'.$this->profileID.'?'.print_r($this->icServer->_connected,true)); //error_log(__METHOD__.__LINE__.' Connected with icServer for Profile:'.$this->profileID.'?'.print_r($this->icServer->_connected,true));
if (!($this->icServer->_connected == 1)) { if ($this->folderIsSelectable($_foldername)) {
$tretval = $this->openConnection($this->profileID,false); $tretval = $this->icServer->openMailbox($_foldername);
}
if ($this->icServer->_connected == 1 && $this->folderIsSelectable($_foldername)) {
$tretval = $this->icServer->selectMailbox($_foldername);
} }
$folderOpened = $_foldername; $folderOpened = $_foldername;
//} //}
@ -679,25 +627,11 @@ class mail_bo
} }
//error_log( "-------------------------->open connection ".function_backtrace()); //error_log( "-------------------------->open connection ".function_backtrace());
//error_log(__METHOD__.__LINE__.' ->'.array2string($this->icServer)); //error_log(__METHOD__.__LINE__.' ->'.array2string($this->icServer));
if ($this->icServer->_connected == 1) { $tretval = $this->icServer->openMailbox($this->icServer->currentMailbox);
if (!empty($this->icServer->currentMailbox)) $tretval = $this->icServer->selectMailbox($this->icServer->currentMailbox); //if ( PEAR::isError($tretval) ) $isError[$_icServerID] = $tretval->message;
if ( PEAR::isError($tretval) ) $isError[$_icServerID] = $tretval->message; //error_log(__METHOD__." using existing Connection ProfileID:".$_icServerID.' Status:'.print_r($this->icServer->_connected,true));
//error_log(__METHOD__." using existing Connection ProfileID:".$_icServerID.' Status:'.print_r($this->icServer->_connected,true)); //error_log(__METHOD__.__LINE__."->open connection for Server with profileID:".$_icServerID.function_backtrace());
} else {
//error_log(__METHOD__.__LINE__."->open connection for Server with profileID:".$_icServerID.function_backtrace());
$timeout = mail_bo::getTimeOut();
$tretval = $this->icServer->openConnection($_adminConnection,$timeout);
if ( PEAR::isError($tretval) || $tretval===false)
{
$isError[$_icServerID] = ($tretval?$tretval->message:$this->icServer->_connectionErrorObject->message);
if (self::$debug)
{
error_log(__METHOD__.__LINE__." # failed to open new Connection ProfileID:".$_icServerID.' Status:'.print_r($this->icServer->_connected,true).' Message:'.$isError[$_icServerID].' called from '.function_backtrace());
error_log(__METHOD__.__LINE__.' # Instance='.$GLOBALS['egw_info']['user']['domain'].', User='.$GLOBALS['egw_info']['user']['account_lid']);
}
}
if (!PEAR::isError($tretval) && isset($this->sessionData['mailbox']) && !empty($this->sessionData['mailbox'])) $smretval = $this->icServer->selectMailbox($this->sessionData['mailbox']);//may fail silently
}
if ( PEAR::isError($tretval) ) egw_cache::setCache(egw_cache::INSTANCE,'email','icServerIMAP_connectionError'.trim($GLOBALS['egw_info']['user']['account_id']),$isError,$expiration=60*15); if ( PEAR::isError($tretval) ) egw_cache::setCache(egw_cache::INSTANCE,'email','icServerIMAP_connectionError'.trim($GLOBALS['egw_info']['user']['account_id']),$isError,$expiration=60*15);
//error_log(print_r($this->icServer->_connected,true)); //error_log(print_r($this->icServer->_connected,true));
//make sure we are working with the correct hierarchyDelimiter on the current connection, calling getHierarchyDelimiter with false to reset the cache //make sure we are working with the correct hierarchyDelimiter on the current connection, calling getHierarchyDelimiter with false to reset the cache
@ -853,7 +787,7 @@ class mail_bo
self::$specialUseFolders = $_specialUseFolders[$this->icServer->ImapServerId]; // make sure this one is set on function call self::$specialUseFolders = $_specialUseFolders[$this->icServer->ImapServerId]; // make sure this one is set on function call
return $_specialUseFolders[$this->icServer->ImapServerId]; return $_specialUseFolders[$this->icServer->ImapServerId];
} }
if(($this->icServer instanceof defaultimap) && $this->icServer->_connected) if(($this->icServer instanceof defaultimap) )
{ {
//error_log(__METHOD__.__LINE__); //error_log(__METHOD__.__LINE__);
if(($this->hasCapability('SPECIAL-USE'))) if(($this->hasCapability('SPECIAL-USE')))
@ -963,7 +897,7 @@ class mail_bo
if (isset($folderInfoCache[$_folderName]) && $ignoreStatusCache==false && $basicInfoOnly) return $folderInfoCache[$_folderName]; if (isset($folderInfoCache[$_folderName]) && $ignoreStatusCache==false && $basicInfoOnly) return $folderInfoCache[$_folderName];
$retValue = array(); $retValue = array();
$retValue['subscribed'] = false; $retValue['subscribed'] = false;
if(!$icServer = $this->mailPreferences->getIncomingServer($this->profileID)) { if(!$icServer = emailadmin_account::read($this->profileID)) {
if (self::$debug) error_log(__METHOD__." no Server found for Folder:".$_folderName); if (self::$debug) error_log(__METHOD__." no Server found for Folder:".$_folderName);
return false; return false;
} }
@ -1075,7 +1009,7 @@ class mail_bo
error_log(__METHOD__. " time used for reopen: ".$endtime.' for Folder:'.$_folderName); error_log(__METHOD__. " time used for reopen: ".$endtime.' for Folder:'.$_folderName);
} }
//$currentFolder = $this->icServer->getCurrentMailbox(); //$currentFolder = $this->icServer->getCurrentMailbox();
//if ($currentFolder != $_folderName); $this->icServer->selectMailbox($_folderName); //if ($currentFolder != $_folderName); $this->icServer->openMailbox($_folderName);
$rByUid = true; // try searching by uid. this var will be passed by reference to getSortedList, and may be set to false, if UID retrieval fails $rByUid = true; // try searching by uid. this var will be passed by reference to getSortedList, and may be set to false, if UID retrieval fails
#print "<pre>"; #print "<pre>";
#$this->icServer->setDebug(true); #$this->icServer->setDebug(true);
@ -1206,12 +1140,12 @@ class mail_bo
//error_log(__METHOD__.__LINE__.array2string($_headerObject)); //error_log(__METHOD__.__LINE__.array2string($_headerObject));
$headerObject['MSG_NUM'] = $_headerObject->getSeq(); $headerObject['MSG_NUM'] = $_headerObject->getSeq();
$headerObject['SIZE'] = $_headerObject->getSize(); $headerObject['SIZE'] = $_headerObject->getSize();
$headerObject['DATE'] = $_headerObject->getEnvelope()->__get('date'); $headerObject['DATE'] = $_headerObject->getEnvelope()->date;
$headerObject['INTERNALDATE'] = $_headerObject->getImapDate(); $headerObject['INTERNALDATE'] = $_headerObject->getImapDate();
$headerObject['SUBJECT'] = $_headerObject->getEnvelope()->__get('subject'); $headerObject['SUBJECT'] = $_headerObject->getEnvelope()->subject;
$headerObject['FROM'] = $_headerObject->getEnvelope()->__get('from')->__get('addresses'); $headerObject['FROM'] = $_headerObject->getEnvelope()->from->addresses;
$headerObject['TO'] = $_headerObject->getEnvelope()->__get('to')->__get('addresses'); $headerObject['TO'] = $_headerObject->getEnvelope()->to->addresses;
$headerObject['CC'] = $_headerObject->getEnvelope()->__get('cc')->__get('addresses'); $headerObject['CC'] = $_headerObject->getEnvelope()->cc->addresses;
$headerObject['FLAGS'] = $_headerObject->getFlags(); $headerObject['FLAGS'] = $_headerObject->getFlags();
//error_log(__METHOD__.__LINE__.array2string($headerObject)); //error_log(__METHOD__.__LINE__.array2string($headerObject));
@ -2529,11 +2463,10 @@ class mail_bo
// does the folder exist??? // does the folder exist???
//error_log(__METHOD__."->Connected?".$this->icServer->_connected.", ".$_folder.", ".($forceCheck?' forceCheck activated':'dont check on server')); //error_log(__METHOD__."->Connected?".$this->icServer->_connected.", ".$_folder.", ".($forceCheck?' forceCheck activated':'dont check on server'));
if ((!($this->icServer->_connected == 1)) && $forceCheck || empty($folderInfo) || !isset($folderInfo[$this->profileID]) || !isset($folderInfo[$this->profileID][$_folder])) { if ( $forceCheck || empty($folderInfo) || !isset($folderInfo[$this->profileID]) || !isset($folderInfo[$this->profileID][$_folder])) {
//error_log(__METHOD__."->NotConnected and forceCheck with profile:".$this->profileID); //error_log(__METHOD__."->NotConnected and forceCheck with profile:".$this->profileID);
//return false; //return false;
//try to connect //try to connect
if (!$this->icServer->_connected) $this->openConnection($this->profileID,false);
} }
if(($this->icServer instanceof defaultimap)) if(($this->icServer instanceof defaultimap))
{ {
@ -2583,7 +2516,7 @@ class mail_bo
$deleteOptions = $GLOBALS['egw_info']['user']['preferences']['mail']['deleteOptions']; $deleteOptions = $GLOBALS['egw_info']['user']['preferences']['mail']['deleteOptions'];
$trashFolder = $this->getTrashFolder(); $trashFolder = $this->getTrashFolder();
$this->icServer->selectMailbox($folderName); $this->icServer->openMailbox($folderName);
if($folderName == $trashFolder && $deleteOptions == "move_to_trash") { if($folderName == $trashFolder && $deleteOptions == "move_to_trash") {
$this->icServer->deleteMessages('1:*'); $this->icServer->deleteMessages('1:*');
@ -2632,7 +2565,7 @@ class mail_bo
} }
if($this->icServer->getCurrentMailbox() != $_folder) { if($this->icServer->getCurrentMailbox() != $_folder) {
$oldMailbox = $this->icServer->getCurrentMailbox(); $oldMailbox = $this->icServer->getCurrentMailbox();
$this->icServer->selectMailbox($_folder); $this->icServer->openMailbox($_folder);
} }
$updateCache = false; $updateCache = false;
switch($deleteOptions) { switch($deleteOptions) {
@ -2715,7 +2648,7 @@ class mail_bo
if ($cachemodified) egw_cache::setCache(egw_cache::INSTANCE,'email','structureCache'.trim($GLOBALS['egw_info']['user']['account_id']),$structure,$expiration=60*60*1); if ($cachemodified) egw_cache::setCache(egw_cache::INSTANCE,'email','structureCache'.trim($GLOBALS['egw_info']['user']['account_id']),$structure,$expiration=60*60*1);
} }
if($oldMailbox != '') { if($oldMailbox != '') {
$this->icServer->selectMailbox($oldMailbox); $this->icServer->openMailbox($oldMailbox);
} }
return true; return true;
@ -2792,7 +2725,7 @@ class mail_bo
} }
} }
$this->icServer->selectMailbox(($_folder?$_folder:$this->sessionData['mailbox'])); $this->icServer->openMailbox(($_folder?$_folder:$this->sessionData['mailbox']));
switch($_flag) { switch($_flag) {
case "undelete": case "undelete":

View File

@ -214,7 +214,9 @@ class mail_bopreferences extends mail_sopreferences
function getUserDefinedIdentities() function getUserDefinedIdentities()
{ {
$profileID = emailadmin_bo::getUserDefaultProfileID(); $profileID = emailadmin_bo::getUserDefaultAccID();
error_log(__METHOD__.__LINE__.' Not done jet');
/*
$profileData = $this->boemailadmin->getUserProfile('mail'); $profileData = $this->boemailadmin->getUserProfile('mail');
if(!($profileData instanceof ea_preferences) || !($profileData->ic_server[$profileID] instanceof defaultimap)) { if(!($profileData instanceof ea_preferences) || !($profileData->ic_server[$profileID] instanceof defaultimap)) {
return false; return false;
@ -232,19 +234,18 @@ class mail_bopreferences extends mail_sopreferences
return $accountArray; return $accountArray;
} }
} }
*/
return array(); return array();
} }
/** /**
* getPreferences - fetches the active profile for a user * getPreferences - fetches the active profile for a user
* *
* @param boolean $getUserDefinedProfiles
* @param int $_profileID - use this profile to be set its prefs as active profile (0) * @param int $_profileID - use this profile to be set its prefs as active profile (0)
* @param string $_appName - the app the profile is fetched for * @param int $_singleProfileToFetch - single Profile to fetch
* @param int $_singleProfileToFetch - single Profile to fetch no merging of profileData; emailadminprofiles only; for Administrative use only (by now)
* @return object ea_preferences object with the active emailprofile set to ID = 0 * @return object ea_preferences object with the active emailprofile set to ID = 0
*/ */
function getPreferences($getUserDefinedProfiles=true,$_profileID=0,$_appName='mail',$_singleProfileToFetch=0) function getPreferences($_profileID=0,$_singleProfileToFetch=0)
{ {
if (isset($this->sessionData['profileData']) && ($this->sessionData['profileData'] instanceof ea_preferences)) if (isset($this->sessionData['profileData']) && ($this->sessionData['profileData'] instanceof ea_preferences))
{ {
@ -257,110 +258,104 @@ class mail_bopreferences extends mail_sopreferences
$userPreferences = $GLOBALS['egw_info']['user']['preferences']['mail']; $userPreferences = $GLOBALS['egw_info']['user']['preferences']['mail'];
$imapServerTypes = $this->boemailadmin->getIMAPServerTypes(); $imapServerTypes = $this->boemailadmin->getIMAPServerTypes();
$profileData = $this->boemailadmin->getUserProfile($_appName,'',($_singleProfileToFetch<0?-$_singleProfileToFetch:'')); // by now we assume only one profile to be returned try
$icServerKeys = array_keys((array)$profileData->ic_server);
$icProfileID = array_shift($icServerKeys);
$ogServerKeys = array_keys((array)$profileData->og_server);
$ogProfileID = array_shift($ogServerKeys);
//error_log(__METHOD__.__LINE__.' ServerProfile(s)Fetched->'.array2string(count($profileData->ic_server)));
//may be needed later on, as it may hold users Identities connected to MailAlternateAdresses
$IdIsDefault = 0;
$rememberIdentities = $profileData->identities;
foreach ($rememberIdentities as $adkey => $ident)
{ {
if ($ident->default) $IdIsDefault = $ident->id; $profileData_ = emailadmin_account::search($only_current_user=true, $just_name=false, $order_by=null,$offset=0);
$profileData->identities[$adkey]->default = false; $_profileIDs = array_keys($profileData_);
$_profileID = $_profileIDs[0];
$profileData = $profileData_[$_profileID];
_debug_array($profileData->imapServer());
$icProfileID = $profileData->__get('acc_id');
$ogProfileID = $profileData->__get('acc_id');
//error_log(__METHOD__.__LINE__.' ServerProfile(s)Fetched->'.array2string(count($profileData->ic_server)));
}
catch (egw_exception $e)
{ // not sure that this is needed to pass on exeptions
throw new egw_exception_assertion_failed($e->getMessage());
//return false
} }
if(!($profileData instanceof ea_preferences) || !($profileData->ic_server[$icProfileID] instanceof defaultimap))
{
return false;
}
// set the emailadminprofile as profile 0; it will be assumed the active one (if no other profiles are active) // set the emailadminprofile as profile 0; it will be assumed the active one (if no other profiles are active)
$profileData->setIncomingServer($profileData->ic_server[$icProfileID],0); $profileData->setIncomingServer($profileData_[$icProfileID]->imapServer,$icProfileID);
$profileID = $icProfileID; $profileID = $icProfileID;
$profileData->setOutgoingServer($profileData->og_server[$ogProfileID],0); $profileData->setOutgoingServer($profileData_[$icProfileID]->smtpServer,$ogProfileID);
$profileData->setIdentity($profileData->identities[$icProfileID],0); $profileData->setIdentity($profileData->identities[$icProfileID],0);
$userPrefs = $this->mergeUserAndProfilePrefs($userPreferences,$profileData,$icProfileID); $userPrefs = $this->mergeUserAndProfilePrefs($userPreferences,$profileData,$icProfileID);
$rememberID = array(); // there may be more ids to be rememered $rememberID = array(); // there may be more ids to be rememered
$maxId = $icProfileID>0?$icProfileID:0; $maxId = $icProfileID>0?$icProfileID:0;
$minId = $icProfileID<0?$icProfileID:0; $minId = $icProfileID<0?$icProfileID:0;
//$profileData->setPreferences($userPrefs,0); //$profileData->setPreferences($userPrefs,0);
if($profileData->userDefinedAccounts && $GLOBALS['egw_info']['user']['apps']['mail'] && $getUserDefinedProfiles)
// get user defined accounts (only fetch the active one(s), as we call it without second parameter)
// we assume only one account may be active at once
$allAccountData = $this->getAllAccountData($profileData);
foreach ((array)$allAccountData as $k => $accountData)
{ {
// get user defined accounts (only fetch the active one(s), as we call it without second parameter) // set defined IMAP server
// we assume only one account may be active at once if(($accountData['icServer'] instanceof defaultimap))
$allAccountData = $this->getAllAccountData($profileData);
foreach ((array)$allAccountData as $k => $accountData)
{ {
// set defined IMAP server $profileData->setIncomingServer($accountData['icServer'],$k);
$userPrefs = $this->mergeUserAndProfilePrefs($userPreferences,$profileData,$k);
//$profileData->setPreferences($userPrefs,$k);
}
// set defined SMTP Server
if(($accountData['ogServer'] instanceof emailadmin_smtp))
$profileData->setOutgoingServer($accountData['ogServer'],$k);
if(($accountData['identity'] instanceof ea_identity))
{
$profileData->setIdentity($accountData['identity'],$k);
$rememberID[] = $k; // remember Identity as already added
if ($k>0 && $k>$maxId) $maxId = $k;
if ($k<0 && $k<$minId) $minId = $k;
}
if (empty($_profileID))
{
$setAsActive = $accountData['active'];
//if($setAsActive) error_log(__METHOD__.__LINE__." Setting Profile with ID=$k (using Active Info) for ActiveProfile");
}
else
{
$setAsActive = ($_profileID==$k);
//if($setAsActive) error_log(__METHOD__.__LINE__." Setting Profile with ID=$_profileID for ActiveProfile");
}
if($setAsActive)
{
// replace the global defined IMAP Server
if(($accountData['icServer'] instanceof defaultimap)) if(($accountData['icServer'] instanceof defaultimap))
{ {
$profileData->setIncomingServer($accountData['icServer'],$k); $profileID = $k;
$profileData->setIncomingServer($accountData['icServer'],0);
$userPrefs = $this->mergeUserAndProfilePrefs($userPreferences,$profileData,$k); $userPrefs = $this->mergeUserAndProfilePrefs($userPreferences,$profileData,$k);
//$profileData->setPreferences($userPrefs,$k); //$profileData->setPreferences($userPrefs,0);
} }
// set defined SMTP Server
// replace the global defined SMTP Server
if(($accountData['ogServer'] instanceof emailadmin_smtp)) if(($accountData['ogServer'] instanceof emailadmin_smtp))
$profileData->setOutgoingServer($accountData['ogServer'],$k); $profileData->setOutgoingServer($accountData['ogServer'],0);
if(($accountData['identity'] instanceof ea_identity)) // replace the global defined identity
{ if(($accountData['identity'] instanceof ea_identity)) {
$profileData->setIdentity($accountData['identity'],$k); //_debug_array($profileData);
$rememberID[] = $k; // remember Identity as already added $profileData->setIdentity($accountData['identity'],0);
if ($k>0 && $k>$maxId) $maxId = $k; $profileData->identities[0]->default = true;
if ($k<0 && $k<$minId) $minId = $k; $rememberID[] = $IdIsDefault = $accountData['identity']->id;
}
if (empty($_profileID))
{
$setAsActive = $accountData['active'];
//if($setAsActive) error_log(__METHOD__.__LINE__." Setting Profile with ID=$k (using Active Info) for ActiveProfile");
}
else
{
$setAsActive = ($_profileID==$k);
//if($setAsActive) error_log(__METHOD__.__LINE__." Setting Profile with ID=$_profileID for ActiveProfile");
}
if($setAsActive)
{
// replace the global defined IMAP Server
if(($accountData['icServer'] instanceof defaultimap))
{
$profileID = $k;
$profileData->setIncomingServer($accountData['icServer'],0);
$userPrefs = $this->mergeUserAndProfilePrefs($userPreferences,$profileData,$k);
//$profileData->setPreferences($userPrefs,0);
}
// replace the global defined SMTP Server
if(($accountData['ogServer'] instanceof emailadmin_smtp))
$profileData->setOutgoingServer($accountData['ogServer'],0);
// replace the global defined identity
if(($accountData['identity'] instanceof ea_identity)) {
//_debug_array($profileData);
$profileData->setIdentity($accountData['identity'],0);
$profileData->identities[0]->default = true;
$rememberID[] = $IdIsDefault = $accountData['identity']->id;
}
} }
} }
} }
if($profileData->userDefinedIdentities && $GLOBALS['egw_info']['user']['apps']['mail'])
$allUserIdentities = $this->getUserDefinedIdentities();
if (is_array($allUserIdentities))
{ {
$allUserIdentities = $this->getUserDefinedIdentities(); $i=$maxId+1;
if (is_array($allUserIdentities)) $y=$minId-1;
foreach ($allUserIdentities as $tmpkey => $id)
{ {
$i=$maxId+1; if (!in_array($id->id,$rememberID))
$y=$minId-1;
foreach ($allUserIdentities as $tmpkey => $id)
{ {
if (!in_array($id->id,$rememberID)) $profileData->setIdentity($id,$i);
{ $i++;
$profileData->setIdentity($id,$i);
$i++;
}
} }
} }
} }

View File

@ -22,7 +22,7 @@ class mail_hooks
*/ */
static public function accountHooks($hookData) static public function accountHooks($hookData)
{ {
if (($default_profile_id = emailadmin_bo::getDefaultProfileID())) if (($default_profile_id = emailadmin_bo::getDefaultAccID()))
{ {
$mail_bo = mail_bo::forceEAProfileLoad($default_profile_id); $mail_bo = mail_bo::forceEAProfileLoad($default_profile_id);
@ -47,7 +47,7 @@ class mail_hooks
*/ */
static public function adminMenu() static public function adminMenu()
{ {
if (($default_profile_id = emailadmin_bo::getDefaultProfileID())) if (($default_profile_id = emailadmin_bo::getDefaultAccID()))
{ {
$mail_bo = mail_bo::forceEAProfileLoad($default_profile_id); $mail_bo = mail_bo::forceEAProfileLoad($default_profile_id);

View File

@ -122,9 +122,9 @@ class mail_ui
$this->mail_bo = mail_bo::getInstance(false,self::$icServerID); $this->mail_bo = mail_bo::getInstance(false,self::$icServerID);
if (mail_bo::$debug) error_log(__METHOD__.__LINE__.' Fetched IC Server:'.self::$icServerID.'/'.$this->mail_bo->profileID.':'.function_backtrace()); if (mail_bo::$debug) error_log(__METHOD__.__LINE__.' Fetched IC Server:'.self::$icServerID.'/'.$this->mail_bo->profileID.':'.function_backtrace());
error_log(__METHOD__.__LINE__.array2string($this->mail_bo->icServer));
// no icServer Object: something failed big time // no icServer Object: something failed big time
if (!isset($this->mail_bo->icServer)) exit; // ToDo: Exception or the dialog for setting up a server config if (!isset($this->mail_bo->icServer)) exit; // ToDo: Exception or the dialog for setting up a server config
if (!($this->mail_bo->icServer->_connected == 1)) $this->mail_bo->openConnection(self::$icServerID);
$GLOBALS['egw']->session->commit_session(); $GLOBALS['egw']->session->commit_session();
} }
@ -265,7 +265,7 @@ class mail_ui
//$this->mail_bo->reopen($sessionFolder); // needed to fetch full set of capabilities: but did that earlier //$this->mail_bo->reopen($sessionFolder); // needed to fetch full set of capabilities: but did that earlier
} }
// since we are connected,(and selected the folder) we check for capabilities SUPPORTS_KEYWORDS to eventually add the keyword filters // since we are connected,(and selected the folder) we check for capabilities SUPPORTS_KEYWORDS to eventually add the keyword filters
if ($this->mail_bo->icServer->_connected == 1 && $this->mail_bo->icServer->hasCapability('SUPPORTS_KEYWORDS')) if ( $this->mail_bo->icServer->hasCapability('SUPPORTS_KEYWORDS'))
{ {
$this->statusTypes = array_merge($this->statusTypes,array( $this->statusTypes = array_merge($this->statusTypes,array(
'keyword1' => 'urgent',//lang('urgent'), 'keyword1' => 'urgent',//lang('urgent'),
@ -1412,11 +1412,7 @@ unset($query['actions']);
$header['mimetype'] != 'multipart/signed' $header['mimetype'] != 'multipart/signed'
) )
{ {
if ($this->mail_bo->icServer->_connected != 1) $this->mail_bo->reopen($_folderName);
{
$this->mail_bo->openConnection($this->profileID); // connect to the current server
$this->mail_bo->reopen($_folderName);
}
$attachments = $this->mail_bo->getMessageAttachments($header['uid'],$_partID='', $_structure='', $fetchEmbeddedImages=true, $fetchTextCalendar=false, $resolveTNEF=false); $attachments = $this->mail_bo->getMessageAttachments($header['uid'],$_partID='', $_structure='', $fetchEmbeddedImages=true, $fetchTextCalendar=false, $resolveTNEF=false);
if (count($attachments)<1) if (count($attachments)<1)
{ {