class Dmarcer::Record

Attributes

data[RW]

Public Class Methods

new(data) click to toggle source
# File lib/dmarcer.rb, line 100
def initialize(data)
  @data = data
end

Public Instance Methods

auth_failed_dkim_domains() click to toggle source
# File lib/dmarcer.rb, line 132
def auth_failed_dkim_domains
  auth_failure_domains_by_record_type(:dkim)
end
auth_failed_spf_domains() click to toggle source
# File lib/dmarcer.rb, line 136
def auth_failed_spf_domains
  auth_failure_domains_by_record_type(:spf)
end
count() click to toggle source
# File lib/dmarcer.rb, line 120
def count
  @data.row.count
end
dkim?() click to toggle source
# File lib/dmarcer.rb, line 108
def dkim?
  @data.auth_results.respond_to?('dkim')
end
dkim_domains() click to toggle source
# File lib/dmarcer.rb, line 124
def dkim_domains
  domains_by_record_type(:dkim)
end
header_from() click to toggle source
# File lib/dmarcer.rb, line 116
def header_from
  @data.identifiers.header_from.content
end
policy_eval() click to toggle source
# File lib/dmarcer.rb, line 140
def policy_eval
  p = @data.row.policy_evaluated
  {
    disposition: p.disposition.content,
    dkim: p.dkim.content,
    spf: p.spf.content
  }
end
source_ip() click to toggle source
# File lib/dmarcer.rb, line 112
def source_ip
  @data.row.source_ip.content
end
spf?() click to toggle source
# File lib/dmarcer.rb, line 104
def spf?
  @data.auth_results.respond_to?('spf')
end
spf_domains() click to toggle source
# File lib/dmarcer.rb, line 128
def spf_domains
  domains_by_record_type(:spf)
end

Private Instance Methods

auth_failure_domains_by_record_type(type) click to toggle source
# File lib/dmarcer.rb, line 159
def auth_failure_domains_by_record_type(type)
  # rubocop:disable Metrics/LineLength
  return [] unless @data.auth_results.respond_to?(type)
  if @data.auth_results.send(type).respond_to?('result') &&
     @data.auth_results.send(type).result.content != 'pass'
    return [@data.auth_results.send(type).domain.content]
  end
  @data.auth_results.send(type)
    .select { |r| r.respond_to?(type) && r.send(type).result.content != 'pass' }
    .map { |r| r.domain.content }.uniq.sort
  # rubocop:enable Metrics/LineLength
end
domains_by_record_type(type) click to toggle source
# File lib/dmarcer.rb, line 151
def domains_by_record_type(type)
  # rubocop:disable Metrics/LineLength
  return [] unless @data.auth_results.respond_to?(type)
  return [@data.auth_results.send(type).domain.content] if @data.auth_results.send(type).respond_to?('domain')
  @data.auth_results.send(type).map { |r| r.domain.content }.uniq.sort
  # rubocop:enable Metrics/LineLength
end