/** * Loads a list of Email_Log for the specified parameters, returns an array of Email_Log elements * * @return array */ public function load() { $emailLogs = $this->db->fetchCol("SELECT id FROM email_log" . $this->getCondition() . $this->getOrder() . $this->getOffsetLimit(), $this->model->getConditionVariables()); $emailLogsArray = array(); foreach ($emailLogs as $log) { $emailLogsArray[] = Model\Tool\Email\Log::getById($log); } $this->model->setEmailLogs($emailLogsArray); return $emailLogsArray; }
/** * Returns the EmailLog entry by the given id * * @static * @param integer $id * @return EmailLog|null */ public static function getById($id) { $id = intval($id); if ($id < 1) { return null; } $emailLog = new Model\Tool\Email\Log(); $emailLog->getDao()->getById($id); $emailLog->setEmailLogExistsHtml(); $emailLog->setEmailLogExistsText(); return $emailLog; }
/** * @param MailClient $mail * @return Model\Tool\Email\Log */ public static function logEmail(MailClient $mail) { $emailLog = new Model\Tool\Email\Log(); $document = $mail->getDocument(); if ($document instanceof Model\Document) { $emailLog->setDocumentId($document->getId()); } $emailLog->setRequestUri(htmlspecialchars($_SERVER['REQUEST_URI'])); $emailLog->setParams($mail->getParams()); $emailLog->setSubject($mail->getSubject()); $emailLog->setSentDate(time()); $mailFrom = $mail->getFrom(); if ($mailFrom) { $emailLog->setFrom($mailFrom); } else { $defaultFrom = $mail->getDefaultFrom(); $tmpString = $defaultFrom['email']; if ($defaultFrom['name']) { $tmpString .= " (" . $defaultFrom["name"] . ")"; } $emailLog->setFrom($tmpString); } $html = $mail->getBodyHtml(); if ($html instanceof \Zend_Mime_Part) { $emailLog->setBodyHtml($html->getRawContent()); } $text = $mail->getBodyText(); if ($text instanceof \Zend_Mime_Part) { $emailLog->setBodyText($text->getRawContent()); } $temporaryStorage = $mail->getTemporaryStorage(); foreach (array('To', 'Cc', 'Bcc') as $key) { if (isset($temporaryStorage[$key]) && is_array($temporaryStorage[$key])) { if (method_exists($emailLog, 'set' . $key)) { $emailLog->{"set{$key}"}(self::formatDebugReceivers($temporaryStorage[$key])); } } } $emailLog->save(); return $emailLog; }
/** * Resends the email to the recipients */ public function resendEmailAction() { if (!$this->getUser()->isAllowed("emails")) { throw new \Exception("Permission denied, user needs 'emails' permission."); } $success = false; $emailLog = Tool\Email\Log::getById($this->getParam('id')); if ($emailLog instanceof Tool\Email\Log) { $mail = new Mail(); $mail->preventDebugInformationAppending(); if ($html = $emailLog->getHtmlLog()) { $mail->setBodyHtml($html); } if ($text = $emailLog->getTextLog()) { $mail->setBodyText($text); } $mail->setFrom($emailLog->getFrom()); foreach ($emailLog->getToAsArray() as $entry) { $mail->addTo($entry['email'], $entry['name']); } foreach ($emailLog->getCcAsArray() as $entry) { $mail->addCc($entry['email'], $entry['name']); } foreach ($emailLog->getBccAsArray() as $entry) { $mail->addBcc($entry['email']); } $mail->setSubject($emailLog->getSubject()); $mail->send(); $success = true; } $this->_helper->json(array("success" => $success)); }