class PhisherPhinder::MailParser::ReceivedHeaders::ForParser
Public Class Methods
new(starttls_parser:)
click to toggle source
# File lib/phisher_phinder/mail_parser/received_headers/for_parser.rb, line 7 def initialize(starttls_parser:) @starttls_parser = starttls_parser end
Public Instance Methods
parse(component)
click to toggle source
# 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
Private Instance Methods
strip_angle_brackets(email_address_string)
click to toggle source
# File lib/phisher_phinder/mail_parser/received_headers/for_parser.rb, line 37 def strip_angle_brackets(email_address_string) email_address_string =~ /\<\s?([^>]+?)\s?\>/ ? $1 : email_address_string end