FIX: Prevent Email Processor errors when mail is blank or nil (#21292)

Currently processing emails that are blank or have a nil value for the mail will cause several errors.

This update allows emails with blank body or missing sender to log the blank email error to the mail logs rather than throwing an error.
This commit is contained in:
David Battersby 2023-05-18 10:39:37 +08:00 committed by GitHub
parent 4ec9a947dc
commit 1de8361d2e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 2 deletions

View File

@ -24,7 +24,7 @@ module Email
raise raise
end end
rescue => e rescue => e
return handle_bounce(e) if @receiver.is_bounce? return handle_bounce(e) if @receiver&.is_bounce?
log_email_process_failure(@mail, e) log_email_process_failure(@mail, e)
incoming_email = @receiver.try(:incoming_email) incoming_email = @receiver.try(:incoming_email)
@ -156,7 +156,7 @@ module Email
end end
def can_send_rejection_email?(email, type) 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 return true if type == :email_reject_unrecognized_error
key = "rejection_email:#{email}:#{type}:#{Date.today}" key = "rejection_email:#{email}:#{type}:#{Date.today}"

View File

@ -48,6 +48,13 @@ RSpec.describe Email::Processor do
end end
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 describe "rate limits" do
let(:mail) { "From: #{from}\nTo: bar@foo.com\nSubject: FOO BAR\n\nFoo foo bar bar?" } let(:mail) { "From: #{from}\nTo: bar@foo.com\nSubject: FOO BAR\n\nFoo foo bar bar?" }
let(:limit_exceeded) { RateLimiter::LimitExceeded.new(10) } let(:limit_exceeded) { RateLimiter::LimitExceeded.new(10) }