Skip to content

fix(mail): trim recipients when sending emails separately (#754) - #869

Merged
bmfmancini merged 1 commit into
Cacti:developfrom
bmfmancini:fix/754-trim-separate-recipients
Nov 6, 2026
Merged

bmfmancini merged 1 commit into
Cacti:developfrom
bmfmancini:fix/754-trim-separate-recipients

Conversation

@bmfmancini

Copy link
Copy Markdown
Member

Description

With Send Emails Separately enabled, thold_mail() split the recipient list on commas without trimming:

$ar_to_email = explode(',', $to_email);
foreach ($ar_to_email as $to) {
	if (filter_var($to, FILTER_VALIDATE_EMAIL) == $to) {

Lists are commonly written with , , so every address after the first (" noc@example.org") failed FILTER_VALIDATE_EMAIL and was skipped, with no log entry. A trailing comma produced an empty entry. Since filter_var('') returns false and false == '' in PHP, mailer() was even called with an empty address.

This PR trims each address, drops empty entries, and logs any address that's still invalid instead of skipping it silently.

This is one of two causes of #754. The other, failed sends not logged in the default mode, is a separate PR.

Related Issue

Part of #754.

Motivation and Context

In send-separately mode, only the first recipient on a typical list ever receives threshold mail.

How Has This Been Tested?

Unit tests (Pest): a new TholdMailSeparateRecipientsTest covers addresses after , and trailing commas, and an invalid address being logged. Both tests fail without the change.

Real poller: Cacti 1.2.32, PHP 8.4, cactid every 60 s, with this exact commit deployed. Send Emails Separately was enabled, and a live threshold was breached with notify_extra = "a@…, b@…" (two local addresses). The setting was restored afterwards.

develop this PR
Alert mails delivered (2 addresses) 1 2

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation repository accordingly.

With "Send Emails Separately" enabled, thold_mail() split the recipient
list on commas without trimming. Lists are commonly joined with ", ", so
every address after the first (" noc@example.org") failed
FILTER_VALIDATE_EMAIL and was skipped without any log entry. A trailing
comma produced an empty entry, and since filter_var('') returns false
and false == '' in PHP, mailer() was even called with an empty address.

Trim each address and drop empty entries, and log any address that is
still invalid instead of skipping it silently.
Copilot AI balanced review requested due to automatic review settings November 6, 2026 05:50

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

@sonarqubecloud

sonarqubecloud Bot commented Nov 6, 2026

Copy link
Copy Markdown

@somethingwithproof somethingwithproof left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No blockers found. The full suite passes on Linux/PHP 8.4; PHP 8.2–8.4 CI is green.

@bmfmancini
bmfmancini merged commit 8a4cbe6 into Cacti:develop Nov 6, 2026
5 checks passed
@bmfmancini
bmfmancini deleted the fix/754-trim-separate-recipients branch November 6, 2026 22:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants