mirror of
https://github.com/internetee/registry.git
synced 2025-07-25 03:58:27 +02:00
Reflect new bounced mail structure
This commit is contained in:
parent
659cb7f4e6
commit
98674ab381
2 changed files with 26 additions and 28 deletions
|
@ -1,6 +1,5 @@
|
||||||
class BouncedMailAddress < ApplicationRecord
|
class BouncedMailAddress < ApplicationRecord
|
||||||
validates :email, presence: true
|
validates :email, :message_id, :bounce_type, :bounce_subtype, :action, :status, presence: true
|
||||||
validates :bounce_reason, :recipient_json, :response_json, presence: true
|
|
||||||
before_validation :assign_bounce_reason
|
before_validation :assign_bounce_reason
|
||||||
|
|
||||||
def assign_bounce_reason
|
def assign_bounce_reason
|
||||||
|
@ -9,31 +8,24 @@ class BouncedMailAddress < ApplicationRecord
|
||||||
self.bounce_reason = "#{action} (#{status} #{diagnostic})"
|
self.bounce_reason = "#{action} (#{status} #{diagnostic})"
|
||||||
end
|
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)
|
def self.record(json)
|
||||||
bounced_records = json['bounce']['bouncedRecipients']
|
bounced_records = json['bounce']['bouncedRecipients']
|
||||||
bounced_records.each do |record|
|
bounced_records.each do |record|
|
||||||
bounce_record = BouncedMailAddress.new(email: record['emailAddress'], recipient_json: record,
|
bounce_record = BouncedMailAddress.new(params_from_json(json, record))
|
||||||
response_json: json)
|
|
||||||
|
|
||||||
bounce_record.save
|
bounce_record.save
|
||||||
end
|
end
|
||||||
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
|
end
|
||||||
|
|
|
@ -1,20 +1,26 @@
|
||||||
|
<p>
|
||||||
<strong>Email:</strong>
|
<strong>Email:</strong>
|
||||||
<%= @bounced_mail_address.email %>
|
<%= @bounced_mail_address.email %>
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
<strong>Bounce reason:</strong>
|
<strong>Bounced message ID:</strong>
|
||||||
<%= @bounced_mail_address.bounce_reason %>
|
<%= @bounced_mail_address.message_id %>
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
<strong>Bounced recipient JSON:</strong>
|
<strong>Overall bounce type:</strong>
|
||||||
<pre><%= JSON.pretty_generate(@bounced_mail_address.recipient_json) %></pre>
|
<%= @bounced_mail_address.bounce_type %> (<%= @bounced_mail_address.bounce_subtype %> )
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
<strong>Bounce payload:</strong>
|
<strong>Bounced recipient status:</strong>
|
||||||
<pre><%= JSON.pretty_generate(@bounced_mail_address.response_json) %></pre>
|
<%= @bounced_mail_address.action %> (<%= @bounced_mail_address.status %>)
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
<strong>Bounced recipient diagnostic:</strong>
|
||||||
|
<pre><%= @bounced_mail_address.diagnostic %></pre>
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<%= link_to 'Back', admin_bounced_mail_addresses_path %>
|
<%= link_to 'Back', admin_bounced_mail_addresses_path %>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue