From 98674ab3817148e6c5e15acd7b48a956e3ef58d2 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Karl=20Erik=20=C3=95unapuu?=
Date: Mon, 21 Sep 2020 13:47:57 +0300
Subject: [PATCH] Reflect new bounced mail structure
---
app/models/bounced_mail_address.rb | 36 ++++++++-----------
.../bounced_mail_addresses/show.html.erb | 18 ++++++----
2 files changed, 26 insertions(+), 28 deletions(-)
diff --git a/app/models/bounced_mail_address.rb b/app/models/bounced_mail_address.rb
index 02bb42337..61679f543 100644
--- a/app/models/bounced_mail_address.rb
+++ b/app/models/bounced_mail_address.rb
@@ -1,6 +1,5 @@
class BouncedMailAddress < ApplicationRecord
- validates :email, presence: true
- validates :bounce_reason, :recipient_json, :response_json, presence: true
+ validates :email, :message_id, :bounce_type, :bounce_subtype, :action, :status, presence: true
before_validation :assign_bounce_reason
def assign_bounce_reason
@@ -9,31 +8,24 @@ class BouncedMailAddress < ApplicationRecord
self.bounce_reason = "#{action} (#{status} #{diagnostic})"
end
- def diagnostic
- return unless recipient_json
-
- recipient_json['diagnosticCode']
- end
-
- def action
- return unless recipient_json
-
- recipient_json['action']
- end
-
- def status
- return unless recipient_json
-
- recipient_json['status']
- end
-
def self.record(json)
bounced_records = json['bounce']['bouncedRecipients']
bounced_records.each do |record|
- bounce_record = BouncedMailAddress.new(email: record['emailAddress'], recipient_json: record,
- response_json: json)
+ bounce_record = BouncedMailAddress.new(params_from_json(json, record))
bounce_record.save
end
end
+
+ def params_from_json(json, bounced_record)
+ {
+ email: bounced_record['emailAddress'],
+ message_id: json['mail']['messageId'],
+ bounce_type: json['bounce']['bounceType'],
+ bounce_subtype: json['bounce']['bounceSubType'],
+ action: bounced_record['action'],
+ status: bounced_record['status'],
+ diagnostic: bounced_record['diagnosticCode'],
+ }
+ end
end
diff --git a/app/views/admin/bounced_mail_addresses/show.html.erb b/app/views/admin/bounced_mail_addresses/show.html.erb
index 98eeabcd2..5183ae5a1 100644
--- a/app/views/admin/bounced_mail_addresses/show.html.erb
+++ b/app/views/admin/bounced_mail_addresses/show.html.erb
@@ -1,20 +1,26 @@
+
Email:
<%= @bounced_mail_address.email %>
- Bounce reason:
- <%= @bounced_mail_address.bounce_reason %>
+ Bounced message ID:
+ <%= @bounced_mail_address.message_id %>
- Bounced recipient JSON:
-
<%= JSON.pretty_generate(@bounced_mail_address.recipient_json) %>
+ Overall bounce type:
+ <%= @bounced_mail_address.bounce_type %> (<%= @bounced_mail_address.bounce_subtype %> )
- Bounce payload:
-
<%= JSON.pretty_generate(@bounced_mail_address.response_json) %>
+ Bounced recipient status:
+ <%= @bounced_mail_address.action %> (<%= @bounced_mail_address.status %>)
+
+
+
+ Bounced recipient diagnostic:
+
<%= @bounced_mail_address.diagnostic %>
<%= link_to 'Back', admin_bounced_mail_addresses_path %>