diff --git a/lib/email/processor.rb b/lib/email/processor.rb index 9c807fc2b8e..30c50c2baef 100644 --- a/lib/email/processor.rb +++ b/lib/email/processor.rb @@ -24,7 +24,7 @@ module Email raise end rescue => e - return handle_bounce(e) if @receiver.is_bounce? + return handle_bounce(e) if @receiver&.is_bounce? log_email_process_failure(@mail, e) incoming_email = @receiver.try(:incoming_email) @@ -156,7 +156,7 @@ module Email end def can_send_rejection_email?(email, type) - return false if @receiver.sent_to_mailinglist_mirror? + 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/lib/email/processor_spec.rb b/spec/lib/email/processor_spec.rb index 4f57124145f..2d0d797b495 100644 --- a/spec/lib/email/processor_spec.rb +++ b/spec/lib/email/processor_spec.rb @@ -48,6 +48,13 @@ RSpec.describe Email::Processor do end end + describe "when mail is not set" do + it "does not raise an error" do + expect { Email::Processor.process!(nil) }.not_to raise_error + expect { Email::Processor.process!("") }.not_to raise_error + end + end + describe "rate limits" do let(:mail) { "From: #{from}\nTo: bar@foo.com\nSubject: FOO BAR\n\nFoo foo bar bar?" } let(:limit_exceeded) { RateLimiter::LimitExceeded.new(10) }