Sha256: 9d47509017d5d8c67f6e20f186f3f0639d0c99a4e5834d8943659c5fea4e8c4b

Contents?: true

Size: 1.33 KB

Versions: 22

Compression:

Stored size: 1.33 KB

Contents

# frozen_string_literal: true
module Mail::Parsers
  class EnvelopeFromParser
    def parse(s)
      envelope_from = EnvelopeFromStruct.new
      if Mail::Utilities.blank?(s)
        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

Version data entries

22 entries across 20 versions & 6 rubygems

Version Path
tdiary-5.0.6 vendor/bundle/gems/mail-2.6.6/lib/mail/parsers/envelope_from_parser.rb
tdiary-5.0.5 vendor/bundle/gems/mail-2.6.4/lib/mail/parsers/envelope_from_parser.rb
tdiary-5.0.5 vendor/bundle/gems/tdiary-5.0.4/vendor/bundle/gems/mail-2.6.4/lib/mail/parsers/envelope_from_parser.rb
tdiary-5.0.5 vendor/bundle/gems/mail-2.6.6/lib/mail/parsers/envelope_from_parser.rb
mail-2.6.6 lib/mail/parsers/envelope_from_parser.rb
mail-2.6.6.rc1 lib/mail/parsers/envelope_from_parser.rb
enju_leaf-1.2.1 vendor/bundle/ruby/2.3/gems/mail-2.6.5/lib/mail/parsers/envelope_from_parser.rb
mail-2.6.5 lib/mail/parsers/envelope_from_parser.rb
mail-2.6.5.rc1 lib/mail/parsers/envelope_from_parser.rb
tdiary-5.0.4 vendor/bundle/gems/mail-2.6.4/lib/mail/parsers/envelope_from_parser.rb
autocompl-0.2.2 test/dummy/vendor/bundle/ruby/2.3.0/gems/mail-2.6.4/lib/mail/parsers/envelope_from_parser.rb
autocompl-0.2.1 test/dummy/vendor/bundle/ruby/2.3.0/gems/mail-2.6.4/lib/mail/parsers/envelope_from_parser.rb
autocompl-0.2.0 test/dummy/vendor/bundle/ruby/2.3.0/gems/mail-2.6.4/lib/mail/parsers/envelope_from_parser.rb
autocompl-0.1.2 test/dummy/vendor/bundle/ruby/2.3.0/gems/mail-2.6.4/lib/mail/parsers/envelope_from_parser.rb
autocompl-0.1.1 test/dummy/vendor/bundle/ruby/2.3.0/gems/mail-2.6.4/lib/mail/parsers/envelope_from_parser.rb
autocompl-0.1.0 test/dummy/vendor/bundle/ruby/2.3.0/gems/mail-2.6.4/lib/mail/parsers/envelope_from_parser.rb
autocompl-0.0.1 test/dummy/vendor/bundle/ruby/2.3.0/gems/mail-2.6.4/lib/mail/parsers/envelope_from_parser.rb
abaci-0.3.0 vendor/bundle/gems/mail-2.6.4/lib/mail/parsers/envelope_from_parser.rb
tdiary-5.0.2 vendor/bundle/gems/mail-2.6.4/lib/mail/parsers/envelope_from_parser.rb
tdiary-5.0.1 vendor/bundle/gems/mail-2.6.4/lib/mail/parsers/envelope_from_parser.rb