File: ruby.rb

package info (click to toggle)
ruby-mail 2.6.4%2Bdfsg1-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 4,256 kB
  • ctags: 1,327
  • sloc: ruby: 44,678; makefile: 3
file content (40 lines) | stat: -rw-r--r-- 1,229 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
module Mail
  module Parsers
    module Ragel
      module Ruby
        def self.silence_warnings
          old, $VERBOSE = $VERBOSE, nil
          yield
        ensure
          $VERBOSE = old
        end

        # Ragel-generated parsers give a lot of warnings
        # and may cause logs to balloon in size
        silence_warnings do
          Mail::Parsers::Ragel::FIELD_PARSERS.each do |field_parser|
            require "mail/parsers/ragel/ruby/machines/#{field_parser}_machine"
          end
        end

        MACHINE_LIST = {
          :address_lists => AddressListsMachine,
          :phrase_lists => PhraseListsMachine,
          :date_time => DateTimeMachine,
          :received => ReceivedMachine,
          :message_ids => MessageIdsMachine,
          :envelope_from => EnvelopeFromMachine,
          :mime_version => MimeVersionMachine,
          :content_type => ContentTypeMachine,
          :content_disposition => ContentDispositionMachine,
          :content_transfer_encoding => ContentTransferEncodingMachine,
          :content_location => ContentLocationMachine
        }

        def self.parse(machine, string)
          MACHINE_LIST[machine].parse(string)
        end
      end
    end
  end
end