From 8f7cfc29db1890f5b2d2548788933a4e1319a2e8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Fr=C4=85ckiewicz?= Date: Tue, 23 Apr 2019 05:03:31 +0200 Subject: [PATCH] FIX: Detect SNS notifications for SES correctly (#7284) * Fix handling SNS notifications for AWS SES This fixes detection of email bounce by: - removing hard requirement for email ID, ID in webhook msg never equals this in email_log - gets bounce_score from user stats instead of nonexistent field in webhook msg * Remove empty line * Prettify access to EmailLog for parsing SNS notification Co-Authored-By: SystemZ --- app/jobs/regular/process_sns_notification.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/jobs/regular/process_sns_notification.rb b/app/jobs/regular/process_sns_notification.rb index ab26c258d64..fb8447d825c 100644 --- a/app/jobs/regular/process_sns_notification.rb +++ b/app/jobs/regular/process_sns_notification.rb @@ -22,11 +22,11 @@ module Jobs return unless Aws::SNS::MessageVerifier.new.authentic?(raw) message.dig("bounce", "bouncedRecipients").each do |r| - if email_log = EmailLog.find_by(message_id: message_id, to_address: r["emailAddress"]) + if email_log = EmailLog.order("created_at DESC").where(to_address: r["emailAddress"]).first email_log.update_columns(bounced: true) if email_log.user&.email.present? - if r["status"]&.start_with?["4."] || bounce_type == "Transient" + if email_log.user.user_stat.bounce_score.to_s.start_with?("4.") || bounce_type == "Transient" Email::Receiver.update_bounce_score(email_log.user.email, SiteSetting.soft_bounce_score) else Email::Receiver.update_bounce_score(email_log.user.email, SiteSetting.hard_bounce_score)