A platform for community discussion. Free, open, simple.
FIX: Handle forwarded email quotes around Reply-To display name (#14384)
Martin Brennan4fb7d045a04e
diff --git a/lib/email/receiver.rb b/lib/email/receiver.rbindex 2b2cd363950..1f9e90b32a4 100644--- a/lib/email/receiver.rb+++ b/lib/email/receiver.rb@@ -637,7 +637,10 @@ module Emailcomparison_failed = falsecomparison_headers.each do |comparison_header|- comparison_failed = true if address_field.to_s != mail_object[comparison_header].to_s+ if mail_object[comparison_header].to_s != "#{from_display_name} <#{from_address}>"+ comparison_failed = true+ break+ endendnext if comparison_faileddiff --git a/spec/components/email/receiver_spec.rb b/spec/components/email/receiver_spec.rbindex 3f6e103adc2..7c61a0f62f5 100644--- a/spec/components/email/receiver_spec.rb+++ b/spec/components/email/receiver_spec.rb@@ -870,9 +870,9 @@ describe Email::Receiver doenddescribe "reply-to header" do- it "handles emails where there is a reply-to address, using that instead of the from address" do+ it "handles emails where there is a Reply-To address, using that instead of the from address, if X-Original-From is present" doSiteSetting.block_auto_generated_emails = false- expect { process(:reply_to_different_to_from) }.to change(Topic, :count)+ expect { process(:reply_to_different_to_from) }.to change(Topic, :count).by(1)user = User.lastincoming = IncomingEmail.find_by(message_id: "[email protected]")topic = incoming.topic@@ -880,9 +880,19 @@ describe Email::Receiver doexpect(user.email).to eq("[email protected]")end+ it "allows for quotes around the display name of the Reply-To address" do+ SiteSetting.block_auto_generated_emails = false+ expect { process(:reply_to_different_to_from_quoted_display_name) }.to change(Topic, :count).by(1)+ user = User.last+ incoming = IncomingEmail.find_by(message_id: "[email protected]")+ topic = incoming.topic+ expect(incoming.from_address).to eq("[email protected]")+ expect(user.email).to eq("[email protected]")+ end+it "does not use the reply-to address if an X-Original-From header is not present" doSiteSetting.block_auto_generated_emails = false- expect { process(:reply_to_different_to_from_no_x_original) }.to change(Topic, :count)+ expect { process(:reply_to_different_to_from_no_x_original) }.to change(Topic, :count).by(1)user = User.lastincoming = IncomingEmail.find_by(message_id: "[email protected]")topic = incoming.topic@@ -892,7 +902,7 @@ describe Email::Receiver doit "does not use the reply-to address if the X-Original-From header is different from the reply-to address" doSiteSetting.block_auto_generated_emails = false- expect { process(:reply_to_different_to_from_x_original_different) }.to change(Topic, :count)+ expect { process(:reply_to_different_to_from_x_original_different) }.to change(Topic, :count).by(1)user = User.lastincoming = IncomingEmail.find_by(message_id: "[email protected]")topic = incoming.topicdiff --git a/spec/fixtures/emails/reply_to_different_to_from_quoted_display_name.eml b/spec/fixtures/emails/reply_to_different_to_from_quoted_display_name.emlnew file mode 100644index 00000000000..f74499707c5--- /dev/null+++ b/spec/fixtures/emails/reply_to_different_to_from_quoted_display_name.eml@@ -0,0 +1,16 @@+From: 'Marston, John' via Western Support <[email protected]>+Reply-To: =?iso-8859-1?Q?Marston=2C_John?= <[email protected]>+To: [email protected]+Subject: I need some support+Date: Fri, 15 Jan 2016 00:12:43 +0100+Message-ID: <[email protected]>+Mime-Version: 1.0+Content-Type: text/plain+Content-Transfer-Encoding: 7bit+X-Original-From: Marston, John <[email protected]>+Precedence: list+Mailing-list: list [email protected]; contact+List-ID: <[email protected]>++Ain't no trouble.