Class: Mail::Parsers::ContentTransferEncodingParser

Inherits:
Object
  • Object
show all
Defined in:
lib/mail/parsers/content_transfer_encoding_parser.rb

Instance Method Summary collapse

Instance Method Details

#parse(s) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/mail/parsers/content_transfer_encoding_parser.rb', line 4

def parse(s)
  content_transfer_encoding = ContentTransferEncodingStruct.new("")
  if s.blank?
    return content_transfer_encoding
  end

  actions, error = Ragel.parse(:content_transfer_encoding, s)
  if error
    raise Mail::Field::ParseError.new(Mail::ContentTransferEncodingElement, s, error)
  end

  encoding_s = nil
  actions.each_slice(2) do |action_id, p|
    action = Mail::Parsers::Ragel::ACTIONS[action_id]
    case action

    # Encoding
    when :encoding_s then encoding_s = p
    when :encoding_e
      content_transfer_encoding.encoding = s[encoding_s..(p-1)].downcase

    else
      raise Mail::Field::ParseError.new(Mail::ContentTransferEncodingElement, s, "Failed to process unknown action: #{action}")
    end
  end

  content_transfer_encoding
end