diff --git a/core/action.class.inc.php b/core/action.class.inc.php index d7ff9d367..5bb64979b 100644 --- a/core/action.class.inc.php +++ b/core/action.class.inc.php @@ -314,42 +314,54 @@ class ActionEmail extends ActionNotification { $this->m_iRecipients = 0; $this->m_aMailErrors = array(); - $bRes = false; // until we do succeed in sending the email - + // Determine recicipients // $sTo = $this->FindRecipients('to', $aContextArgs); $sCC = $this->FindRecipients('cc', $aContextArgs); $sBCC = $this->FindRecipients('bcc', $aContextArgs); - + $sFrom = MetaModel::ApplyParams($this->Get('from'), $aContextArgs); $sReplyTo = MetaModel::ApplyParams($this->Get('reply_to'), $aContextArgs); - + $sSubject = MetaModel::ApplyParams($this->Get('subject'), $aContextArgs); $sBody = MetaModel::ApplyParams($this->Get('body'), $aContextArgs); - + $oObj = $aContextArgs['this->object()']; - $sMessageId = sprintf('iTop_%s_%d_%f@%s.openitop.org', get_class($oObj), $oObj->GetKey(), microtime(true /* get as float*/), MetaModel::GetEnvironmentId()); + $sMessageId = sprintf('iTop_%s_%d_%f@%s.openitop.org', get_class($oObj), $oObj->GetKey(), microtime(true /* get as float*/), + MetaModel::GetEnvironmentId()); $sReference = '<'.$sMessageId.'>'; } - catch(Exception $e) - { - ApplicationContext::SetUrlMakerClass($sPreviousUrlMaker); - throw $e; - } - ApplicationContext::SetUrlMakerClass($sPreviousUrlMaker); - - if (!is_null($oLog)) - { + catch (Exception $e) { + /** @noinspection PhpUnhandledExceptionInspection */ + throw $e; + } + finally { + ApplicationContext::SetUrlMakerClass($sPreviousUrlMaker); + } + + if (!is_null($oLog)) { // Note: we have to secure this because those values are calculated // inside the try statement, and we would like to keep track of as // many data as we could while some variables may still be undefined - if (isset($sTo)) $oLog->Set('to', $sTo); - if (isset($sCC)) $oLog->Set('cc', $sCC); - if (isset($sBCC)) $oLog->Set('bcc', $sBCC); - if (isset($sFrom)) $oLog->Set('from', $sFrom); - if (isset($sSubject)) $oLog->Set('subject', $sSubject); - if (isset($sBody)) $oLog->Set('body', $sBody); + if (isset($sTo)) { + $oLog->Set('to', $sTo); + } + if (isset($sCC)) { + $oLog->Set('cc', $sCC); + } + if (isset($sBCC)) { + $oLog->Set('bcc', $sBCC); + } + if (isset($sFrom)) { + $oLog->Set('from', $sFrom); + } + if (isset($sSubject)) { + $oLog->Set('subject', $sSubject); + } + if (isset($sBody)) { + $oLog->Set('body', $sBody); + } } $sStyles = file_get_contents(APPROOT.'css/email.css'); $sStyles .= MetaModel::GetConfig()->Get('email_css'); @@ -439,4 +451,3 @@ class ActionEmail extends ActionNotification } } } -?> diff --git a/core/metamodel.class.php b/core/metamodel.class.php index bfdb61da4..3d8e2332d 100644 --- a/core/metamodel.class.php +++ b/core/metamodel.class.php @@ -7222,9 +7222,11 @@ abstract class MetaModel * @param string $sInput * @param array $aParams * - * @return mixed + * @return string + * + * @throws \Exception */ - static public function ApplyParams($sInput, $aParams) + public static function ApplyParams($sInput, $aParams) { $aParams = static::AddMagicPlaceholders($aParams); @@ -7234,7 +7236,7 @@ abstract class MetaModel $aSearches = array(); $aReplacements = array(); - foreach($aParams as $sSearch => $replace) + foreach ($aParams as $sSearch => $replace) { // Some environment parameters are objects, we just need scalars if (is_object($replace))