fix(mailer): fix delivery prevented with bcc

This commit is contained in:
Colin Darie 2024-06-03 22:38:23 +02:00
parent 395967e0a1
commit ec269a568c
No known key found for this signature in database
GPG key ID: 4FB865FDBCA4BCC4
2 changed files with 10 additions and 2 deletions

View file

@ -45,6 +45,7 @@ class BalancerDeliveryMethod
def prevent_delivery?(mail) def prevent_delivery?(mail)
return false if mail[BYPASS_UNVERIFIED_MAIL_PROTECTION].present? 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) user = User.find_by(email: mail.to.first)
return user.unverified_email? if user.present? return user.unverified_email? if user.present?

View file

@ -2,8 +2,8 @@ RSpec.describe BalancerDeliveryMethod do
class ExampleMailer < ApplicationMailer class ExampleMailer < ApplicationMailer
include BalancedDeliveryConcern include BalancedDeliveryConcern
def greet(name, bypass_unverified_mail_protection: true) def greet(name, bypass_unverified_mail_protection: true, **mail_args)
mail(to: name, from: "smtp_from", body: "Hello #{name}") mail(to: name, from: "smtp_from", body: "Hello #{name}", **mail_args)
bypass_unverified_mail_protection! if bypass_unverified_mail_protection bypass_unverified_mail_protection! if bypass_unverified_mail_protection
end end
@ -202,6 +202,13 @@ RSpec.describe BalancerDeliveryMethod do
it { expect(mail).to have_been_delivered_using(MockSmtp) } it { expect(mail).to have_been_delivered_using(MockSmtp) }
end end
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 end
# Helpers # Helpers