/** * @param $config * @param $responseCode * @param $view * @param $request * @param $exception * @return bool * @throws Application_Exception * @throws Opus_Mail_Exception * * TODO Escape exception messages, other stuff? Is it possible to inject javascript in E-Mail? */ public function _sendErrorMail($config, $responseCode, $view, $request, $exception) { if (!isset($config->errorController->mailTo)) { return false; } if (!is_object($exception) or !$exception instanceof Exception) { throw new Application_Exception('Invalid Exception object given.'); } if (!is_object($request) or !$request instanceof Zend_Controller_Request_Abstract) { throw new Application_Exception('Invalid Zend_Controller_Request_Abstract object given.'); } // Setting up mail subject. $instanceName = isset($config->instance_name) ? $config->instance_name : 'Opus4'; $subject = $instanceName . " (ID " . (array_key_exists('id_string', $GLOBALS) ? $GLOBALS['id_string'] : 'undef') . ") ({$responseCode}): " . get_class($exception) . " "; $subject .= "/" . $request->getModuleName() . "/" . $request->getControllerName() . "/" . $request->getActionName(); // Setting up mail body. $body = ''; $body .= "Source:\n"; $body .= " module: " . $request->getModuleName() . "\n"; $body .= " controller: " . $request->getControllerName() . "\n"; $body .= " action: " . $request->getActionName() . "\n"; $body .= " file: " . $exception->getFile() . ":" . $exception->getLine() . "\n"; $body .= "\n"; $body .= "View:\n"; if (isset($view->title)) { $body .= " title: " . $view->title . "\n"; } if (isset($view->message)) { $body .= " message: " . $view->message . "\n"; } $body .= "\n"; $body .= "Request:\n"; $serverKeys = array('HTTP_USER_AGENT', 'SCRIPT_URI', 'HTTP_REFERER', 'REMOTE_ADDR'); foreach ($serverKeys as $key) { if (array_key_exists($key, $_SERVER)) { $body .= " {$key}: " . $_SERVER[$key] . "\n"; } } $body .= "\n"; $body .= "file: " . $exception->getFile() . ":" . $exception->getLine() . "\n"; $body .= "-- start exception message --\n"; $body .= $exception->getMessage() . "\n"; $body .= "-- end exception message --\n\n"; $body .= "-- start exception trace --\n"; $body .= $exception->getTraceAsString() . "\n"; $body .= "-- end exception trace --\n\n"; $body .= "Request parameters:\n"; $body .= "-- start request params --\n"; $body .= var_export($request->getParams(), TRUE) . "\n"; $body .= "-- end request params --\n\n"; $body .= "Request:\n"; $body .= "-- start request --\n"; $body .= var_export($request, TRUE) . "\n"; $body .= "-- end request --\n\n"; if (isset($_SERVER)) { $body .= "Request header:\n"; $body .= "-- start request header --\n"; $body .= var_export($_SERVER, TRUE) . "\n"; $body .= "-- end request header --\n\n"; } $adminAddress = array('address' => $config->errorController->mailTo->address, 'name' => $config->errorController->mailTo->name); $mail = new Opus_Mail_SendMail(); $mail->sendMail($config->mail->opus->address, $config->mail->opus->name, $subject, $body, array($adminAddress)); return true; }
/** * Perfom work. * * @param Opus_Job $job Job description and attached data. * @return array Array of Jobs to be newly created. */ public function work(Opus_Job $job) { $data = $job->getData(true); $message = $data['message']; $subject = $data['subject']; $users = $data['users']; $from = $this->_getFrom(); $fromName = $this->_getFromName(); if (!is_null($users) and !is_array($users)) { $users = array($users); } $recipient = array(); if ($this->lookupRecipients) { $this->_logger->debug(__CLASS__ . ': Resolving mail addresses for users = {"' . implode('", "', $users) . '"}'); $recipient = $this->getRecipients($users); } else { $recipient = $users; } // if (empty($recipient)) { // $this->_logger->info(__CLASS__ . ': No recipients avaiable. Mail canceled.'); // return true; // } $mailSendMail = new Opus_Mail_SendMail(); $this->_logger->info(__CLASS__ . ': Sending notification email...'); $this->_logger->debug(__CLASS__ . ': sender: ' . $from); $mailSendMail->sendMail($from, $fromName, $subject, $message, $recipient); return true; }