From 8c51d34100a98d2b1548965bc4a9c5432913a5e7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9gis=20Hanol?= Date: Wed, 22 Jun 2016 20:41:21 +0200 Subject: [PATCH] FIX: receiving a bounce from a deleted user --- lib/email/receiver.rb | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/lib/email/receiver.rb b/lib/email/receiver.rb index 32c809d1852..5c184cecf68 100644 --- a/lib/email/receiver.rb +++ b/lib/email/receiver.rb @@ -150,15 +150,17 @@ module Email bounce_key = verp[/\+verp-(\h{32})@/, 1] if bounce_key && (email_log = EmailLog.find_by(bounce_key: bounce_key)) email_log.update_columns(bounced: true) - - if @mail.error_status.present? - if @mail.error_status.start_with?("4.") - Email::Receiver.update_bounce_score(email_log.user.email, SOFT_BOUNCE_SCORE) - elsif @mail.error_status.start_with?("5.") - Email::Receiver.update_bounce_score(email_log.user.email, HARD_BOUNCE_SCORE) + email = email_log.user.try(:email) || @from_email + if email.present? + if @mail.error_status.present? + if @mail.error_status.start_with?("4.") + Email::Receiver.update_bounce_score(email, SOFT_BOUNCE_SCORE) + elsif @mail.error_status.start_with?("5.") + Email::Receiver.update_bounce_score(email, HARD_BOUNCE_SCORE) + end + elsif is_auto_generated? + Email::Receiver.update_bounce_score(email, HARD_BOUNCE_SCORE) end - elsif is_auto_generated? - Email::Receiver.update_bounce_score(email_log.user.email, HARD_BOUNCE_SCORE) end end end