Skip to content

A platform for community discussion. Free, open, simple.

FIX: Queue incoming email for review when `Authentication-Results` can't be evaluated

Régis Hanold90d67df5cdd
diff --git a/lib/email/receiver.rb b/lib/email/receiver.rb
index 285330d8280..57319cefa85 100644
--- a/lib/email/receiver.rb
+++ b/lib/email/receiver.rb
@@ -423,6 +423,10 @@ module Email
def auth_res_action
@auth_res_action ||= AuthenticationResults.new(@mail.header[:authentication_results]).action
+ rescue StandardError => e
+ # fail closed without losing the post: queue it for review
+ Discourse.warn_exception(e, message: "Failed to evaluate Authentication-Results")
+ @auth_res_action = :enqueue
end
def select_body
diff --git a/spec/lib/email/receiver_spec.rb b/spec/lib/email/receiver_spec.rb
index bd257f48415..f0cd64b6ba5 100644
--- a/spec/lib/email/receiver_spec.rb
+++ b/spec/lib/email/receiver_spec.rb
@@ -902,6 +902,19 @@ RSpec.describe Email::Receiver do
expect(user.reload.silenced?).to be(false)
end
+ it "enqueues the post when evaluating the Authentication-Results header fails" do
+ Email::AuthenticationResults.any_instance.stubs(:action).raises(StandardError)
+ Discourse.expects(:warn_exception).once
+
+ Fabricate(
+ :user,
+ email: "[email protected]",
+ trust_level: TrustLevel[2],
+ refresh_auto_groups: true,
+ )
+ expect { process(:existing_user) }.to change { ReviewableQueuedPost.count }.by(1)
+ end
+
it "adds the 'elided' part of the original message when always_show_trimmed_content is enabled" do
SiteSetting.always_show_trimmed_content = true