A platform for community discussion. Free, open, simple.
FIX: bounced email can contain multiple status codes
Gerhard Schlagerceb7590bcb2e
diff --git a/lib/email/receiver.rb b/lib/email/receiver.rbindex 78ed3008f35..1cf9754b259 100644--- a/lib/email/receiver.rb+++ b/lib/email/receiver.rb@@ -169,7 +169,7 @@ module Emailemail ||= @from_email- if @mail.error_status.present? && @mail.error_status.start_with?("4.")+ if @mail.error_status.present? && Array.wrap(@mail.error_status).any? { |s| s.start_with?("4.") }Email::Receiver.update_bounce_score(email, SiteSetting.soft_bounce_score)elseEmail::Receiver.update_bounce_score(email, SiteSetting.hard_bounce_score)diff --git a/spec/components/email/receiver_spec.rb b/spec/components/email/receiver_spec.rbindex 5b5d91f5caf..d9da0a04351 100644--- a/spec/components/email/receiver_spec.rb+++ b/spec/components/email/receiver_spec.rb@@ -81,6 +81,9 @@ describe Email::Receiver doit "raises a BouncerEmailError when email is a bounced email" doexpect { process(:bounced_email) }.to raise_error(Email::Receiver::BouncedEmailError)expect(IncomingEmail.last.is_bounce).to eq(true)++ expect { process(:bounced_email_multiple_status_codes) }.to raise_error(Email::Receiver::BouncedEmailError)+ expect(IncomingEmail.last.is_bounce).to eq(true)endit "logs a blank error" dodiff --git a/spec/fixtures/emails/bounced_email_multiple_status_codes.eml b/spec/fixtures/emails/bounced_email_multiple_status_codes.emlnew file mode 100644index 00000000000..3a0328932a4--- /dev/null+++ b/spec/fixtures/emails/bounced_email_multiple_status_codes.eml@@ -0,0 +1,45 @@+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: 5.1.1+Diagnostic-Code: X-Postfix; unknown user: "linux-admin"++Final-Recipient: rfc822; [email protected]+Original-Recipient: rfc822;[email protected]+Action: failed+Status: 5.1.1+Diagnostic-Code: X-Postfix; unknown user: "foo"++--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]