From 5c88f5e19a69485da44e132e0b102b835eee7f05 Mon Sep 17 00:00:00 2001 From: Christian Weiske Date: Fri, 17 Jun 2016 21:27:16 +0200 Subject: [PATCH 1/1] debug option for mail renderer --- src/bdrem/Config.php | 6 ++++++ src/bdrem/Renderer/Mail.php | 13 ++++++++++--- src/bdrem/UserInterface.php | 9 +++++++++ 3 files changed, 25 insertions(+), 3 deletions(-) diff --git a/src/bdrem/Config.php b/src/bdrem/Config.php index f586ed3..693307e 100644 --- a/src/bdrem/Config.php +++ b/src/bdrem/Config.php @@ -44,6 +44,12 @@ class Config */ public $daysNext; + /** + * Development helper + * @var boolean + */ + public $debug; + /** * Locale to render the dates in, e.g. "de_DE.UTF-8" * @var string diff --git a/src/bdrem/Renderer/Mail.php b/src/bdrem/Renderer/Mail.php index bc7e220..d7aef3e 100644 --- a/src/bdrem/Renderer/Mail.php +++ b/src/bdrem/Renderer/Mail.php @@ -75,11 +75,18 @@ class Renderer_Mail extends Renderer $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; } } diff --git a/src/bdrem/UserInterface.php b/src/bdrem/UserInterface.php index b0b21cc..8a25bf4 100644 --- a/src/bdrem/UserInterface.php +++ b/src/bdrem/UserInterface.php @@ -149,6 +149,14 @@ abstract class UserInterface 'action' => 'StoreString' ) ); + $parser->addOption( + 'debug', + array( + 'long_name' => '--debug', + 'description' => 'Development helper (mail)', + 'action' => 'StoreTrue' + ) + ); return $parser; } @@ -171,6 +179,7 @@ abstract class UserInterface $this->config->daysNext = $result->options['daysNext']; $this->config->daysPrev = $result->options['daysPrev']; + $this->config->debug = $result->options['debug']; $this->config->renderer = $result->options['renderer']; $this->config->stopOnEmpty = $result->options['stopOnEmpty']; $this->config->setDate($result->options['date']); -- 2.30.2