FIX: Prioritize VERP key over final_recipient header in bounced email
Per RFC3464 2.3.2, the final_recipient header may not match the address we originally sent the email to.
This commit is contained in:
parent
0d41d58d27
commit
0644c10bfe
|
@ -513,13 +513,13 @@ module Email
|
|||
def 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]
|
||||
end
|
||||
|
||||
return unless mail[:from]
|
||||
|
|
|
@ -212,6 +212,14 @@ describe Email::Receiver do
|
|||
expect(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'" do
|
||||
expect(user.active).to eq(true)
|
||||
|
||||
|
|
|
@ -0,0 +1,39 @@
|
|||
Delivered-To: foo+verp-14b08c855160d67f2e0c2f8ef36e251e@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: foo+verp-14b08c855160d67f2e0c2f8ef36e251e@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; catchall@b-s-c.co.jp
|
||||
Original-Recipient: rfc822;linux-admin@b-s-c.co.jp
|
||||
Action: failed
|
||||
Status: 4.1.1
|
||||
Diagnostic-Code: X-Postfix; unknown user: "linux-admin"
|
||||
|
||||
--18F5D18A0075.1460023470/some@daemon.com
|
||||
Content-Description: Undelivered Message
|
||||
Content-Type: message/rfc822
|
||||
|
||||
Return-Path: <foo+verp-14b08c855160d67f2e0c2f8ef36e251e@discourse.org>
|
||||
Date: Thu, 07 Apr 2016 03:04:28 -0700 (PDT)
|
||||
From: foo+verp-14b08c855160d67f2e0c2f8ef36e251e@discourse.org
|
||||
X-Discourse-Auto-Generated: marked
|
||||
|
||||
This is the body
|
||||
|
||||
--18F5D18A0075.1460023470/some@daemon.com--
|
Loading…
Reference in New Issue