Class: PhisherPhinder::MailParser::Body::BlockParser

Inherits:
Object
  • Object
show all
Defined in:
lib/phisher_phinder/mail_parser/body/block_parser.rb

Instance Method Summary collapse

Constructor Details

#initialize(line_end) ⇒ BlockParser

Returns a new instance of BlockParser.



7
8
9
# File 'lib/phisher_phinder/mail_parser/body/block_parser.rb', line 7

def initialize(line_end)
  @line_end = line_end
end

Instance Method Details

#parse(block_data) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/phisher_phinder/mail_parser/body/block_parser.rb', line 11

def parse(block_data)
  encoding = block_data[:content_transfer_encoding] || :seven_bit

  case encoding
  when :seven_bit
    block_data[:content]
  when :base64
    decoded = Base64.decode64(block_data[:content])
    if block_data[:character_set] == :utf_8
      decoded.force_encoding('UTF-8')
    elsif block_data[:character_set] == :windows_1251
      decoded.force_encoding('cp1251').encode('UTF-8')
    end
  when :quoted_printable
    remove_troublesome_sequences(block_data[:content]).unpack('M').first.force_encoding('UTF-8')
  end
end