A platform for community discussion. Free, open, simple.
FIX: Prioritize VERP key over final_recipient header in bounced email
David Taylor0644c10bfefe
diff --git a/lib/email/receiver.rb b/lib/email/receiver.rbindex 68a5fa817c6..2f5bc9c806b 100644--- a/lib/email/receiver.rb+++ b/lib/email/receiver.rb@@ -513,13 +513,13 @@ module Emaildef parse_from_field(mail = nil)mail ||= @mail- if mail.bounced?+ if email_log.present?+ email = email_log.to_address || email_log.user&.email+ return [email, email_log.user&.username]+ elsif mail.bounced?Array.wrap(mail.final_recipient).each do |from|return extract_from_address_and_name(from)end- elsif email_log.present?- email = email_log.user&.email || email_log.to_address- return [email, email_log.user&.username]endreturn unless mail[:from]diff --git a/spec/components/email/receiver_spec.rb b/spec/components/email/receiver_spec.rbindex d3a89acb13b..71d57a8f6d2 100644--- a/spec/components/email/receiver_spec.rb+++ b/spec/components/email/receiver_spec.rb@@ -212,6 +212,14 @@ describe Email::Receiver doexpect(email_log_2.bounced).to eq(true)end+ it "works when the final recipient is different" do+ expect { process(:verp_bounce_different_final_recipient) }.to raise_error(Email::Receiver::BouncedEmailError)++ email_log.reload+ expect(email_log.bounced).to eq(true)+ expect(email_log.user.user_stat.bounce_score).to eq(SiteSetting.soft_bounce_score)+ end+it "sends a system message once they reach the 'bounce_score_threshold'" doexpect(user.active).to eq(true)diff --git a/spec/fixtures/emails/verp_bounce_different_final_recipient.eml b/spec/fixtures/emails/verp_bounce_different_final_recipient.emlnew file mode 100644index 00000000000..cc6e4480f79--- /dev/null+++ b/spec/fixtures/emails/verp_bounce_different_final_recipient.eml@@ -0,0 +1,39 @@+Delivered-To: [email protected]+Date: Thu, 7 Apr 2016 19:04:30 +0900 (JST)+From: [email protected] (Mail Delivery System)+Subject: Undelivered Mail Returned to Sender+To: [email protected]+MIME-Version: 1.0+Content-Type: multipart/report; report-type=delivery-status;+ boundary="18F5D18A0075.1460023470/[email protected]"++This is a MIME-encapsulated message.++--18F5D18A0075.1460023470/[email protected]+Content-Description: Notification+Content-Type: text/plain; charset=us-ascii++Your email bounced++--18F5D18A0075.1460023470/[email protected]+Content-Description: Delivery report+Content-Type: message/delivery-status++Final-Recipient: rfc822; [email protected]+Original-Recipient: rfc822;[email protected]+Action: failed+Status: 4.1.1+Diagnostic-Code: X-Postfix; unknown user: "linux-admin"++--18F5D18A0075.1460023470/[email protected]+Content-Description: Undelivered Message+Content-Type: message/rfc822++Return-Path: <[email protected]>+Date: Thu, 07 Apr 2016 03:04:28 -0700 (PDT)+From: [email protected]+X-Discourse-Auto-Generated: marked++This is the body++--18F5D18A0075.1460023470/[email protected]