Class: PhisherPhinder::MailParser::AuthenticationHeaders::ReceivedSpfParser

Inherits:
Object
  • Object
show all
Defined in:
lib/phisher_phinder/mail_parser/authentication_headers/received_spf_parser.rb

Instance Method Summary collapse

Constructor Details

#initialize(ip_factory:) ⇒ ReceivedSpfParser

Returns a new instance of ReceivedSpfParser.



7
8
9
# File 'lib/phisher_phinder/mail_parser/authentication_headers/received_spf_parser.rb', line 7

def initialize(ip_factory:)
  @ip_factory = ip_factory
end

Instance Method Details

#parse(value) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/phisher_phinder/mail_parser/authentication_headers/received_spf_parser.rb', line 11

def parse(value)
  matches = value.match(
    %r{
      \A(?<result>\S+)\s
      \((?<additional_data>[^\)]+)\)
      (?<attributes>.*)
    }x
  )

  {
    result: matches[:result].downcase.to_sym,
  }.merge(parse_additional_data(matches[:additional_data])).merge(parse_attributes(matches[:attributes]))

    # {
    #   result: matches[:result].downcase.to_sym,
    #   authserv_id: extract(matches, :authserv_id),
    #   mailfrom: extract(matches, :mailfrom),
    #   ip: @ip_factory.build(extract(matches, :ip)),
    #   client_ip: expand_ip(extract(matches, :client_ip)),
    #   receiver: extract(matches, :receiver),
    #   helo: expand_ip(extract(matches, :helo)),
    #   envelope_from: extract(matches, :envelope_from)
    # }
end