Class: PhisherPhinder::MailParser::ReceivedHeaders::ForParser
- Inherits:
-
Object
- Object
- PhisherPhinder::MailParser::ReceivedHeaders::ForParser
- Defined in:
- lib/phisher_phinder/mail_parser/received_headers/for_parser.rb
Instance Method Summary collapse
-
#initialize(starttls_parser:) ⇒ ForParser
constructor
A new instance of ForParser.
- #parse(component) ⇒ Object
Constructor Details
#initialize(starttls_parser:) ⇒ ForParser
Returns a new instance of ForParser.
7 8 9 |
# File 'lib/phisher_phinder/mail_parser/received_headers/for_parser.rb', line 7 def initialize(starttls_parser:) @starttls_parser = starttls_parser end |
Instance Method Details
#parse(component) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/phisher_phinder/mail_parser/received_headers/for_parser.rb', line 11 def parse(component) return {recipient_mailbox: nil}.merge(@starttls_parser.parse(nil)) unless component patterns = [ /\Afor\s(?<recipient_mailbox>\S+)\s\(Google Transport Security\)\z/, /\Afor\s(?<recipient_mailbox>\S+)\s(?<starttls>\([^\)]+\))\z/, /\Afor\s(?<recipient_mailbox>.+)\z/, ] matches = patterns.inject(nil) do |memo, pattern| memo || component.match(pattern) end output = { recipient_mailbox: strip_angle_brackets(matches[:recipient_mailbox]), }.merge( if matches.names.include?('starttls') @starttls_parser.parse(matches[:starttls]) else @starttls_parser.parse(nil) end ) end |