Sha256: c65fcc9f9ce92d8beb35ad161880c8b93c06da0a19614eaf2f944dad0e926769

Contents?: true

Size: 1.32 KB

Versions: 16

Compression:

Stored size: 1.32 KB

Contents

module Mail::Parsers
  class ReceivedParser

    def parse(s)
      actions, error = Ragel.parse(:received, s)
      if error
        raise Mail::Field::ParseError.new(Mail::ReceivedElement, s, error)
      end

      received = ReceivedStruct.new

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

        # Received Tokens:
        when :received_tokens_s then received_tokens_s = p
        when :received_tokens_e
          received.info = s[received_tokens_s..(p-1)]

        # Date
        when :date_s then date_s = p
        when :date_e
          received.date = s[date_s..(p-1)].strip

        # Time
        when :time_s then time_s = p
        when :time_e
          received.time = s[time_s..(p-1)]

        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,
             :local_quoted_string_s, :local_quoted_string_e
          # ignored actions

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

Version data entries

16 entries across 15 versions & 7 rubygems

Version Path
mail-2.6.4.rc2 lib/mail/parsers/received_parser.rb
angular-rails4-templates-0.4.1 vendor/ruby/2.1.0/gems/mail-2.6.3/lib/mail/parsers/received_parser.rb
angular-rails4-templates-0.4.0 vendor/ruby/2.1.0/gems/mail-2.6.3/lib/mail/parsers/received_parser.rb
tdiary-4.2.1 vendor/bundle/ruby/2.2.0/gems/mail-2.6.3/lib/mail/parsers/received_parser.rb
tdiary-4.2.1 vendor/bundle/ruby/2.3.0/gems/mail-2.6.3/lib/mail/parsers/received_parser.rb
angular-rails4-templates-0.3.0 vendor/ruby/2.1.0/gems/mail-2.6.3/lib/mail/parsers/received_parser.rb
mail-2.6.4.rc1 lib/mail/parsers/received_parser.rb
sc_core-0.0.7 test/dummy/vendor/bundle/ruby/2.2.0/gems/mail-2.6.3/lib/mail/parsers/received_parser.rb
solidus_backend-1.0.0.pre3 vendor/bundle/gems/mail-2.6.3/lib/mail/parsers/received_parser.rb
solidus_backend-1.0.0.pre2 vendor/bundle/gems/mail-2.6.3/lib/mail/parsers/received_parser.rb
solidus_backend-1.0.0.pre vendor/bundle/gems/mail-2.6.3/lib/mail/parsers/received_parser.rb
shoppe-paypal-1.1.0 vendor/bundle/ruby/2.1.0/gems/mail-2.6.3/lib/mail/parsers/received_parser.rb
mail-2.6.3 lib/mail/parsers/received_parser.rb
mail-portertech-2.6.2.edge lib/mail/parsers/received_parser.rb
mail-2.6.1 lib/mail/parsers/received_parser.rb
mail-2.6.0 lib/mail/parsers/received_parser.rb