forked from extern/egroupware
* Mail: harden mailapp to better cope with broken accounts
This commit is contained in:
parent
5b80563707
commit
d808e0a6c5
@ -483,9 +483,9 @@ class mail_hooks
|
|||||||
{
|
{
|
||||||
$mail_bo = mail_bo::getInstance(true,$profileID);
|
$mail_bo = mail_bo::getInstance(true,$profileID);
|
||||||
$profileID = $GLOBALS['egw_info']['user']['preferences']['mail']['ActiveProfileID'] = $mail_bo->profileID;
|
$profileID = $GLOBALS['egw_info']['user']['preferences']['mail']['ActiveProfileID'] = $mail_bo->profileID;
|
||||||
} catch (Exception $ex) {
|
} catch (Exception $e) {
|
||||||
error_log(__METHOD__."()" . $ex->getMessage());
|
//error_log(__METHOD__."()" . $e->getMessage());
|
||||||
$profileID = null;
|
$profileID = emailadmin_bo::getUserDefaultAccID();
|
||||||
}
|
}
|
||||||
|
|
||||||
$preferences =& $mail_bo->mailPreferences;
|
$preferences =& $mail_bo->mailPreferences;
|
||||||
|
@ -129,13 +129,16 @@ class mail_ui
|
|||||||
//error_log(__METHOD__.__LINE__.array2string($this->mail_bo->icServer->ImapServerId));
|
//error_log(__METHOD__.__LINE__.array2string($this->mail_bo->icServer->ImapServerId));
|
||||||
if ($_GET['menuaction'] != 'mail.etemplate_widget_nextmatch.ajax_get_rows.etemplate')
|
if ($_GET['menuaction'] != 'mail.etemplate_widget_nextmatch.ajax_get_rows.etemplate')
|
||||||
{
|
{
|
||||||
|
//error_log(__METHOD__.__LINE__.' Fetched IC Server openConnection:'.self::$icServerID.'/'.$this->mail_bo->profileID.':'.function_backtrace());
|
||||||
//openConnection gathers SpecialUseFolderInformation and Delimiter Info
|
//openConnection gathers SpecialUseFolderInformation and Delimiter Info
|
||||||
$this->mail_bo->openConnection(self::$icServerID);
|
$this->mail_bo->openConnection(self::$icServerID);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception $e)
|
catch (Exception $e)
|
||||||
{
|
{
|
||||||
|
//error_log(__METHOD__.__LINE__.' Fetched IC Server failed:'.self::$icServerID.'/'.$this->mail_bo->profileID.':'.function_backtrace());
|
||||||
// redirect to mail wizard to handle it (redirect works for ajax too)
|
// redirect to mail wizard to handle it (redirect works for ajax too)
|
||||||
|
/*
|
||||||
egw_framework::redirect_link('/index.php',
|
egw_framework::redirect_link('/index.php',
|
||||||
(self::$icServerID ? array(
|
(self::$icServerID ? array(
|
||||||
'menuaction' => 'mail.mail_wizard.edit',
|
'menuaction' => 'mail.mail_wizard.edit',
|
||||||
@ -145,13 +148,36 @@ class mail_ui
|
|||||||
)) + array(
|
)) + array(
|
||||||
'msg' => $e->getMessage()//.' ('.get_class($e).': '.$e->getCode().')',
|
'msg' => $e->getMessage()//.' ('.get_class($e).': '.$e->getCode().')',
|
||||||
));
|
));
|
||||||
|
*/
|
||||||
|
self::callWizard($e->getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//$GLOBALS['egw']->session->commit_session();
|
//$GLOBALS['egw']->session->commit_session();
|
||||||
//_debug_array($this->mail_bo->mailPreferences);
|
//_debug_array($this->mail_bo->mailPreferences);
|
||||||
if (mail_bo::$debugTimes) mail_bo::logRunTimes($starttime,null,'',__METHOD__.__LINE__);
|
if (mail_bo::$debugTimes) mail_bo::logRunTimes($starttime,null,'',__METHOD__.__LINE__);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* callWizard
|
||||||
|
*
|
||||||
|
* @param string $message
|
||||||
|
*/
|
||||||
|
static function callWizard($message)
|
||||||
|
{
|
||||||
|
$response = egw_json_response::get();
|
||||||
|
$linkData=(self::$icServerID ? array(
|
||||||
|
'menuaction' => 'mail.mail_wizard.edit',
|
||||||
|
'acc_id' => self::$icServerID,
|
||||||
|
) : array(
|
||||||
|
'menuaction' => 'mail.mail_wizard.add',
|
||||||
|
)) + array(
|
||||||
|
'msg' => $message//.' ('.get_class($e).': '.$e->getCode().')',
|
||||||
|
);
|
||||||
|
$windowName = "editMailAccount".self::$icServerID;
|
||||||
|
$response->call("egw.open_link",egw::link('/index.php',$linkData,$windowName,"600x480"));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* changeProfile
|
* changeProfile
|
||||||
*
|
*
|
||||||
@ -173,11 +199,15 @@ class mail_ui
|
|||||||
/*if (!($this->mail_bo->icServer->_connected == 1))*/
|
/*if (!($this->mail_bo->icServer->_connected == 1))*/
|
||||||
// save session varchar
|
// save session varchar
|
||||||
$oldicServerID =& egw_cache::getSession('mail','activeProfileID');
|
$oldicServerID =& egw_cache::getSession('mail','activeProfileID');
|
||||||
|
if (!emailadmin_imapbase::storeActiveProfileIDToPref($this->mail_bo->icServer, self::$icServerID, true ))
|
||||||
|
{
|
||||||
|
throw new egw_exception(__METHOD__." failed to change Profile to $_icServerID");
|
||||||
|
}
|
||||||
if ($oldicServerID <> self::$icServerID) $this->mail_bo->openConnection(self::$icServerID);
|
if ($oldicServerID <> self::$icServerID) $this->mail_bo->openConnection(self::$icServerID);
|
||||||
$oldicServerID = self::$icServerID;
|
$oldicServerID = self::$icServerID;
|
||||||
$GLOBALS['egw']->preferences->add('mail','ActiveProfileID',self::$icServerID,'user');
|
//$GLOBALS['egw']->preferences->add('mail','ActiveProfileID',self::$icServerID,'user');
|
||||||
$GLOBALS['egw']->preferences->save_repository(true);
|
//$GLOBALS['egw']->preferences->save_repository(true);
|
||||||
$GLOBALS['egw_info']['user']['preferences']['mail']['ActiveProfileID'] = self::$icServerID;
|
//$GLOBALS['egw_info']['user']['preferences']['mail']['ActiveProfileID'] = self::$icServerID;
|
||||||
if (mail_bo::$debugTimes) mail_bo::logRunTimes($starttime,null,'',__METHOD__.__LINE__);
|
if (mail_bo::$debugTimes) mail_bo::logRunTimes($starttime,null,'',__METHOD__.__LINE__);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -351,10 +381,17 @@ class mail_ui
|
|||||||
$sessionFolder = $this->mail_bo->sessionData['mailbox'];
|
$sessionFolder = $this->mail_bo->sessionData['mailbox'];
|
||||||
//$toSchema = false;//decides to select list schema with column to selected (if false fromaddress is default)
|
//$toSchema = false;//decides to select list schema with column to selected (if false fromaddress is default)
|
||||||
if ($this->mail_bo->folderExists($sessionFolder))
|
if ($this->mail_bo->folderExists($sessionFolder))
|
||||||
|
{
|
||||||
|
try
|
||||||
{
|
{
|
||||||
$this->mail_bo->reopen($sessionFolder); // needed to fetch full set of capabilities
|
$this->mail_bo->reopen($sessionFolder); // needed to fetch full set of capabilities
|
||||||
//$toSchema = $this->mail_bo->isDraftFolder($sessionFolder)||$this->mail_bo->isSentFolder($sessionFolder)||$this->mail_bo->isTemplateFolder($sessionFolder);
|
//$toSchema = $this->mail_bo->isDraftFolder($sessionFolder)||$this->mail_bo->isSentFolder($sessionFolder)||$this->mail_bo->isTemplateFolder($sessionFolder);
|
||||||
}
|
}
|
||||||
|
catch (Exception $e)
|
||||||
|
{
|
||||||
|
self::callWizard($e->getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
$sessionFolder = $this->mail_bo->sessionData['mailbox'] = 'INBOX';
|
$sessionFolder = $this->mail_bo->sessionData['mailbox'] = 'INBOX';
|
||||||
@ -743,11 +780,45 @@ class mail_ui
|
|||||||
if ($_profileID && $_profileID != $this->mail_bo->profileID)
|
if ($_profileID && $_profileID != $this->mail_bo->profileID)
|
||||||
{
|
{
|
||||||
//error_log(__METHOD__.__LINE__.' change Profile to ->'.$_profileID);
|
//error_log(__METHOD__.__LINE__.' change Profile to ->'.$_profileID);
|
||||||
|
try
|
||||||
|
{
|
||||||
$this->changeProfile($_profileID);
|
$this->changeProfile($_profileID);
|
||||||
}
|
}
|
||||||
|
catch (Exception $e)
|
||||||
|
{
|
||||||
|
error_log(__METHOD__.__LINE__.' failed change Profile to ->'.$_profileID.': '.$e->getMessage());
|
||||||
|
$out = array('id' => 0);
|
||||||
|
$accountObj = emailadmin_account::read($_profileID);
|
||||||
|
$identity_name = emailadmin_account::identity_name($accountObj);
|
||||||
|
$oA = array('id' => $acc_id,
|
||||||
|
'text' => str_replace(array('<','>'),array('[',']'),$identity_name).' '.$e->getMessage(),// as angle brackets are quoted, display in Javascript messages when used is ugly, so use square brackets instead
|
||||||
|
'tooltip' => '('.$acc_id.') '.htmlspecialchars_decode($identity_name). ' '.$e->getMessage(),
|
||||||
|
'im0' => 'thunderbird.png',
|
||||||
|
'im1' => 'thunderbird.png',
|
||||||
|
'im2' => 'thunderbird.png',
|
||||||
|
'path'=> array($acc_id),
|
||||||
|
'child'=> 0, // dynamic loading on unfold
|
||||||
|
'parent' => ''
|
||||||
|
);
|
||||||
|
|
||||||
|
self::callWizard($e->getMessage());
|
||||||
|
|
||||||
|
$this->setOutStructure($oA, $out, self::$delimiter);
|
||||||
|
if (!is_null($_nodeID) && $_nodeID !=0 && $_returnNodeOnly==true)
|
||||||
|
{
|
||||||
|
$node = self::findNode($out,$_nodeID);
|
||||||
|
//error_log(__METHOD__.__LINE__.':'.$_nodeID.'->'.array2string($node));
|
||||||
|
if (mail_bo::$debugTimes) mail_bo::logRunTimes($starttime,null,'return subtree for:'.$_nodeID,__METHOD__.__LINE__);
|
||||||
|
return $node;
|
||||||
|
}
|
||||||
|
return ($c?$out:array('id'=>0, 'item'=>array('text'=>'INBOX','tooltip'=>'INBOX'.' '.lang('(not connected)'),'im0'=>'kfm_home.png')));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//$starttime = microtime(true);
|
//$starttime = microtime(true);
|
||||||
|
try
|
||||||
|
{
|
||||||
$folderObjects = $this->mail_bo->getFolderObjects($_subscribedOnly,false,false,$_useCacheIfPossible);
|
$folderObjects = $this->mail_bo->getFolderObjects($_subscribedOnly,false,false,$_useCacheIfPossible);
|
||||||
//$endtime = microtime(true) - $starttime;
|
//$endtime = microtime(true) - $starttime;
|
||||||
//error_log(__METHOD__.__LINE__.' Fetching folderObjects took: '.$endtime);
|
//error_log(__METHOD__.__LINE__.' Fetching folderObjects took: '.$endtime);
|
||||||
@ -760,6 +831,13 @@ class mail_ui
|
|||||||
if (isset($sentFolder) && $sentFolder != 'none') $userDefinedFunctionFolders['Sent'] = $sentFolder;
|
if (isset($sentFolder) && $sentFolder != 'none') $userDefinedFunctionFolders['Sent'] = $sentFolder;
|
||||||
if (isset($draftFolder) && $draftFolder != 'none') $userDefinedFunctionFolders['Drafts'] = $draftFolder;
|
if (isset($draftFolder) && $draftFolder != 'none') $userDefinedFunctionFolders['Drafts'] = $draftFolder;
|
||||||
if (isset($templateFolder) && $templateFolder != 'none') $userDefinedFunctionFolders['Templates'] = $templateFolder;
|
if (isset($templateFolder) && $templateFolder != 'none') $userDefinedFunctionFolders['Templates'] = $templateFolder;
|
||||||
|
}
|
||||||
|
catch (Exception $e)
|
||||||
|
{
|
||||||
|
$folderObjects=array();
|
||||||
|
self::callWizard($e->getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
$out = array('id' => 0);
|
$out = array('id' => 0);
|
||||||
|
|
||||||
//$starttime = microtime(true);
|
//$starttime = microtime(true);
|
||||||
@ -794,10 +872,13 @@ class mail_ui
|
|||||||
//error_log(__METHOD__.__LINE__.array2string($oA));
|
//error_log(__METHOD__.__LINE__.array2string($oA));
|
||||||
//error_log(__METHOD__.__LINE__.array2string($folderObjects));
|
//error_log(__METHOD__.__LINE__.array2string($folderObjects));
|
||||||
$c = 0;
|
$c = 0;
|
||||||
|
if (!empty($folderObjects))
|
||||||
|
{
|
||||||
$delimiter = $this->mail_bo->getHierarchyDelimiter();
|
$delimiter = $this->mail_bo->getHierarchyDelimiter();
|
||||||
$cmb = $this->mail_bo->icServer->getCurrentMailbox();
|
$cmb = $this->mail_bo->icServer->getCurrentMailbox();
|
||||||
$cmblevels = explode($delimiter,$cmb);
|
$cmblevels = explode($delimiter,$cmb);
|
||||||
$cmblevelsCt = count($cmblevels);
|
$cmblevelsCt = count($cmblevels);
|
||||||
|
}
|
||||||
//error_log(__METHOD__.__LINE__.function_backtrace());
|
//error_log(__METHOD__.__LINE__.function_backtrace());
|
||||||
foreach($folderObjects as $key => $obj)
|
foreach($folderObjects as $key => $obj)
|
||||||
{
|
{
|
||||||
@ -1383,8 +1464,16 @@ unset($query['actions']);
|
|||||||
if ($_profileID && $_profileID != $this->mail_bo->profileID)
|
if ($_profileID && $_profileID != $this->mail_bo->profileID)
|
||||||
{
|
{
|
||||||
//error_log(__METHOD__.__LINE__.' change Profile to ->'.$_profileID);
|
//error_log(__METHOD__.__LINE__.' change Profile to ->'.$_profileID);
|
||||||
|
try
|
||||||
|
{
|
||||||
$this->changeProfile($_profileID);
|
$this->changeProfile($_profileID);
|
||||||
}
|
}
|
||||||
|
catch(Exception $e)
|
||||||
|
{
|
||||||
|
$rows=array();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
$_folderName = (!empty($folderName)?$folderName:'INBOX');
|
$_folderName = (!empty($folderName)?$folderName:'INBOX');
|
||||||
}
|
}
|
||||||
//save selected Folder to sessionData (mailbox)->currentFolder
|
//save selected Folder to sessionData (mailbox)->currentFolder
|
||||||
@ -1425,6 +1514,8 @@ unset($query['actions']);
|
|||||||
}
|
}
|
||||||
$reverse = ($query['sort']=='ASC'?false:true);
|
$reverse = ($query['sort']=='ASC'?false:true);
|
||||||
//error_log(__METHOD__.__LINE__.' maxMessages:'.$maxMessages.' Offset:'.$offset.' Filter:'.array2string($this->sessionData['messageFilter']));
|
//error_log(__METHOD__.__LINE__.' maxMessages:'.$maxMessages.' Offset:'.$offset.' Filter:'.array2string($this->sessionData['messageFilter']));
|
||||||
|
try
|
||||||
|
{
|
||||||
if ($maxMessages > 75)
|
if ($maxMessages > 75)
|
||||||
{
|
{
|
||||||
$_sR = $this->mail_bo->getSortedList(
|
$_sR = $this->mail_bo->getSortedList(
|
||||||
@ -1473,6 +1564,13 @@ unset($query['actions']);
|
|||||||
);
|
);
|
||||||
$rowsFetched['messages'] = $sortResultwH['info']['total'];
|
$rowsFetched['messages'] = $sortResultwH['info']['total'];
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
catch (Exception $e)
|
||||||
|
{
|
||||||
|
$sortResultwH=array();
|
||||||
|
$sR=array();
|
||||||
|
self::callWizard($e->getMessage());
|
||||||
|
}
|
||||||
if (is_array($sR) && count($sR)>0)
|
if (is_array($sR) && count($sR)>0)
|
||||||
{
|
{
|
||||||
foreach ((array)$sR as $key => $v)
|
foreach ((array)$sR as $key => $v)
|
||||||
|
Loading…
Reference in New Issue
Block a user