diff --git a/CHANGELOG.md b/CHANGELOG.md index f892ce1..f43812d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,10 @@ +# v4.0.2 +## 06/27/2023 + +1. [](#bugfix) + * some recipient handling improvements. e.g. missing `bcc_name` throwing error + * Allow overriding of defaults with a form configuration. Use `null` to remove default email configuration + # v4.0.1 ## 05/20/2023 diff --git a/blueprints.yaml b/blueprints.yaml index 68c89de..995b4c3 100644 --- a/blueprints.yaml +++ b/blueprints.yaml @@ -1,7 +1,7 @@ name: Email slug: email type: plugin -version: 4.0.1 +version: 4.0.2 testing: false description: Enables the emailing system for Grav icon: envelope diff --git a/classes/Email.php b/classes/Email.php index 617bbee..949b0cd 100644 --- a/classes/Email.php +++ b/classes/Email.php @@ -138,8 +138,9 @@ public function buildMessage(array $params, array $vars = []): Message $email = $message->getEmail(); // Extend parameters with defaults. - $params += [ + $defaults = [ 'bcc' => $config->get('plugins.email.bcc', []), + 'bcc_name' => $config->get('plugins.email.bcc_name'), 'body' => $config->get('plugins.email.body', '{% include "forms/data.html.twig" %}'), 'cc' => $config->get('plugins.email.cc', []), 'cc_name' => $config->get('plugins.email.cc_name'), @@ -157,6 +158,12 @@ public function buildMessage(array $params, array $vars = []): Message 'message' => $message ]; + foreach ($defaults as $key => $value) { + if (!key_exists($key, $params)) { + $params[$key] = $value; + } + } + if (!$params['to']) { throw new \RuntimeException($language->translate('PLUGIN_EMAIL.PLEASE_CONFIGURE_A_TO_ADDRESS')); } @@ -237,6 +244,10 @@ public function buildMessage(array $params, array $vars = []): Message */ protected function processRecipients(string $type, array $params): array { + if (array_key_exists($type, $params) && $params[$type] === null) { + return []; + } + $recipients = $params[$type] ?? Grav::instance()['config']->get('plugins.email.'.$type) ?? []; $list = []; @@ -260,7 +271,7 @@ protected function processRecipients(string $type, array $params): array $list[] = $this->createAddress($recipient); } } else { - if (!Utils::contains($recipients, ['<','>']) && ($params[$type."_name"])) { + if (!Utils::contains($recipients, ['<','>']) && (isset($params[$type."_name"]))) { $recipients = [$recipients, $params[$type."_name"]]; } $list[] = $this->createAddress($recipients);