Project

General

Profile

Actions

Defect #44300

open

Mailer.with_deliveries(false) does not prevent emails from being sent

Added by Vincent Robert 1 day ago.

Status:
New
Priority:
Normal
Assignee:
-
Category:
Email notifications
Target version:
-
Resolution:
Affected version:

Description

While investigating #44299 on a development instance where email delivery is disabled, and with the "Send email notifications during the project copy" box left unchecked, I noticed that the emails were pushed to the job queue nevertheless.

Mailer.with_deliveries only flips ActionMailer::Base.perform_deliveries, and that flag is read when the mail is delivered. Since Redmine sends everything with deliver_later, the Mailer::DeliveryJob runs after the block has already restored the flag or, with a queue backend, in a process where it was never false at all. So the mails are enqueued and sent.

The only caller may be the "Send email notifications during the project copy" checkbox of ProjectsController#copy. Unchecking it does not prevent anything: copying a project, I get one Mailer::DeliveryJob enqueued per copied issue, and the worker delivers them.

Proposed patch: skip the enqueuing itself.

class DeliveryJob < ActionMailer::MailDeliveryJob
  before_enqueue {throw :abort unless ActionMailer::Base.perform_deliveries}

This makes with_deliveries(false) effective whatever the queue adapter, and it also stops piling up delivery jobs that are discarded at delivery time on instances where email is not configured (perform_deliveries defaults to false in config/application.rb).


Files

No data to display

Actions

Also available in: Atom PDF