module Mail::Parsers::ContentTypeParser

Constants

ContentTypeStruct

Attributes

_eof_actions[RW]
_index_offsets[RW]
_indicies[RW]
_key_spans[RW]
_trans_actions[RW]
_trans_keys[RW]
_trans_targs[RW]
en_comment_tail[RW]
en_main[RW]
error[RW]
first_final[RW]
start[RW]

Public Class Methods

parse(data) click to toggle source
# File lib/mail/parsers/content_type_parser.rb, line 692
    def self.parse(data)
      data = data.dup.force_encoding(Encoding::ASCII_8BIT) if data.respond_to?(:force_encoding)

      return ContentTypeStruct.new('text', 'plain', []) if Mail::Utilities.blank?(data)
      content_type = ContentTypeStruct.new(nil, nil, [])

      # Parser state
      main_type_s = sub_type_s = param_attr_s = param_attr = nil
      qstr_s = qstr = param_val_s = nil

      # 5.1 Variables Used by Ragel
      p = 0
      eof = pe = data.length
      stack = []

      
begin
        p ||= 0
        pe ||= data.length
        cs = start
        top = 0
end

      
begin
        testEof = false
        _slen, _trans, _keys, _inds, _acts, _nacts = nil
        _goto_level = 0
        _resume = 10
        _eof_trans = 15
        _again = 20
        _test_eof = 30
        _out = 40
        while true
        if _goto_level <= 0
        if p == pe
                _goto_level = _test_eof
                next
        end
        if cs == 0
                _goto_level = _out
                next
        end
        end
        if _goto_level <= _resume
        _keys = cs << 1
        _inds = _index_offsets[cs]
        _slen = _key_spans[cs]
        _wide = data[p].ord
        _trans = if (   _slen > 0 && 
                        _trans_keys[_keys] <= _wide && 
                        _wide <= _trans_keys[_keys + 1] 
                    ) then
                        _indicies[ _inds + _wide - _trans_keys[_keys] ] 
                 else 
                        _indicies[ _inds + _slen ]
                 end
        cs = _trans_targs[_trans]
        if _trans_actions[_trans] != 0
        case _trans_actions[_trans]
        when 1 then
                begin
 main_type_s = p                end
        when 2 then
                begin
 content_type.main_type = chars(data, main_type_s, p-1).downcase                end
        when 3 then
                begin
 sub_type_s = p                 end
        when 19 then
                begin
 content_type.sub_type = chars(data, sub_type_s, p-1).downcase          end
        when 4 then
                begin
 param_attr_s = p               end
        when 6 then
                begin
 param_attr = chars(data, param_attr_s, p-1)            end
        when 9 then
                begin
 qstr_s = p             end
        when 11 then
                begin
 qstr = chars(data, qstr_s, p-1)                end
        when 7 then
                begin
 param_val_s = p                end
        when 21 then
                begin

    if param_attr.nil?
      raise Mail::Field::ParseError.new(Mail::ContentTypeElement, data, "no attribute for value")
    end

    # Use quoted s value if one exists, otherwise use parameter value
    value = qstr || chars(data, param_val_s, p-1)

    content_type.parameters << { param_attr => value }
    param_attr = nil
    qstr = nil
                end
        when 12 then
                begin
                end
        when 15 then
                begin
                end
        when 5 then
                begin
        begin
                stack[top] = cs
                top+= 1
                cs = 35
                _goto_level = _again
                next
        end
                end
        when 18 then
                begin
        begin
                top -= 1
                cs = stack[top]
                _goto_level = _again
                next
        end
                end
        when 20 then
                begin
 content_type.sub_type = chars(data, sub_type_s, p-1).downcase          end
                begin
        begin
                stack[top] = cs
                top+= 1
                cs = 35
                _goto_level = _again
                next
        end
                end
        when 10 then
                begin
 qstr_s = p             end
                begin
 qstr = chars(data, qstr_s, p-1)                end
        when 8 then
                begin
 param_val_s = p                end
                begin
        begin
                stack[top] = cs
                top+= 1
                cs = 35
                _goto_level = _again
                next
        end
                end
        when 25 then
                begin

    if param_attr.nil?
      raise Mail::Field::ParseError.new(Mail::ContentTypeElement, data, "no attribute for value")
    end

    # Use quoted s value if one exists, otherwise use parameter value
    value = qstr || chars(data, param_val_s, p-1)

    content_type.parameters << { param_attr => value }
    param_attr = nil
    qstr = nil
                end
                begin
        begin
                stack[top] = cs
                top+= 1
                cs = 35
                _goto_level = _again
                next
        end
                end
        when 13 then
                begin
                end
                begin
 param_attr_s = p               end
        when 23 then
                begin
                end
                begin

    if param_attr.nil?
      raise Mail::Field::ParseError.new(Mail::ContentTypeElement, data, "no attribute for value")
    end

    # Use quoted s value if one exists, otherwise use parameter value
    value = qstr || chars(data, param_val_s, p-1)

    content_type.parameters << { param_attr => value }
    param_attr = nil
    qstr = nil
                end
        when 14 then
                begin
                end
                begin
        begin
                stack[top] = cs
                top+= 1
                cs = 35
                _goto_level = _again
                next
        end
                end
        when 16 then
                begin
                end
                begin
        begin
                stack[top] = cs
                top+= 1
                cs = 35
                _goto_level = _again
                next
        end
                end
        when 17 then
                begin
                end
                begin
        begin
                top -= 1
                cs = stack[top]
                _goto_level = _again
                next
        end
                end
        when 22 then
                begin
        begin
                stack[top] = cs
                top+= 1
                cs = 35
                _goto_level = _again
                next
        end
                end
                begin

    if param_attr.nil?
      raise Mail::Field::ParseError.new(Mail::ContentTypeElement, data, "no attribute for value")
    end

    # Use quoted s value if one exists, otherwise use parameter value
    value = qstr || chars(data, param_val_s, p-1)

    content_type.parameters << { param_attr => value }
    param_attr = nil
    qstr = nil
                end
        when 24 then
                begin
                end
                begin
        begin
                stack[top] = cs
                top+= 1
                cs = 35
                _goto_level = _again
                next
        end
                end
                begin

    if param_attr.nil?
      raise Mail::Field::ParseError.new(Mail::ContentTypeElement, data, "no attribute for value")
    end

    # Use quoted s value if one exists, otherwise use parameter value
    value = qstr || chars(data, param_val_s, p-1)

    content_type.parameters << { param_attr => value }
    param_attr = nil
    qstr = nil
                end
        end
        end
        end
        if _goto_level <= _again
        if cs == 0
                _goto_level = _out
                next
        end
        p += 1
        if p != pe
                _goto_level = _resume
                next
        end
        end
        if _goto_level <= _test_eof
        if p == eof
          case _eof_actions[cs]
        when 19 then
                begin
 content_type.sub_type = chars(data, sub_type_s, p-1).downcase          end
        when 21 then
                begin

    if param_attr.nil?
      raise Mail::Field::ParseError.new(Mail::ContentTypeElement, data, "no attribute for value")
    end

    # Use quoted s value if one exists, otherwise use parameter value
    value = qstr || chars(data, param_val_s, p-1)

    content_type.parameters << { param_attr => value }
    param_attr = nil
    qstr = nil
                end
        when 12 then
                begin
                end
        when 23 then
                begin
                end
                begin

    if param_attr.nil?
      raise Mail::Field::ParseError.new(Mail::ContentTypeElement, data, "no attribute for value")
    end

    # Use quoted s value if one exists, otherwise use parameter value
    value = qstr || chars(data, param_val_s, p-1)

    content_type.parameters << { param_attr => value }
    param_attr = nil
    qstr = nil
                end
          end
        end

        end
        if _goto_level <= _out
                break
        end
end
        end


      if p != eof || cs < 47
        raise Mail::Field::IncompleteParseError.new(Mail::ContentTypeElement, data, p)
      end

      content_type
    end