Skip to content

Commit

Permalink
Merge branch 'release/4.0.2'
Browse files Browse the repository at this point in the history
  • Loading branch information
rhukster committed Jun 27, 2023
2 parents 2563fe9 + a159e3e commit 901f8f3
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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

Expand Down
2 changes: 1 addition & 1 deletion blueprints.yaml
Original file line number Diff line number Diff line change
@@ -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
Expand Down
15 changes: 13 additions & 2 deletions classes/Email.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
Expand All @@ -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'));
}
Expand Down Expand Up @@ -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 = [];
Expand All @@ -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);
Expand Down

0 comments on commit 901f8f3

Please sign in to comment.