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.
This commit is contained in:
Michael Brown 2023-05-03 12:17:19 -04:00
parent 6ce1fbc479
commit 076def505e
No known key found for this signature in database
GPG Key ID: 6C07FB3007CF9360
3 changed files with 15 additions and 1 deletions

View File

@ -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

View File

@ -0,0 +1,10 @@
Return-Path: <discourse@bar.com>
From: Foo Bar <discourse@bar.com>
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.

View File

@ -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 }