File: content_location_parser.rb

package info (click to toggle)
ruby-mail 2.6.1%2Bdfsg1-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 4,092 kB
  • ctags: 1,281
  • sloc: ruby: 43,919; makefile: 2
file content (35 lines) | stat: -rw-r--r-- 1,014 bytes parent folder | download
1
2
3
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
32
33
34
35
module Mail::Parsers
  class ContentLocationParser
    def parse(s)
      content_location = ContentLocationStruct.new(nil)
      if s.blank?
        return content_location
      end

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

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

        # Quoted String.
        when :qstr_s then qstr_s = p
        when :qstr_e then content_location.location = s[qstr_s..(p-1)]

        # Token String
        when :token_string_s then token_string_s = p
        when :token_string_e
          content_location.location = s[token_string_s..(p-1)]

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