diff --git a/lib/email/processor.rb b/lib/email/processor.rb index c93a2b92a1d..f212fef6678 100644 --- a/lib/email/processor.rb +++ b/lib/email/processor.rb @@ -13,17 +13,17 @@ module Email def process! begin - receiver = Email::Receiver.new(@mail) - receiver.process! + @receiver = Email::Receiver.new(@mail) + @receiver.process! rescue RateLimiter::LimitExceeded @retry_on_rate_limit ? Jobs.enqueue(:process_email, mail: @mail) : raise rescue Email::Receiver::BouncedEmailError => e # never reply to bounced emails log_email_process_failure(@mail, e) - set_incoming_email_rejection_message(receiver.incoming_email, I18n.t("emails.incoming.errors.bounced_email_error")) + set_incoming_email_rejection_message(@receiver.incoming_email, I18n.t("emails.incoming.errors.bounced_email_error")) rescue => e log_email_process_failure(@mail, e) - incoming_email = receiver.try(:incoming_email) + incoming_email = @receiver.try(:incoming_email) rejection_message = handle_failure(@mail, e) if rejection_message.present? set_incoming_email_rejection_message(incoming_email, rejection_message.body.to_s) @@ -94,6 +94,7 @@ module Email end def can_send_rejection_email?(email, type) + return false if @receiver.sent_to_mailinglist_mirror? return true if type == :email_reject_unrecognized_error key = "rejection_email:#{email}:#{type}:#{Date.today}" diff --git a/spec/components/email/processor_spec.rb b/spec/components/email/processor_spec.rb index c3291c439d8..d7c5113f9b2 100644 --- a/spec/components/email/processor_spec.rb +++ b/spec/components/email/processor_spec.rb @@ -87,4 +87,22 @@ describe Email::Processor do end + context "mailinglist mirror" do + before do + SiteSetting.email_in = true + Fabricate(:mailinglist_mirror_category) + end + + it "does not send rejection email" do + Email::Receiver.any_instance.stubs(:process_internal).raises("boom") + + email = <<~EMAIL + From: foo@example.com + To: list@example.com + Subject: Hello world + EMAIL + + expect { Email::Processor.process!(email) }.to_not change { EmailLog.count } + end + end end diff --git a/spec/fabricators/category_fabricator.rb b/spec/fabricators/category_fabricator.rb index 582619f23bb..67e498ab163 100644 --- a/spec/fabricators/category_fabricator.rb +++ b/spec/fabricators/category_fabricator.rb @@ -29,3 +29,9 @@ end Fabricator(:link_category, from: :category) do before_validation { |category, transients| category.topic_featured_link_allowed = true } end + +Fabricator(:mailinglist_mirror_category, from: :category) do + email_in 'list@example.com' + email_in_allow_strangers true + mailinglist_mirror true +end