X-Git-Url: https://git.cweiske.de/bdrem.git/blobdiff_plain/6506b1ebe1ecaa6630d6d849c39b9e9d53603699..5c88f5e19a69485da44e132e0b102b835eee7f05:/src/bdrem/Renderer/Mail.php?ds=sidebyside diff --git a/src/bdrem/Renderer/Mail.php b/src/bdrem/Renderer/Mail.php index eee8dec..d7aef3e 100644 --- a/src/bdrem/Renderer/Mail.php +++ b/src/bdrem/Renderer/Mail.php @@ -1,10 +1,44 @@ + * @copyright 2014 Christian Weiske + * @license http://www.gnu.org/licenses/agpl.html GNU AGPL v3 + * @link http://cweiske.de/bdrem.htm + */ namespace bdrem; require_once 'Mail/mime.php'; -class Renderer_Mail +/** + * Send out mails + * + * @category Tools + * @package Bdrem + * @author Christian Weiske + * @copyright 2014 Christian Weiske + * @license http://www.gnu.org/licenses/agpl.html GNU AGPL v3 + * @version Release: @package_version@ + * @link http://cweiske.de/bdrem.htm + */ +class Renderer_Mail extends Renderer { + /** + * Render the events - send out mails. + * + * Uses the config's "mail_to" array as recipients. + * Sends out a single mail for each recipient. + * Config "mail_from" can also be used. + * + * @param array $arEvents Array of events to display + * + * @return void + */ public function render($arEvents) { $todays = array(); @@ -23,7 +57,7 @@ class Renderer_Mail $hdrs = array( 'From' => $this->config->get('mail_from', 'birthday@example.org'), - 'Subject' => $subject + 'Auto-Submitted' => 'auto-generated' ); $mime = new \Mail_mime( array( @@ -41,14 +75,30 @@ class Renderer_Mail $hdrs = $mime->headers($hdrs); $textHeaders = ''; foreach ($hdrs as $k => $v) { - $textHeaders .= $k . ':' . $v . "\n"; + $textHeaders .= $k . ': ' . $v . "\n"; } - foreach ((array) $this->config->get('mail_to') as $recipient) { - mail($recipient, $subject, $body, $textHeaders); + if (!$this->config->get('debug', false)) { + foreach ((array) $this->config->get('mail_to') as $recipient) { + mail($recipient, $subject, $body, $textHeaders); + } + } else { + echo "Subject: " . $subject . "\n"; + echo $textHeaders; + echo "\n"; + echo $body; } } + /** + * Shorten the given string to the specified length. + * Adds ... when the string was too long + * + * @param string $str String to shorten + * @param integer $len Maximum length of the string + * + * @return string Shortened string + */ protected function shorten($str, $len) { if (mb_strlen($str) <= $len) {