diff --git a/mail/inc/class.mail_bo.inc.php b/mail/inc/class.mail_bo.inc.php index 3442c18e3f..bfb5ced9b1 100644 --- a/mail/inc/class.mail_bo.inc.php +++ b/mail/inc/class.mail_bo.inc.php @@ -168,7 +168,6 @@ class mail_bo */ public static function getInstance($_restoreSession=true, $_profileID=0, $_validate=true) { -$_restoreSession=false; //error_log(__METHOD__.__LINE__.' RestoreSession:'.$_restoreSession.' ProfileId:'.$_profileID.' called from:'.function_backtrace()); if ($_profileID == 0) { @@ -211,11 +210,11 @@ $_restoreSession=false; //refresh objects try { - self::$instances[$this->profileID]->icServer = emailadmin_account::read($this->profileID)->imapServer(); - self::$instances[$this->profileID]->ogServer = emailadmin_account::read($this->profileID)->smtpServer(); + self::$instances[$_profileID]->icServer = emailadmin_account::read($_profileID)->imapServer(); + self::$instances[$_profileID]->ogServer = emailadmin_account::read($_profileID)->smtpServer(); // TODO: merge mailprefs into userprefs, for easy treatment - self::$instances[$this->profileID]->mailPreferences = $GLOBALS['egw_info']['user']['preferences']['mail']; - self::$instances[$this->profileID]->htmlOptions = self::$instances[$this->profileID]->mailPreferences['htmlOptions']; + self::$instances[$_profileID]->mailPreferences = $GLOBALS['egw_info']['user']['preferences']['mail']; + self::$instances[$_profileID]->htmlOptions = self::$instances[$_profileID]->mailPreferences['htmlOptions']; } catch (egw_exception $e) { $newprofileID = emailadmin_bo::getUserDefaultAccID(); @@ -582,15 +581,25 @@ $_restoreSession=false; { //error_log( "-------------------------->open connection ".function_backtrace()); //error_log(__METHOD__.__LINE__.' ->'.array2string($this->icServer)); - $tretval = $this->icServer->openMailbox($this->icServer->currentMailbox); - //if ( PEAR::isError($tretval) ) $isError[$_icServerID] = $tretval->message; + $tretval=true; + try + { + $mailbox=null; + if($this->folderExists($this->sessionData['mailbox'])) $mailbox=$this->sessionData['mailbox']; + if (empty($mailbox))$mailbox = $this->icServer->currentMailbox(); + $this->icServer->openMailbox(($mailbox?$mailbox:'INBOX')); + } + catch (egw_exception $e) + { + error_log(__METHOD__.__LINE__.$e->getMessage()); + $tretval = false; + } //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()); //make sure we are working with the correct hierarchyDelimiter on the current connection, calling getHierarchyDelimiter with false to reset the cache $hD = $this->getHierarchyDelimiter(false); self::$specialUseFolders = $this->getSpecialUseFolders(); - //error_log(__METHOD__.__LINE__.array2string($sUF)); return $tretval; } @@ -881,8 +890,8 @@ $_restoreSession=false; $retValue['attributes'] = ($folderInfo[0]['ATTRIBUTES']?$folderInfo[0]['ATTRIBUTES']:$folderInfo[0]['attributes']); $shortNameParts = explode($retValue['delimiter'], $_folderName); $retValue['shortName'] = array_pop($shortNameParts); - $retValue['displayName'] = $this->encodeFolderName($_folderName); - $retValue['shortDisplayName'] = $this->encodeFolderName($retValue['shortName']); + $retValue['displayName'] = $_folderName; + $retValue['shortDisplayName'] = $retValue['shortName']; if(strtoupper($retValue['shortName']) == 'INBOX') { $retValue['displayName'] = lang('INBOX'); $retValue['shortDisplayName'] = lang('INBOX'); @@ -961,7 +970,7 @@ $_restoreSession=false; $endtime = microtime(true) - $starttime; error_log(__METHOD__. " time used for reopen: ".$endtime.' for Folder:'.$_folderName); } - //$currentFolder = $this->icServer->getCurrentMailbox(); + //$currentFolder = $this->icServer->currentMailbox(); //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 #print "
";
@@ -1743,7 +1752,7 @@ $_restoreSession=false;
 			if ($_useCacheIfPossible && isset($folders2return[$this->icServer->ImapServerId]) && !empty($folders2return[$this->icServer->ImapServerId]))
 			{
 				//error_log(__METHOD__.__LINE__.' using Cached folderObjects');
-				//return $folders2return[$this->icServer->ImapServerId];
+				return $folders2return[$this->icServer->ImapServerId];
 			}
 		}
 		$isUWIMAP = false;
@@ -2034,8 +2043,8 @@ $_restoreSession=false;
 						$folderObject->shortDisplayName = lang($shortName);
 						unset($tmpfolderparts);
 					} else {
-						$folderObject->displayName = $this->encodeFolderName($folderObject->folderName);
-						$folderObject->shortDisplayName = $this->encodeFolderName($shortName);
+						$folderObject->displayName = $folderObject->folderName;
+						$folderObject->shortDisplayName = $shortName;
 					}
 					//$folderName = $folderName;
 					if (in_array($shortName,self::$autoFolders)&&self::searchValueInFolderObjects($shortName,$autoFolderObjects)===false) {
@@ -2516,8 +2525,8 @@ $_restoreSession=false;
 		   ($_folder == $draftFolder)) {
 			$deleteOptions = "remove_immediately";
 		}
-		if($this->icServer->getCurrentMailbox() != $_folder) {
-			$oldMailbox = $this->icServer->getCurrentMailbox();
+		if($this->icServer->currentMailbox() != $_folder) {
+			$oldMailbox = $this->icServer->currentMailbox();
 			$this->icServer->openMailbox($_folder);
 		}
 		$updateCache = false;
@@ -3022,7 +3031,7 @@ $_restoreSession=false;
 	function _getStructure($_uid, $byUid=true, $_ignoreCache=false, $_folder = '')
 	{
 		static $structure;
-		if (empty($_folder)) $_folder = ($this->sessionData['mailbox']? $this->sessionData['mailbox'] : $this->icServer->getCurrentMailbox());
+		if (empty($_folder)) $_folder = ($this->sessionData['mailbox']? $this->sessionData['mailbox'] : $this->icServer->currentMailbox());
 		//error_log(__METHOD__.__LINE__.'User:'.trim($GLOBALS['egw_info']['user']['account_id'])." UID: $_uid, ".$this->icServer->ImapServerId.','.$_folder);
 		if (is_null($structure)) $structure = egw_cache::getCache(egw_cache::INSTANCE,'email','structureCache'.trim($GLOBALS['egw_info']['user']['account_id']),$callback=null,$callback_params=array(),$expiration=60*60*1);
 		//error_log(__METHOD__.__LINE__." UID: $_uid, ".$this->icServer->ImapServerId.','.$_folder.'->'.array2string(array_keys($structure)));
@@ -3048,13 +3057,13 @@ $_restoreSession=false;
 	 * @param string/int $queryString the messageuid(s),
 	 * @param boolean $byUid=true, is the messageuid given by UID or ID
 	 * @param boolean $_ignoreCache=false, use or disregard cache, when fetching
-	 * @param string $_folder='', if given search within that folder for the given $queryString, else use sessionData['mailbox'], or servers getCurrentMailbox
+	 * @param string $_folder='', if given search within that folder for the given $queryString, else use sessionData['mailbox'], or servers getcurrentMailbox()
 	 * @return array  an array with the mail headers requested
 	 */
 	function _getSummary($queryString, $byUid=true, $_ignoreCache=false, $_folder = '')
 	{
 		static $summary;
-		if (empty($_folder)) $_folder = ($this->sessionData['mailbox']? $this->sessionData['mailbox'] : $this->icServer->getCurrentMailbox());
+		if (empty($_folder)) $_folder = ($this->sessionData['mailbox']? $this->sessionData['mailbox'] : $this->icServer->currentMailbox());
 		//error_log(__METHOD__.__LINE__.'User:'.trim($GLOBALS['egw_info']['user']['account_id'])." UID: $_uid, ".$this->icServer->ImapServerId.','.$_folder);
 		if (is_null($summary)) $summary = egw_cache::getCache(egw_cache::INSTANCE,'email','summaryCache'.trim($GLOBALS['egw_info']['user']['account_id']),$callback=null,$callback_params=array(),$expiration=60*60*1);
 		$_uids = explode(',', $queryString);
@@ -3927,7 +3936,7 @@ $_restoreSession=false;
 	function getMessageRawHeader($_uid, $_partID = '')
 	{
 		static $rawHeaders;
-		$_folder = ($this->sessionData['mailbox']? $this->sessionData['mailbox'] : $this->icServer->getCurrentMailbox());
+		$_folder = ($this->sessionData['mailbox']? $this->sessionData['mailbox'] : $this->icServer->currentMailbox());
 		//error_log(__METHOD__.__LINE__." Try Using Cache for raw Header $_uid, $_partID in Folder $_folder");
 
 		if (is_null($rawHeaders)) $rawHeaders = egw_cache::getCache(egw_cache::INSTANCE,'email','rawHeadersCache'.trim($GLOBALS['egw_info']['user']['account_id']),$callback=null,$callback_params=array(),$expiration=60*60*1);
@@ -4023,7 +4032,7 @@ $_restoreSession=false;
 	{
 		//TODO: caching einbauen static!
 		static $rawBody;
-		$_folder = ($this->sessionData['mailbox']? $this->sessionData['mailbox'] : $this->icServer->getCurrentMailbox());
+		$_folder = ($this->sessionData['mailbox']? $this->sessionData['mailbox'] : $this->icServer->currentMailbox());
 		if (isset($rawBody[$_folder][$_uid][($_partID==''?'NIL':$_partID)]))
 		{
 			//error_log(__METHOD__.__LINE__." Using Cache for raw Body $_uid, $_partID in Folder $_folder");
diff --git a/mail/inc/class.mail_ui.inc.php b/mail/inc/class.mail_ui.inc.php
index 33fa6fb726..0fff7b402a 100644
--- a/mail/inc/class.mail_ui.inc.php
+++ b/mail/inc/class.mail_ui.inc.php
@@ -126,6 +126,8 @@ class mail_ui
 		//error_log(__METHOD__.__LINE__.array2string($this->mail_bo->icServer->ImapServerId));
 		// 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
+		//openConnection gathers SpecialUseFolderInformation and Delimiter Info
+		$this->mail_bo->openConnection(self::$icServerID);
 		$GLOBALS['egw']->session->commit_session();
 	}
 
@@ -143,12 +145,13 @@ class mail_ui
 		self::$icServerID = $_icServerID;
 		if ($unsetCache) emailadmin_bo::unsetCachedObjects(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());
 		// no icServer Object: something failed big time
 		if (!isset($this->mail_bo->icServer) || $this->mail_bo->icServer->ImapServerId<>$_icServerID) exit; // ToDo: Exception or the dialog for setting up a server config
-		/*if (!($this->mail_bo->icServer->_connected == 1))*/ $this->mail_bo->reopen('INBOX');
+		/*if (!($this->mail_bo->icServer->_connected == 1))*/
 		// save session varchar
 		$oldicServerID =& egw_cache::getSession('mail','activeProfileID');
+		if ($oldicServerID <> self::$icServerID) $this->mail_bo->openConnection(self::$icServerID);
 		$oldicServerID = self::$icServerID;
 		$GLOBALS['egw']->preferences->add('mail','ActiveProfileID',self::$icServerID,'user');
 		$GLOBALS['egw']->preferences->save_repository(true);
@@ -330,7 +333,7 @@ class mail_ui
 		if (isset($GLOBALS['egw_info']['user']['preferences']['mail']['ActiveProfileID']))
 			$icServerID = (int)$GLOBALS['egw_info']['user']['preferences']['mail']['ActiveProfileID'];
 		//_debug_array($this->mail_bo->mailPreferences);
-		if (is_object($preferences)) $imapServer = $preferences->getIncomingServer($icServerID);
+		if (is_object($preferences)) $imapServer = $this->mail_bo->icServer;
 		if (isset($imapServer->ImapServerId) && !empty($imapServer->ImapServerId))
 		{
 			$icServerID = $GLOBALS['egw_info']['user']['preferences']['mail']['ActiveProfileID'] = $imapServer->ImapServerId;
@@ -351,16 +354,11 @@ class mail_ui
 		if ($preferences->preferences['prefcontroltestconnection'] == 'reset') exit;
 
 		echo "

".lang('IMAP Server')."

"; - if($imapServer->_connectionErrorObject) - { - $eO = $imapServer->_connectionErrorObject; - } - else - { - $this->mail_bo->reopen('INBOX'); - } + $this->mail_bo->reopen('INBOX'); +/* unset($imapServer->_connectionErrorObject); $sieveServer = clone $imapServer; +*/ if (!empty($imapServer->adminPassword)) $imapServer->adminPassword='**********************'; if ($preferences->preferences['prefcontroltestconnection'] == 'nopasswords' || $preferences->preferences['prefcontroltestconnection'] == 'nocredentials') { @@ -379,8 +377,8 @@ class mail_ui else { _debug_array(array('ImapServerId' =>$imapServer->ImapServerId, - 'host'=>$imapServer->host, - 'port'=>$imapServer->port, + 'host'=>$imapServer->acc_imap_host, + 'port'=>$imapServer->acc_imap_port, 'validatecert'=>$imapServer->validatecert)); } @@ -400,7 +398,7 @@ class mail_ui $suF = $this->mail_bo->getSpecialUseFolders(); if (is_array($suF) && !empty($suF)) _debug_array(array(lang('Server supports Special-Use Folders')=>$suF)); - +/* if(($sieveServer instanceof defaultimap) && $sieveServer->enableSieve) { $scriptName = (!empty($GLOBALS['egw_info']['user']['preferences']['mail']['sieveScriptName'])) ? $GLOBALS['egw_info']['user']['preferences']['mail']['sieveScriptName'] : 'mail'; $sieveServer->getScript($scriptName); @@ -417,6 +415,7 @@ class mail_ui _debug_array(array(lang('Successfully connected'),$rules)); } } +*/ echo "

".lang('Preferences')."

"; _debug_array($preferences->preferences); //error_log(__METHOD__.__LINE__.' ImapServerId:'.$imapServer->ImapServerId.' Prefs:'.array2string($preferences->preferences)); @@ -475,7 +474,7 @@ class mail_ui list($_profileID,$_folderName) = explode(self::$delimiter,$nodeID,2); if (!empty($_folderName)) $fetchCounters = true; $data = $this->getFolderTree($fetchCounters, $nodeID); - error_log(__METHOD__.__LINE__.':'.$nodeID.'->'.array2string($data)); + //error_log(__METHOD__.__LINE__.':'.$nodeID.'->'.array2string($data)); if (!is_null($_nodeID)) return $data; header('Content-Type: application/json; charset=utf-8'); echo json_encode($data); @@ -524,9 +523,12 @@ class mail_ui $availableProfiles = emailadmin_account::search($only_current_user=true, $just_name=false, $order_by=null,$offset=0); if (count($availableProfiles)) { $identities=array(); - foreach ($availableProfiles as $tmpkey => $accountData) + $spK = array_keys($availableProfiles); + sort($spK); + foreach ($spK as $i =>$tmpkey) { if ($tmpkey==0) continue; + $accountData = $availableProfiles[$tmpkey]; $icServer = $accountData->imapServer(); //_debug_array($accountData->ImapServerId); if ($_profileID && $icServer->ImapServerId<>$_profileID) continue; @@ -736,7 +738,7 @@ class mail_ui $lastFolderUsedForMoveCont = egw_cache::getCache(egw_cache::INSTANCE,'email','lastFolderUsedForMove'.trim($GLOBALS['egw_info']['user']['account_id']),null,array(),$expiration=60*60*1); if (isset($lastFolderUsedForMoveCont[$this->mail_bo->profileID])) { - $_folder = $this->mail_bo->icServer->getCurrentMailbox(); + $_folder = $this->mail_bo->icServer->currentMailbox(); //error_log(__METHOD__.__LINE__.' '.$_folder."<->".$lastFolderUsedForMoveCont[$this->mail_bo->profileID].function_backtrace()); //if ($_folder!=$lastFolderUsedForMoveCont[$this->mail_bo->profileID]) $this->mail_bo->icServer->selectMailbox($lastFolderUsedForMoveCont[$this->mail_bo->profileID]); if ($_folder!=$lastFolderUsedForMoveCont[$this->mail_bo->profileID])