* Mail: harden mailapp to better cope with broken accounts

This commit is contained in:
Klaus Leithoff 2014-05-09 12:43:57 +00:00
parent 5b80563707
commit d808e0a6c5
2 changed files with 158 additions and 60 deletions

View File

@ -483,9 +483,9 @@ class mail_hooks
{
$mail_bo = mail_bo::getInstance(true,$profileID);
$profileID = $GLOBALS['egw_info']['user']['preferences']['mail']['ActiveProfileID'] = $mail_bo->profileID;
} catch (Exception $ex) {
error_log(__METHOD__."()" . $ex->getMessage());
$profileID = null;
} catch (Exception $e) {
//error_log(__METHOD__."()" . $e->getMessage());
$profileID = emailadmin_bo::getUserDefaultAccID();
}
$preferences =& $mail_bo->mailPreferences;

View File

@ -129,13 +129,16 @@ class mail_ui
//error_log(__METHOD__.__LINE__.array2string($this->mail_bo->icServer->ImapServerId));
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
$this->mail_bo->openConnection(self::$icServerID);
}
}
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)
/*
egw_framework::redirect_link('/index.php',
(self::$icServerID ? array(
'menuaction' => 'mail.mail_wizard.edit',
@ -145,13 +148,36 @@ class mail_ui
)) + array(
'msg' => $e->getMessage()//.' ('.get_class($e).': '.$e->getCode().')',
));
*/
self::callWizard($e->getMessage());
}
//$GLOBALS['egw']->session->commit_session();
//_debug_array($this->mail_bo->mailPreferences);
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
*
@ -173,11 +199,15 @@ class mail_ui
/*if (!($this->mail_bo->icServer->_connected == 1))*/
// save session varchar
$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);
$oldicServerID = self::$icServerID;
$GLOBALS['egw']->preferences->add('mail','ActiveProfileID',self::$icServerID,'user');
$GLOBALS['egw']->preferences->save_repository(true);
$GLOBALS['egw_info']['user']['preferences']['mail']['ActiveProfileID'] = self::$icServerID;
//$GLOBALS['egw']->preferences->add('mail','ActiveProfileID',self::$icServerID,'user');
//$GLOBALS['egw']->preferences->save_repository(true);
//$GLOBALS['egw_info']['user']['preferences']['mail']['ActiveProfileID'] = self::$icServerID;
if (mail_bo::$debugTimes) mail_bo::logRunTimes($starttime,null,'',__METHOD__.__LINE__);
}
@ -351,10 +381,17 @@ class mail_ui
$sessionFolder = $this->mail_bo->sessionData['mailbox'];
//$toSchema = false;//decides to select list schema with column to selected (if false fromaddress is default)
if ($this->mail_bo->folderExists($sessionFolder))
{
try
{
$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);
}
catch (Exception $e)
{
self::callWizard($e->getMessage());
}
}
else
{
$sessionFolder = $this->mail_bo->sessionData['mailbox'] = 'INBOX';
@ -743,11 +780,45 @@ class mail_ui
if ($_profileID && $_profileID != $this->mail_bo->profileID)
{
//error_log(__METHOD__.__LINE__.' change Profile to ->'.$_profileID);
try
{
$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);
try
{
$folderObjects = $this->mail_bo->getFolderObjects($_subscribedOnly,false,false,$_useCacheIfPossible);
//$endtime = microtime(true) - $starttime;
//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($draftFolder) && $draftFolder != 'none') $userDefinedFunctionFolders['Drafts'] = $draftFolder;
if (isset($templateFolder) && $templateFolder != 'none') $userDefinedFunctionFolders['Templates'] = $templateFolder;
}
catch (Exception $e)
{
$folderObjects=array();
self::callWizard($e->getMessage());
}
$out = array('id' => 0);
//$starttime = microtime(true);
@ -794,10 +872,13 @@ class mail_ui
//error_log(__METHOD__.__LINE__.array2string($oA));
//error_log(__METHOD__.__LINE__.array2string($folderObjects));
$c = 0;
if (!empty($folderObjects))
{
$delimiter = $this->mail_bo->getHierarchyDelimiter();
$cmb = $this->mail_bo->icServer->getCurrentMailbox();
$cmblevels = explode($delimiter,$cmb);
$cmblevelsCt = count($cmblevels);
}
//error_log(__METHOD__.__LINE__.function_backtrace());
foreach($folderObjects as $key => $obj)
{
@ -1383,8 +1464,16 @@ unset($query['actions']);
if ($_profileID && $_profileID != $this->mail_bo->profileID)
{
//error_log(__METHOD__.__LINE__.' change Profile to ->'.$_profileID);
try
{
$this->changeProfile($_profileID);
}
catch(Exception $e)
{
$rows=array();
return 0;
}
}
$_folderName = (!empty($folderName)?$folderName:'INBOX');
}
//save selected Folder to sessionData (mailbox)->currentFolder
@ -1425,6 +1514,8 @@ unset($query['actions']);
}
$reverse = ($query['sort']=='ASC'?false:true);
//error_log(__METHOD__.__LINE__.' maxMessages:'.$maxMessages.' Offset:'.$offset.' Filter:'.array2string($this->sessionData['messageFilter']));
try
{
if ($maxMessages > 75)
{
$_sR = $this->mail_bo->getSortedList(
@ -1473,6 +1564,13 @@ unset($query['actions']);
);
$rowsFetched['messages'] = $sortResultwH['info']['total'];
}
}
catch (Exception $e)
{
$sortResultwH=array();
$sR=array();
self::callWizard($e->getMessage());
}
if (is_array($sR) && count($sR)>0)
{
foreach ((array)$sR as $key => $v)