mirror of
https://github.com/discourse/discourse.git
synced 2025-05-22 21:01:04 +08:00
DEV: Add bounce_error_code to EmailLog (#15948)
Whenever we got a bounced email in the Email::Receiver we previously would just set bounced: true on the EmailLog and discard the status/diagnostic code. This commit changes this flow to store the bounce error code (defined in the RFC at https://www.iana.org/assignments/smtp-enhanced-status-codes/smtp-enhanced-status-codes.xhtml) not just in the Email::Receiver, but also via webhook events from other mail services and from SNS. This commit does not surface the bounce error in the UI, we can do that later if necessary.
This commit is contained in:
@ -238,16 +238,20 @@ module Email
|
||||
|
||||
def handle_bounce
|
||||
@incoming_email.update_columns(is_bounce: true)
|
||||
mail_error_statuses = Array.wrap(@mail.error_status)
|
||||
|
||||
if email_log.present?
|
||||
email_log.update_columns(bounced: true)
|
||||
email_log.update_columns(
|
||||
bounced: true,
|
||||
bounce_error_code: mail_error_statuses.first
|
||||
)
|
||||
post = email_log.post
|
||||
topic = email_log.topic
|
||||
end
|
||||
|
||||
DiscourseEvent.trigger(:email_bounce, @mail, @incoming_email, @email_log)
|
||||
|
||||
if @mail.error_status.present? && Array.wrap(@mail.error_status).any? { |s| s.start_with?("4.") }
|
||||
if mail_error_statuses.any? { |s| s.start_with?(Email::SMTP_STATUS_TRANSIENT_FAILURE) }
|
||||
Email::Receiver.update_bounce_score(@from_email, SiteSetting.soft_bounce_score)
|
||||
else
|
||||
Email::Receiver.update_bounce_score(@from_email, SiteSetting.hard_bounce_score)
|
||||
|
Reference in New Issue
Block a user