FIX: bounced email can contain multiple status codes

This commit is contained in:
Gerhard Schlager 2018-01-03 17:59:20 +01:00
parent 7ca2e6a80c
commit ceb7590bcb
3 changed files with 49 additions and 1 deletions

View File

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

View File

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

View File

@ -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: <someguy@discourse.org>
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--