Skip to content

Commit

Permalink
Merge branch 'release/3.1.4'
Browse files Browse the repository at this point in the history
  • Loading branch information
rhukster committed Nov 16, 2021
2 parents 859a564 + bebb2f1 commit 0722d61
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 10 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# v3.1.4
## 11/16/2021

1. [](#improved)
* Added second parameter to `Email::send()` to get failed recipients

# v3.1.3
## 07/19/2021

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: 3.1.3
version: 3.1.4
testing: false
description: Enables the emailing system for Grav
icon: envelope
Expand Down
20 changes: 11 additions & 9 deletions classes/Email.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,13 +101,14 @@ public function image($data = null, $filename = null, $contentType = null)
* Send email.
*
* @param \Swift_Message $message
* @param array|null $failedRecipients
* @return int
*/
public function send($message)
public function send($message, &$failedRecipients = null)
{
$mailer = $this->getMailer();

$result = $mailer ? $mailer->send($message) : 0;
$result = $mailer ? $mailer->send($message, $failedRecipients) : 0;

// Check if emails and debugging are both enabled.
if ($mailer && $this->debug()) {
Expand Down Expand Up @@ -181,24 +182,26 @@ public function buildMessage(array $params, array $vars = [])
switch ($key) {
case 'body':
if (is_string($value)) {
$body = $twig->processString($value, $vars);
if (strpos($value, '{{') !== false || strpos($value, '{%') !== false) {
$body = $twig->processString($value, $vars);
} else {
$body = $value;
}

if ($params['process_markdown'] && $params['content_type'] === 'text/html') {
$parsedown = new Parsedown();
$body = $parsedown->text($body);
}

if ($params['template']) {
$vars = array_merge($vars, ['content' => $body]);
$body = $twig->processTemplate($params['template'], $vars);
$body = $twig->processTemplate($params['template'], ['content' => $body] + $vars);
}

$content_type = !empty($params['content_type']) ? $twig->processString($params['content_type'], $vars) : null;
$charset = !empty($params['charset']) ? $twig->processString($params['charset'], $vars) : null;

$message->setBody($body, $content_type, $charset);
}
elseif (is_array($value)) {
} elseif (is_array($value)) {
foreach ($value as $body_part) {
$body_part += [
'charset' => $params['charset'],
Expand All @@ -213,8 +216,7 @@ public function buildMessage(array $params, array $vars = [])
}

if (isset($body_part['template'])) {
$vars = array_merge($vars, ['content' => $body]);
$body = $twig->processTemplate($body_part['template'], $vars);
$body = $twig->processTemplate($body_part['template'], ['content' => $body] + $vars);
}

$content_type = !empty($body_part['content_type']) ? $twig->processString($body_part['content_type'], $vars) : null;
Expand Down

0 comments on commit 0722d61

Please sign in to comment.