diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-14 13:29:16 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-14 13:29:16 +0000 |
commit | 8a985929ed84cdb458a13c66b25f84e41133b24f (patch) | |
tree | 102a3d6e3cb731c6d23263095d0098f99572626d /library/Reporting/Actions/SendMail.php | |
parent | Adding upstream version 0.10.0. (diff) | |
download | icingaweb2-module-reporting-8a985929ed84cdb458a13c66b25f84e41133b24f.tar.xz icingaweb2-module-reporting-8a985929ed84cdb458a13c66b25f84e41133b24f.zip |
Adding upstream version 1.0.1.upstream/1.0.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'library/Reporting/Actions/SendMail.php')
-rw-r--r-- | library/Reporting/Actions/SendMail.php | 40 |
1 files changed, 31 insertions, 9 deletions
diff --git a/library/Reporting/Actions/SendMail.php b/library/Reporting/Actions/SendMail.php index 7c70bf5..a0dc42f 100644 --- a/library/Reporting/Actions/SendMail.php +++ b/library/Reporting/Actions/SendMail.php @@ -1,4 +1,5 @@ <?php + // Icinga Reporting | (c) 2018 Icinga GmbH | GPLv2 namespace Icinga\Module\Reporting\Actions; @@ -9,6 +10,9 @@ use Icinga\Module\Reporting\Hook\ActionHook; use Icinga\Module\Reporting\Mail; use Icinga\Module\Reporting\Report; use ipl\Html\Form; +use ipl\Stdlib\Str; +use ipl\Validator\CallbackValidator; +use ipl\Validator\EmailAddressValidator; class SendMail extends ActionHook { @@ -28,7 +32,9 @@ class SendMail extends ActionHook $mail = new Mail(); - $mail->setFrom(Config::module('reporting')->get('mail', 'from', 'reporting@icinga')); + $mail->setFrom( + Config::module('reporting', 'config', true)->get('mail', 'from', 'reporting@icinga') + ); if (isset($config['subject'])) { $mail->setSubject($config['subject']); @@ -51,9 +57,10 @@ class SendMail extends ActionHook throw new \InvalidArgumentException(); } - $recipients = array_filter(preg_split('/[\s,]+/', $config['recipients'])); + /** @var array<int, string> $recipients */ + $recipients = preg_split('/[\s,]+/', $config['recipients']); - $mail->send(null, $recipients); + $mail->send(null, array_filter($recipients)); } public function initConfigForm(Form $form, Report $report) @@ -66,19 +73,34 @@ class SendMail extends ActionHook } $form->addElement('select', 'type', [ - 'required' => true, - 'label' => t('Type'), - 'options' => $types + 'required' => true, + 'label' => t('Type'), + 'options' => $types ]); $form->addElement('text', 'subject', [ - 'label' => t('Subject'), - 'placeholder' => Mail::DEFAULT_SUBJECT + 'label' => t('Subject'), + 'placeholder' => Mail::DEFAULT_SUBJECT ]); $form->addElement('textarea', 'recipients', [ 'required' => true, - 'label' => t('Recipients') + 'label' => t('Recipients'), + 'validators' => [ + new CallbackValidator(function ($value, CallbackValidator $validator): bool { + $mailValidator = new EmailAddressValidator(); + $mails = Str::trimSplit($value); + foreach ($mails as $mail) { + if (! $mailValidator->isValid($mail)) { + $validator->addMessage(...$mailValidator->getMessages()); + + return false; + } + } + + return true; + }) + ] ]); } } |