[TikiWiki-commits] [Git][tikiwiki/tiki][27.x] [BP][FIX] Failed sending mail with no recipients

"ushindi bienvenu \(@usbbush\) via TikiWiki-cvs" <[email protected]>
Newsgroups gmane.comp.cms.tiki.cvs
Message-ID <68a7c5c59d65a_2cd6f24428d0@gitlab-sidekiq-low-urgency-cpu-bound-v2-5f6d84f9cc-qqcc4.mail>

ushindi bienvenu pushed to branch 27.x at Tiki Wiki CMS Groupware / Tiki


Commits:
684bb63d by ushindi bienvenu at 2025-08-22T01:13:56+00:00
[BP][FIX] Failed sending mail with no recipients
---
* [BP][FIX] Failed sending mail with no recipients
---
* [FIX] Failed sending mail with no recipients
---
* [FIX] Failed sending mail with no recipients
---
* [FIX] Failed sending mail with no recipients

See merge request tikiwiki/tiki!8316

See merge request tikiwiki/tiki!8354

See merge request tikiwiki/tiki!8360

See merge request tikiwiki/tiki!8362

- - - - -


1 changed file:

- lib/core/Tiki/Command/MailQueueSendCommand.php


Changes:

=====================================
lib/core/Tiki/Command/MailQueueSendCommand.php
=====================================
@@ -38,32 +38,36 @@ class MailQueueSendCommand extends Command
             $error = '';
 
             if ($mail && (get_class($mail) === 'Laminas\Mail\Message' || get_class($mail) === 'Zend\Mail\Message')) {
-                try {
-                    tiki_send_email($mail);
-                    $title = 'mail';
-                } catch (ZendMailException | SlmMailException $e) {
-                    $title = 'mail error';
-                    $error = $e->getMessage();
-                }
-
-                if ($error || $prefs['log_mail'] == 'y') {
-                    foreach ($mail->getTo() as $destination) {
-                        $logslib->add_log($title, $error . "\n " . $destination->getEmail() . '/' . $mail->getSubject());
-                    }
-                    foreach ($mail->getCc() as $destination) {
-                        $logslib->add_log($title, $error . "\n " . $destination->getEmail() . '/' . $mail->getSubject());
+                $query = 'DELETE FROM tiki_mail_queue WHERE messageId = ?';
+                if (empty($this->collectRecipients($mail))) {
+                    $output->writeln('Deleted object id: ' . $message['messageId'] . ' (mail has no recipients)');
+                } else {
+                    try {
+                        tiki_send_email($mail);
+                        $title = 'mail';
+                    } catch (ZendMailException | SlmMailException $e) {
+                        $title = 'mail error';
+                        $error = $e->getMessage();
                     }
-                    foreach ($mail->getBcc() as $destination) {
-                        $logslib->add_log($title, $error . "\n " . $destination->getEmail() . '/' . $mail->getSubject());
+
+                    if ($error || $prefs['log_mail'] == 'y') {
+                        foreach ($mail->getTo() as $destination) {
+                            $logslib->add_log($title, $error . "\n " . $destination->getEmail() . '/' . $mail->getSubject());
+                        }
+                        foreach ($mail->getCc() as $destination) {
+                            $logslib->add_log($title, $error . "\n " . $destination->getEmail() . '/' . $mail->getSubject());
+                        }
+                        foreach ($mail->getBcc() as $destination) {
+                            $logslib->add_log($title, $error . "\n " . $destination->getEmail() . '/' . $mail->getSubject());
+                        }
                     }
-                }
 
-                if ($error) {
-                    $query = 'UPDATE tiki_mail_queue SET attempts = attempts + 1 WHERE messageId = ?';
-                    $output->writeln('Failed sending mail object id: ' . $message['messageId'] . ' (' . $error . ')');
-                } else {
-                    $query = 'DELETE FROM tiki_mail_queue WHERE messageId = ?';
-                    $output->writeln('Sent.');
+                    if ($error) {
+                        $query = 'UPDATE tiki_mail_queue SET attempts = attempts + 1 WHERE messageId = ?';
+                        $output->writeln('Failed sending mail object id: ' . $message['messageId'] . ' (' . $error . ')');
+                    } else {
+                        $output->writeln('Sent.');
+                    }
                 }
 
                 \TikiDb::get()->query($query, [$message['messageId']]);
@@ -74,4 +78,19 @@ class MailQueueSendCommand extends Command
         $output->writeln('Mail queue processed...');
         return Command::SUCCESS;
     }
+
+    private function collectRecipients($mail)
+    {
+        $recipients = [];
+        foreach ($mail->getTo() as $destination) {
+            $recipients[] = $destination->getEmail();
+        }
+        foreach ($mail->getCc() as $destination) {
+            $recipients[] = $destination->getEmail();
+        }
+        foreach ($mail->getBcc() as $destination) {
+            $recipients[] = $destination->getEmail();
+        }
+        return $recipients;
+    }
 }



View it on GitLab: https://gitlab.com/tikiwiki/tiki/-/commit/684bb63dbf92e4af62b086720ae1ed04f338767f

-- 
View it on GitLab: https://gitlab.com/tikiwiki/tiki/-/commit/684bb63dbf92e4af62b086720ae1ed04f338767f
You're receiving this email because of your account on gitlab.com.

_______________________________________________
TikiWiki-cvs mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/tikiwiki-cvs
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.