Skip to content

fix(MailQueueHandler): check enable_email toggle before sending queued emails#2563

Open
miaulalala wants to merge 1 commit into
masterfrom
fix/mail-queue-handler-email-toggle
Open

fix(MailQueueHandler): check enable_email toggle before sending queued emails#2563
miaulalala wants to merge 1 commit into
masterfrom
fix/mail-queue-handler-email-toggle

Conversation

@miaulalala
Copy link
Copy Markdown
Collaborator

@miaulalala miaulalala commented May 6, 2026

Summary

The admin Enable notification emails toggle was only checked when queuing new emails (Consumer::receive() / bulkReceive()). The MailQueueHandler::sendEmails() background job that actually delivers emails had no knowledge of the toggle and would send all queued entries regardless.

This means: if emails were already sitting in oc_activity_mq when an admin disabled the toggle, they would still be sent on the next background job run.

The fix adds an early-return guard at the top of sendEmails(), consistent with the checks already in UserSettings::getUserSetting() and filterUsersBySetting(). The queue is intentionally left intact — if the admin re-enables emails, pending notifications can still be delivered.

Related to #2562 (which fixed the same missing check in bulkReceive()).

Test plan

  • composer test:unit passes (327 tests)
  • New test testSendEmailsSkipsWhenAdminEmailDisabled verifies: return value is 0, mailer is never called, queue entries survive
  • Backport to stable33

🤖 Generated with Claude Code

@miaulalala
Copy link
Copy Markdown
Collaborator Author

/backport to stable33

@cypress
Copy link
Copy Markdown

cypress Bot commented May 6, 2026

Activity    Run #3753

Run Properties:  status check failed Failed #3753  •  git commit 53bba77bf0: fix(MailQueueHandler): check enable_email toggle before sending queued emails
Project Activity
Branch Review fix/mail-queue-handler-email-toggle
Run status status check failed Failed #3753
Run duration 02m 38s
Commit git commit 53bba77bf0: fix(MailQueueHandler): check enable_email toggle before sending queued emails
Committer Anna
View all properties for this run ↗︎

Test results
Tests that failed  Failures 2
Tests that were flaky  Flaky 0
Tests that did not run due to a developer annotating a test with .skip  Pending 1
Tests that did not run due to a failure in a mocha hook  Skipped 0
Tests that passed  Passing 7
View all changes introduced in this branch ↗︎

Tests for review

Failed  sidebar.cy.ts • 1 failed test • Run E2E

View Output

Test Artifacts
Check activity listing in the sidebar > Has favorite activity Test Replay Screenshots
Failed  settings.cy.ts • 1 failed test • Run E2E

View Output

Test Artifacts
Check that user's settings survive a reload > Form survive a reload Test Replay Screenshots

@miaulalala
Copy link
Copy Markdown
Collaborator Author

/backport to stable32

Comment thread lib/MailQueueHandler.php Outdated
* @return int Number of users we sent an email to
*/
public function sendEmails(int $limit, int $sendTime, bool $forceSending = false, ?int $restrictEmails = null): int {
if ($this->config->getAppValue('activity', 'enable_email', 'yes') === 'no') {
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.

Might as well inject IAppConfig and use that instead of the deprecated getAppValue, that will avoid having to adapt both the class and the test later on.

@miaulalala miaulalala force-pushed the fix/mail-queue-handler-email-toggle branch from cb519bb to e2703fe Compare May 13, 2026 13:41
@codecov
Copy link
Copy Markdown

codecov Bot commented May 13, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

…d emails

The admin Enable notification emails toggle was only checked when queuing
new emails. The sendEmails() background job had no knowledge of it and
would send all queued entries regardless.

Adds an early-return guard using IAppConfig::getValueString() at the top
of sendEmails(), consistent with the checks in UserSettings. The queue is
left intact so pending notifications can be delivered if the admin
re-enables emails.

AI-Assisted-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Signed-off-by: Anna Larch <anna@nextcloud.com>
@miaulalala miaulalala force-pushed the fix/mail-queue-handler-email-toggle branch from e2703fe to bbd2758 Compare May 13, 2026 13:54
@miaulalala miaulalala requested a review from come-nc May 13, 2026 13:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants