diff --git a/CHANGELOG.md b/CHANGELOG.md index f43812d..b47ce53 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,12 @@ +# v4.0.3 +## 06/29/2023 + +1. [](#improved) + * Simplified the `Email::processRecipients()` logic for readability +1. [](#bugfix) + * Fix an issue with 2 email addresses provided with 'just' email and no name [#176](https://github.com/getgrav/grav-plugin-email/issues/176) + * Fix for blank subjectlines when using `Message::setSubject()` in Twig templates [getgrav/grav-plugin-login#299](https://github.com/getgrav/grav-plugin-login/issues/299) + # v4.0.2 ## 06/27/2023 diff --git a/blueprints.yaml b/blueprints.yaml index 995b4c3..442a62c 100644 --- a/blueprints.yaml +++ b/blueprints.yaml @@ -1,7 +1,7 @@ name: Email slug: email type: plugin -version: 4.0.2 +version: 4.0.3 testing: false description: Enables the emailing system for Grav icon: envelope diff --git a/classes/Email.php b/classes/Email.php index 949b0cd..1bc7b1d 100644 --- a/classes/Email.php +++ b/classes/Email.php @@ -253,33 +253,30 @@ protected function processRecipients(string $type, array $params): array $list = []; if (!empty($recipients)) { - if (is_array($recipients) && Utils::isAssoc($recipients)) { - $list[] = $this->createAddress($recipients); + if (is_array($recipients)) { + if (Utils::isAssoc($recipients) || (count($recipients) ===2 && $this->isValidEmail($recipients[0]) && !$this->isValidEmail($recipients[1]))) { + $list[] = $this->createAddress($recipients); + } else { + foreach ($recipients as $recipient) { + $list[] = $this->createAddress($recipient); + } + } } else { - if (is_array($recipients)) { - if (count($recipients) ===2 && $this->isValidEmail($recipients[0]) && is_string($recipients[1])) { - $list[] = $this->createAddress($recipients); - } else { - foreach ($recipients as $recipient) { - $list[] = $this->createAddress($recipient); - } + if (is_string($recipients) && Utils::contains($recipients, ',')) { + $recipients = array_map('trim', explode(',', $recipients)); + foreach ($recipients as $recipient) { + $list[] = $this->createAddress($recipient); } } else { - if (is_string($recipients) && Utils::contains($recipients, ',')) { - $recipients = array_map('trim', explode(',', $recipients)); - foreach ($recipients as $recipient) { - $list[] = $this->createAddress($recipient); - } - } else { - if (!Utils::contains($recipients, ['<','>']) && (isset($params[$type."_name"]))) { - $recipients = [$recipients, $params[$type."_name"]]; - } - $list[] = $this->createAddress($recipients); + if (!Utils::contains($recipients, ['<','>']) && (isset($params[$type."_name"]))) { + $recipients = [$recipients, $params[$type."_name"]]; } + $list[] = $this->createAddress($recipients); } } } + return $list; } diff --git a/classes/Message.php b/classes/Message.php index fb691f8..066a209 100644 --- a/classes/Message.php +++ b/classes/Message.php @@ -18,6 +18,12 @@ public function subject($subject): self return $this; } + public function setSubject($subject): self + { + $this->subject($subject); + return $this; + } + public function to($to): self { $this->email->to($to);