mirror of
https://github.com/EGroupware/egroupware.git
synced 2024-12-23 23:29:31 +01:00
* eMail/eSync: on failed connection with the mail-server return 503 Service Unavailable; Retry After; if the client supports this, he should wait until retrying; if we experience consecutive connection failure over a defined limit, return 500 internal Server Error
This commit is contained in:
parent
9df39d8dfc
commit
754cbe37d0
@ -66,6 +66,19 @@ class felamimail_activesync implements activesync_plugin_write, activesync_plugi
|
||||
|
||||
static $profileID;
|
||||
|
||||
/**
|
||||
* Integer waitOnFailureDefault how long (in seconds) to wait on connection failure
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $waitOnFailureDefault = 120;
|
||||
|
||||
/**
|
||||
* Integer waitOnFailureLimit how long (in seconds) to wait on connection failure until a 500 is raised
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $waitOnFailureLimit = 7200;
|
||||
/**
|
||||
* debugLevel - enables more debug
|
||||
*
|
||||
@ -265,10 +278,14 @@ class felamimail_activesync implements activesync_plugin_write, activesync_plugi
|
||||
*/
|
||||
private function _connect($account=0)
|
||||
{
|
||||
static $waitOnFailure;
|
||||
if ($this->mail && $this->account != $account) $this->_disconnect();
|
||||
|
||||
$hereandnow = egw_time::to('now','ts');
|
||||
$this->_wasteID = false;
|
||||
$this->_sentID = false;
|
||||
|
||||
$connectionFailed = false;
|
||||
if (!$this->mail)
|
||||
{
|
||||
$this->account = $account;
|
||||
@ -278,13 +295,7 @@ class felamimail_activesync implements activesync_plugin_write, activesync_plugi
|
||||
//error_log(__METHOD__.__LINE__.' create object with ProfileID:'.array2string(self::$profileID));
|
||||
if (!$this->mail->openConnection(self::$profileID,false))
|
||||
{
|
||||
error_log(__METHOD__.__LINE__."($account) can not open connection!".$this->mail->getErrorMessage());
|
||||
//error_log(date('Y-m-d H:i:s').' '.__METHOD__.__LINE__."($account) can not open connection!".$this->mail->getErrorMessage()."\n",3,'/var/lib/egroupware/esync-imap.log');
|
||||
//error_log('# Instance='.$GLOBALS['egw_info']['user']['domain'].', User='.$GLOBALS['egw_info']['user']['account_lid'].', URL='.
|
||||
// ($_SERVER['HTTPS']?'https://':'http://').$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']."\n\n",3,'/var/lib/egroupware/esync-imap.log');
|
||||
header("HTTP/1.1 500 Internal Server Error");
|
||||
//die('Mail not or mis-configured!');
|
||||
throw new egw_exception_not_found(__METHOD__."($account) can not open connection!");
|
||||
$connectionFailed = true;
|
||||
}
|
||||
}
|
||||
else
|
||||
@ -295,16 +306,39 @@ class felamimail_activesync implements activesync_plugin_write, activesync_plugi
|
||||
{
|
||||
if (!$this->mail->openConnection(self::$profileID,false))
|
||||
{
|
||||
error_log(__METHOD__.__LINE__."($account) can not open connection!".$this->mail->getErrorMessage());
|
||||
//error_log(date('Y-m-d H:i:s').' '.__METHOD__.__LINE__."($account) can not open connection!".$this->mail->getErrorMessage()."\n",3,'/var/lib/egroupware/esync-imap.log');
|
||||
//error_log('# Instance='.$GLOBALS['egw_info']['user']['domain'].', User='.$GLOBALS['egw_info']['user']['account_lid'].', URL='.
|
||||
// ($_SERVER['HTTPS']?'https://':'http://').$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']."\n\n",3,'/var/lib/egroupware/esync-imap.log');
|
||||
header("HTTP/1.1 500 Internal Server Error");
|
||||
//die('Mail not or mis-configured!');
|
||||
throw new egw_exception_not_found(__METHOD__."($account) can not open connection!");
|
||||
$connectionFailed = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (is_null($waitOnFailure)) $waitOnFailure = egw_cache::getCache(egw_cache::INSTANCE,'email','ActiveSyncWaitOnFailure'.trim($GLOBALS['egw_info']['user']['account_id']),$callback=null,$callback_params=array(),$expiration=60*60*2);
|
||||
if (empty($waitOnFailure[self::$profileID])) $waitOnFailure[self::$profileID] = array('howlong'=>$this->waitOnFailureDefault,'lastattempt'=>$hereandnow);
|
||||
if ($connectionFailed)
|
||||
{
|
||||
error_log(__METHOD__.__LINE__."($account) could not open connection!".$this->mail->getErrorMessage());
|
||||
//error_log(date('Y-m-d H:i:s').' '.__METHOD__.__LINE__."($account) can not open connection!".$this->mail->getErrorMessage()."\n",3,'/var/lib/egroupware/esync-imap.log');
|
||||
//error_log('# Instance='.$GLOBALS['egw_info']['user']['domain'].', User='.$GLOBALS['egw_info']['user']['account_lid'].', URL='.
|
||||
// ($_SERVER['HTTPS']?'https://':'http://').$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']."\n\n",3,'/var/lib/egroupware/esync-imap.log');
|
||||
if ($waitOnFailure[self::$profileID]['howlong'] > $this->waitOnFailureLimit )
|
||||
{
|
||||
header("HTTP/1.1 500 Internal Server Error");
|
||||
$waitOnFailure[self::$profileID] = array('howlong'=>$this->waitOnFailureDefault,'lastattempt'=>$hereandnow);
|
||||
}
|
||||
else
|
||||
{
|
||||
error_log(__METHOD__.__LINE__.'# Instance='.$GLOBALS['egw_info']['user']['domain'].', User='.$GLOBALS['egw_info']['user']['account_lid']." Can not open connection for Profile:".self::$profileID.' Device should wait '.array2string($waitOnFailure[self::$profileID]));
|
||||
header("HTTP/1.1 503 Service Unavailable");
|
||||
header("Retry-After: ".$waitOnFailure[self::$profileID]['howlong']);
|
||||
$waitOnFailure[self::$profileID] = array('howlong'=>$waitOnFailure[self::$profileID]['howlong'] * 2,'lastattempt'=>$hereandnow);
|
||||
}
|
||||
//die('Mail not or mis-configured!');
|
||||
egw_cache::setCache(egw_cache::INSTANCE,'email','ActiveSyncWaitOnFailure'.trim($GLOBALS['egw_info']['user']['account_id']),$waitOnFailure,$expiration=60*60*2);
|
||||
throw new egw_exception_not_found(__METHOD__."($account) can not open connection!");
|
||||
}
|
||||
else
|
||||
{
|
||||
$waitOnFailure[self::$profileID] = array();
|
||||
egw_cache::setCache(egw_cache::INSTANCE,'email','ActiveSyncWaitOnFailure'.trim($GLOBALS['egw_info']['user']['account_id']),$waitOnFailure,$expiration=60*60*2);
|
||||
}
|
||||
$this->_wasteID = $this->mail->getTrashFolder(false);
|
||||
//error_log(__METHOD__.__LINE__.' TrashFolder:'.$this->_wasteID);
|
||||
$this->_sentID = $this->mail->getSentFolder(false);
|
||||
|
@ -1693,6 +1693,7 @@ class felamimail_bo
|
||||
{
|
||||
$buff = array();
|
||||
$isConError = array();
|
||||
$waitOnFailure = array();
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -1706,9 +1707,15 @@ class felamimail_bo
|
||||
{
|
||||
unset($isConError[$_ImapServerId]);
|
||||
}
|
||||
$waitOnFailure = egw_cache::getCache(egw_cache::INSTANCE,'email','ActiveSyncWaitOnFailure'.trim($GLOBALS['egw_info']['user']['account_id']),$callback=null,$callback_params=array(),$expiration=60*60*2);
|
||||
if (isset($waitOnFailure[$_ImapServerId]))
|
||||
{
|
||||
unset($waitOnFailure[$_ImapServerId]);
|
||||
}
|
||||
}
|
||||
egw_cache::setCache(egw_cache::INSTANCE,'email','icServerIMAP_connectionError'.trim($account_id),$buff,$expiration=60*15);
|
||||
egw_cache::setCache(egw_cache::INSTANCE,'email','icServerSIEVE_connectionError'.trim($account_id),$isConError,$expiration=60*15);
|
||||
egw_cache::setCache(egw_cache::INSTANCE,'email','ActiveSyncWaitOnFailure'.trim($GLOBALS['egw_info']['user']['account_id']),$waitOnFailure,$expiration=60*60*2);
|
||||
}
|
||||
|
||||
static function resetFolderObjectCache($_ImapServerId=null)
|
||||
@ -4537,7 +4544,7 @@ class felamimail_bo
|
||||
continue;
|
||||
}
|
||||
if ($singleBodyPart['charSet']===false) $singleBodyPart['charSet'] = felamimail_bo::detect_encoding($singleBodyPart['body']);
|
||||
$singleBodyPart['body'] = $GLOBALS['egw']->translation->convert(
|
||||
$singleBodyPart['body'] = translation::convert(
|
||||
$singleBodyPart['body'],
|
||||
strtolower($singleBodyPart['charSet'])
|
||||
);
|
||||
|
Loading…
Reference in New Issue
Block a user