Class: Mail::Parsers::MessageIdsParser

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

Instance Method Summary collapse

Instance Method Details

#parse(s) ⇒ Object



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
# File 'lib/mail/parsers/message_ids_parser.rb', line 3

def parse(s)
  if s.blank?
    return MessageIdsStruct.new
  end

  message_ids = MessageIdsStruct.new([])

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

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

    # Message Ids
    when :msg_id_s then msg_id_s = p
    when :msg_id_e
      message_ids.message_ids << s[msg_id_s..(p-1)].rstrip

    when :domain_e, :domain_s, :local_dot_atom_e,
      :local_dot_atom_pre_comment_e,
      :local_dot_atom_pre_comment_s,
      :local_dot_atom_s

      # ignored actions

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