class Dmarcer::Parser

Public Class Methods

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

Public Instance Methods

date_range() click to toggle source
# File lib/dmarcer.rb, line 23
def date_range
  t_begin = Time.at(data.report_metadata.date_range.begin.content.to_i)
  t_end = Time.at(data.report_metadata.date_range.end.content.to_i)
  t_begin..t_end
end
dkim_auth_failure_records() click to toggle source
# File lib/dmarcer.rb, line 37
def dkim_auth_failure_records
  records.select { |r| r.auth_failed_dkim_domains.any? }
end
id() click to toggle source
# File lib/dmarcer.rb, line 29
def id
  data.report_metadata.report_id.content
end
identifiers() click to toggle source
# File lib/dmarcer.rb, line 15
def identifiers
  data.record.map { |r| r.identifiers.header_from.content }.uniq.sort
end
org_name() click to toggle source
# File lib/dmarcer.rb, line 19
def org_name
  data.report_metadata.org_name.content
end
print_report() click to toggle source
record_by_identifier(identifier) click to toggle source
# File lib/dmarcer.rb, line 11
def record_by_identifier(identifier)
  data.record.select { |r| r.identifiers.header_from.content == identifier }
end
records() click to toggle source
# File lib/dmarcer.rb, line 33
def records
  @records ||= @data.record.map { |r| Record.new r }
end
spf_auth_failure_records() click to toggle source
# File lib/dmarcer.rb, line 41
def spf_auth_failure_records
  records.select { |r| r.auth_failed_spf_domains.any? }
end
spf_domain_ip_hash() click to toggle source
# File lib/dmarcer.rb, line 45
def spf_domain_ip_hash
  spf_auth_failure_records.each_with_object({}) do |r, m|
    r.auth_failed_spf_domains.each do |d|
      if m[d]
        m[d] << r.source_ip
      else
        m[d] = [r.source_ip]
      end
    end
  end
end

Private Instance Methods

data() click to toggle source
# File lib/dmarcer.rb, line 92
def data
  @data ||= Nokogiri::Slop(File.read(@input_file)).feedback
end
lookup(ip) click to toggle source
# File lib/dmarcer.rb, line 85
def lookup(ip)
  return Resolv.getname(ip) if ip !~ Resolv::IPv6::Regex
  'err IPv6 address'
rescue Resolv::ResolvError
  nil
end