From 076def505eab99adf13a04fc76be012a16f0076c Mon Sep 17 00:00:00 2001 From: Michael Brown Date: Wed, 3 May 2023 12:17:19 -0400 Subject: [PATCH] FIX: email receiver should ignore x-auto-response-suppress This header is used by Microsoft Exchange to indicate when certain types of autoresponses should not be generated for an email. It triggers our "is this mail autogenerated?" detection, but should not be used for this purpose. --- lib/email/receiver.rb | 2 +- spec/fixtures/emails/quirks_exchange_xars.eml | 10 ++++++++++ spec/lib/email/receiver_spec.rb | 4 ++++ 3 files changed, 15 insertions(+), 1 deletion(-) create mode 100644 spec/fixtures/emails/quirks_exchange_xars.eml diff --git a/lib/email/receiver.rb b/lib/email/receiver.rb index 73d468e4ac3..1d5a044d35f 100644 --- a/lib/email/receiver.rb +++ b/lib/email/receiver.rb @@ -383,7 +383,7 @@ module Email @mail[:subject].to_s[ /\A\s*(Auto:|Automatic reply|Autosvar|Automatisk svar|Automatisch antwoord|Abwesenheitsnotiz|Risposta Non al computer|Automatisch antwoord|Auto Response|Respuesta automática|Fuori sede|Out of Office|Frånvaro|Réponse automatique)/i ] || - @mail.header.to_s[ + @mail.header.reject { |h| h.name.downcase == "x-auto-response-suppress" }.to_s[ /auto[\-_]?(response|submitted|replied|reply|generated|respond)|holidayreply|machinegenerated/i ] end diff --git a/spec/fixtures/emails/quirks_exchange_xars.eml b/spec/fixtures/emails/quirks_exchange_xars.eml new file mode 100644 index 00000000000..16bd2d60e34 --- /dev/null +++ b/spec/fixtures/emails/quirks_exchange_xars.eml @@ -0,0 +1,10 @@ +Return-Path: +From: Foo Bar +To: reply+4f97315cc828096c9cb34c6f1a0d6fe8@bar.com +Date: Fri, 15 Jan 2016 00:12:43 +0100 +Message-ID: <21@foo.bar.mail> +Mime-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +X-Auto-Response-Suppress: DR, RN, NRN, OOF, AutoReply + +Some thing. diff --git a/spec/lib/email/receiver_spec.rb b/spec/lib/email/receiver_spec.rb index 99035646be8..4910880bc81 100644 --- a/spec/lib/email/receiver_spec.rb +++ b/spec/lib/email/receiver_spec.rb @@ -521,6 +521,10 @@ RSpec.describe Email::Receiver do expect { process(:invalid_from_2) }.to raise_error(Email::Receiver::NoSenderDetectedError) end + it "doesn't raise an AutoGeneratedEmailError due to an X-Auto-Response-Suppress header" do + expect { process(:quirks_exchange_xars) }.to change { topic.posts.count } + end + it "doesn't raise an AutoGeneratedEmailError when the mail is auto generated but is allowlisted" do SiteSetting.auto_generated_allowlist = "foo@bar.com|discourse@bar.com" expect { process(:auto_generated_allowlisted) }.to change { topic.posts.count }