Class: PhisherPhinder::MailParser::ReceivedHeaders::ByParser
- Inherits:
-
Object
- Object
- PhisherPhinder::MailParser::ReceivedHeaders::ByParser
- Defined in:
- lib/phisher_phinder/mail_parser/received_headers/by_parser.rb
Instance Method Summary collapse
-
#initialize(ip_factory:, starttls_parser:) ⇒ ByParser
constructor
A new instance of ByParser.
- #parse(component) ⇒ Object
Constructor Details
#initialize(ip_factory:, starttls_parser:) ⇒ ByParser
Returns a new instance of ByParser.
7 8 9 10 |
# File 'lib/phisher_phinder/mail_parser/received_headers/by_parser.rb', line 7 def initialize(ip_factory:, starttls_parser:) @extended_ip_factory = ip_factory @starttls_parser = starttls_parser end |
Instance Method Details
#parse(component) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/phisher_phinder/mail_parser/received_headers/by_parser.rb', line 12 def parse(component) unless component return { recipient: nil, protocol: nil, id: nil, recipient_additional: nil, authenticated_as: nil }.merge(@starttls_parser.parse(nil)) end patterns = [ %r{by\s(?<recipient>\S+)\s \((?<additional>[^)]+)\)\s with\sMicrosoft\sSMTP\sServer\s(?<starttls>\([^\)]+\))\s id\s(?<id>\S+)\s via\s(?<protocol>Frontend\sTransport) }x, %r{by\s(?<recipient>\S+)\s \((?<additional>[^)]+)\)\s with\sMicrosoft\sSMTP\sServer\s(?<starttls>\([^\)]+\))\s id\s(?<id>\S+) }x, /by\s(?<recipient>\S+)\swith\s(?<protocol>\S+)\sid\s(?<id>\S+)/, /by\s(?<recipient>\S+)\s\((?<additional>[^)]+)\)\swith\s(?<protocol>\S+)\sid\s(?<id>\S+)/, /by\s(?<recipient>\S+)\s(?<additional>.+)\swith\s(?<protocol>\S+)\sid\s(?<id>\S+)/, /by\s(?<recipient>\S+)\s\((?<additional>[^)]+)\)\sid\s(?<id>\S+)/, /by\s(?<recipient>\S+)\s\((?<additional>[^)]+)\)\swith\s(?<protocol>.+)\sid\s(?<id>\S+)/, /by\s(?<recipient>\S+)\s\((?<additional>[^)]+)\)\swith\s(?<protocol>\S+)\sID\s(?<id>\S+)/, /by\s(?<recipient>\S+)\swith\s(?<protocol>.+)\sid\s(?<id>\S+)/, /by\s(?<recipient>\S+)\swith\s(?<protocol>.+)/, /by\s(?<recipient>\S+)\s\((?<additional>[^)]+)\)\s\(authenticated as (?<authenticated_as>[^\)]+)\)\sid\s(?<id>\S+)/, /by\s(?<recipient>\S+)\sid\s(?<id>\S+)/, /by\s(?<recipient>\S+)/ ] matches = patterns.inject(nil) do |memo, pattern| memo || component.match(pattern) end { recipient: enrich_recipient(matches[:recipient]), protocol: matches.names.include?('protocol') ? matches[:protocol]: nil, id: matches.names.include?('id') ? matches[:id]: nil, recipient_additional: matches.names.include?('additional') ? matches[:additional] : nil, authenticated_as: matches.names.include?('authenticated_as') ? matches[:authenticated_as] : nil, }.merge( if matches.names.include?('starttls') @starttls_parser.parse(matches[:starttls]) else @starttls_parser.parse(nil) end ) end |