diff --git a/lib/email/receiver.rb b/lib/email/receiver.rb index 78ed3008f35..1cf9754b259 100644 --- a/lib/email/receiver.rb +++ b/lib/email/receiver.rb @@ -169,7 +169,7 @@ module Email email ||= @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) else Email::Receiver.update_bounce_score(email, SiteSetting.hard_bounce_score) diff --git a/spec/components/email/receiver_spec.rb b/spec/components/email/receiver_spec.rb index 5b5d91f5caf..d9da0a04351 100644 --- a/spec/components/email/receiver_spec.rb +++ b/spec/components/email/receiver_spec.rb @@ -81,6 +81,9 @@ describe Email::Receiver do it "raises a BouncerEmailError when email is a bounced email" do expect { 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) end it "logs a blank error" do diff --git a/spec/fixtures/emails/bounced_email_multiple_status_codes.eml b/spec/fixtures/emails/bounced_email_multiple_status_codes.eml new file mode 100644 index 00000000000..3a0328932a4 --- /dev/null +++ b/spec/fixtures/emails/bounced_email_multiple_status_codes.eml @@ -0,0 +1,45 @@ +Delivered-To: someguy@discourse.org +Date: Thu, 7 Apr 2016 19:04:30 +0900 (JST) +From: MAILER-DAEMON@b-s-c.co.jp (Mail Delivery System) +Subject: Undelivered Mail Returned to Sender +To: someguy@discourse.org +MIME-Version: 1.0 +Content-Type: multipart/report; report-type=delivery-status; + boundary="18F5D18A0075.1460023470/some@daemon.com" + +This is a MIME-encapsulated message. + +--18F5D18A0075.1460023470/some@daemon.com +Content-Description: Notification +Content-Type: text/plain; charset=us-ascii + +Your email bounced + +--18F5D18A0075.1460023470/some@daemon.com +Content-Description: Delivery report +Content-Type: message/delivery-status + +Final-Recipient: rfc822; linux-admin@b-s-c.co.jp +Original-Recipient: rfc822;linux-admin@b-s-c.co.jp +Action: failed +Status: 5.1.1 +Diagnostic-Code: X-Postfix; unknown user: "linux-admin" + +Final-Recipient: rfc822; foo@b-s-c.co.jp +Original-Recipient: rfc822;linux-admin@b-s-c.co.jp +Action: failed +Status: 5.1.1 +Diagnostic-Code: X-Postfix; unknown user: "foo" + +--18F5D18A0075.1460023470/some@daemon.com +Content-Description: Undelivered Message +Content-Type: message/rfc822 + +Return-Path: +Date: Thu, 07 Apr 2016 03:04:28 -0700 (PDT) +From: someguy@discourse.org +X-Discourse-Auto-Generated: marked + +This is the body + +--18F5D18A0075.1460023470/some@daemon.com--