From ec269a568c074a1446f8c363e98da42d2c585ce3 Mon Sep 17 00:00:00 2001 From: Colin Darie Date: Mon, 3 Jun 2024 22:38:23 +0200 Subject: [PATCH] fix(mailer): fix delivery prevented with bcc --- app/lib/balancer_delivery_method.rb | 1 + spec/lib/balancer_delivery_method_spec.rb | 11 +++++++++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/app/lib/balancer_delivery_method.rb b/app/lib/balancer_delivery_method.rb index 2ed33ae91..4ad5d5728 100644 --- a/app/lib/balancer_delivery_method.rb +++ b/app/lib/balancer_delivery_method.rb @@ -45,6 +45,7 @@ class BalancerDeliveryMethod def prevent_delivery?(mail) return false if mail[BYPASS_UNVERIFIED_MAIL_PROTECTION].present? + return false if mail.to.blank? # bcc list user = User.find_by(email: mail.to.first) return user.unverified_email? if user.present? diff --git a/spec/lib/balancer_delivery_method_spec.rb b/spec/lib/balancer_delivery_method_spec.rb index 659adb46e..92cb80082 100644 --- a/spec/lib/balancer_delivery_method_spec.rb +++ b/spec/lib/balancer_delivery_method_spec.rb @@ -2,8 +2,8 @@ RSpec.describe BalancerDeliveryMethod do class ExampleMailer < ApplicationMailer include BalancedDeliveryConcern - def greet(name, bypass_unverified_mail_protection: true) - mail(to: name, from: "smtp_from", body: "Hello #{name}") + def greet(name, bypass_unverified_mail_protection: true, **mail_args) + mail(to: name, from: "smtp_from", body: "Hello #{name}", **mail_args) bypass_unverified_mail_protection! if bypass_unverified_mail_protection end @@ -202,6 +202,13 @@ RSpec.describe BalancerDeliveryMethod do it { expect(mail).to have_been_delivered_using(MockSmtp) } end end + + context 'when there are only bcc recipients' do + let(:bypass_unverified_mail_protection) { false } + let(:mail) { ExampleMailer.greet(nil, bypass_unverified_mail_protection: false, bcc: ["'u@a.com'"]) } + + it { expect(mail).to have_been_delivered_using(MockSmtp) } + end end # Helpers