Skip to content

Commit 901f8f3

Browse files
committed
Merge branch 'release/4.0.2'
2 parents 2563fe9 + a159e3e commit 901f8f3

File tree

3 files changed

+21
-3
lines changed

3 files changed

+21
-3
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
# v4.0.2
2+
## 06/27/2023
3+
4+
1. [](#bugfix)
5+
* some recipient handling improvements. e.g. missing `bcc_name` throwing error
6+
* Allow overriding of defaults with a form configuration. Use `null` to remove default email configuration
7+
18
# v4.0.1
29
## 05/20/2023
310

blueprints.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name: Email
22
slug: email
33
type: plugin
4-
version: 4.0.1
4+
version: 4.0.2
55
testing: false
66
description: Enables the emailing system for Grav
77
icon: envelope

classes/Email.php

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,8 +138,9 @@ public function buildMessage(array $params, array $vars = []): Message
138138
$email = $message->getEmail();
139139

140140
// Extend parameters with defaults.
141-
$params += [
141+
$defaults = [
142142
'bcc' => $config->get('plugins.email.bcc', []),
143+
'bcc_name' => $config->get('plugins.email.bcc_name'),
143144
'body' => $config->get('plugins.email.body', '{% include "forms/data.html.twig" %}'),
144145
'cc' => $config->get('plugins.email.cc', []),
145146
'cc_name' => $config->get('plugins.email.cc_name'),
@@ -157,6 +158,12 @@ public function buildMessage(array $params, array $vars = []): Message
157158
'message' => $message
158159
];
159160

161+
foreach ($defaults as $key => $value) {
162+
if (!key_exists($key, $params)) {
163+
$params[$key] = $value;
164+
}
165+
}
166+
160167
if (!$params['to']) {
161168
throw new \RuntimeException($language->translate('PLUGIN_EMAIL.PLEASE_CONFIGURE_A_TO_ADDRESS'));
162169
}
@@ -237,6 +244,10 @@ public function buildMessage(array $params, array $vars = []): Message
237244
*/
238245
protected function processRecipients(string $type, array $params): array
239246
{
247+
if (array_key_exists($type, $params) && $params[$type] === null) {
248+
return [];
249+
}
250+
240251
$recipients = $params[$type] ?? Grav::instance()['config']->get('plugins.email.'.$type) ?? [];
241252

242253
$list = [];
@@ -260,7 +271,7 @@ protected function processRecipients(string $type, array $params): array
260271
$list[] = $this->createAddress($recipient);
261272
}
262273
} else {
263-
if (!Utils::contains($recipients, ['<','>']) && ($params[$type."_name"])) {
274+
if (!Utils::contains($recipients, ['<','>']) && (isset($params[$type."_name"]))) {
264275
$recipients = [$recipients, $params[$type."_name"]];
265276
}
266277
$list[] = $this->createAddress($recipients);

0 commit comments

Comments
 (0)