Class: Mail::Parsers::MimeVersionParser

Inherits:
Object
  • Object
show all
Includes:
Utilities
Defined in:
lib/mail/parsers/mime_version_parser.rb

Constant Summary

Constant Summary

Constants included from Mail::Patterns

Mail::Patterns::ATOM_UNSAFE, Mail::Patterns::CONTROL_CHAR, Mail::Patterns::CRLF, Mail::Patterns::FIELD_BODY, Mail::Patterns::FIELD_LINE, Mail::Patterns::FIELD_NAME, Mail::Patterns::FIELD_PREFIX, Mail::Patterns::FIELD_SPLIT, Mail::Patterns::FWS, Mail::Patterns::HEADER_LINE, Mail::Patterns::HEADER_SPLIT, Mail::Patterns::PHRASE_UNSAFE, Mail::Patterns::QP_SAFE, Mail::Patterns::QP_UNSAFE, Mail::Patterns::TEXT, Mail::Patterns::TOKEN_UNSAFE, Mail::Patterns::WSP

Instance Method Summary (collapse)

Methods included from Utilities

#atom_safe?, #bracket, #capitalize_field, #constantize, #dasherize, #dquote, #escape_paren, #map_lines, #map_with_index, #match_to_s, #paren, #quote_atom, #quote_phrase, #quote_token, #token_safe?, #unbracket, #underscoreize, #unparen, #unquote, #uri_escape, #uri_parser, #uri_unescape

Instance Method Details

- (Object) parse(s)



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
32
33
34
35
36
37
38
39
# File 'lib/mail/parsers/mime_version_parser.rb', line 5

def parse(s)
  if s.blank?
    return MimeVersionStruct.new("", nil)
  end

  mime_version = MimeVersionStruct.new

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

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

    # Major Digits
    when :major_digits_s then major_digits_s = p
    when :major_digits_e
      mime_version.major = s[major_digits_s..(p-1)]

    # Minor Digits
    when :minor_digits_s then minor_digits_s = p
    when :minor_digits_e
      mime_version.minor = s[minor_digits_s..(p-1)]

    when :comment_e, :comment_s then nil

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