File: envelope_from_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 (45 lines) | stat: -rw-r--r-- 1,317 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
36
37
38
39
40
41
42
43
44
45
module Mail::Parsers
  class EnvelopeFromParser
    def parse(s)
      envelope_from = EnvelopeFromStruct.new
      if s.blank?
        return envelope_from
      end

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

      address_s = ctime_date_s = nil
      envelope_from = EnvelopeFromStruct.new
      actions.each_slice(2) do |action_id, p|
        action = Mail::Parsers::Ragel::ACTIONS[action_id]
        case action

        # Address
        when :address_s then address_s = p
        when :address_e
          envelope_from.address = s[address_s..(p-1)].rstrip

        # ctime_date
        when :ctime_date_s then ctime_date_s = p
        when :ctime_date_e
          envelope_from.ctime_date = s[ctime_date_s..(p-1)]

        # ignored actions
        when :angle_addr_s, :comment_e, :comment_s,
             :domain_e, :domain_s, :local_dot_atom_e,
             :local_dot_atom_pre_comment_e,
             :local_dot_atom_pre_comment_s,
             :local_dot_atom_s, :qstr_e, :qstr_s
          nil

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