Sha256: 7589b894a2be9bb055666e890704ff6958f74edbd134bccfe658bcc95a6465e3

Contents?: true

Size: 1.49 KB

Versions: 14

Compression:

Stored size: 1.49 KB

Contents

# frozen_string_literal: true
require 'mail/utilities'
require 'mail/parser_tools'

begin
  original_verbose, $VERBOSE = $VERBOSE, nil

%%{
  machine mime_version;
  alphtype int;

  # Major Digits
  action major_digits_s { major_digits_s = p }
  action major_digits_e { mime_version.major = chars(data, major_digits_s, p-1) }

  # Minor Digits
  action minor_digits_s { minor_digits_s = p }
  action minor_digits_e { mime_version.minor = chars(data, minor_digits_s, p-1) }

  # No-op actions
  action comment_s {}
  action comment_e {}
  action qstr_s {}
  action qstr_e {}
  action phrase_s {}
  action phrase_e {}

  include rfc2045_mime "rfc2045_mime.rl";
  main := mime_version;
}%%

module Mail::Parsers
  module MimeVersionParser
    extend Mail::ParserTools

    MimeVersionStruct = Struct.new(:major, :minor, :error)

    %%write data noprefix;

    def self.parse(data)
      data = data.dup.force_encoding(Encoding::ASCII_8BIT) if data.respond_to?(:force_encoding)

      return MimeVersionStruct.new('', nil) if Mail::Utilities.blank?(data)

      # Parser state
      mime_version = MimeVersionStruct.new
      major_digits_s = minor_digits_s = nil

      # 5.1 Variables Used by Ragel
      p = 0
      eof = pe = data.length
      stack = []

      %%write init;
      %%write exec;

      if p != eof || cs < %%{ write first_final; }%%
        raise Mail::Field::IncompleteParseError.new(Mail::MimeVersionElement, data, p)
      end

      mime_version
    end
  end
end

ensure
  $VERBOSE = original_verbose
end

Version data entries

14 entries across 14 versions & 5 rubygems

Version Path
minato_ruby_api_client-0.2.2 vendor/bundle/ruby/3.2.0/gems/mail-2.8.1/lib/mail/parsers/mime_version_parser.rl
blacklight-spotlight-3.6.0.beta8 vendor/bundle/ruby/3.2.0/gems/mail-2.8.1/lib/mail/parsers/mime_version_parser.rl
cm-admin-1.5.22 vendor/bundle/ruby/3.3.0/gems/mail-2.8.1/lib/mail/parsers/mime_version_parser.rl
cm-admin-1.5.21 vendor/bundle/ruby/3.3.0/gems/mail-2.8.1/lib/mail/parsers/mime_version_parser.rl
cm-admin-1.5.20 vendor/bundle/ruby/3.3.0/gems/mail-2.8.1/lib/mail/parsers/mime_version_parser.rl
tinymce-rails-7.1.2 vendor/bundle/ruby/3.3.0/gems/mail-2.8.1/lib/mail/parsers/mime_version_parser.rl
mail-2.8.1 lib/mail/parsers/mime_version_parser.rl
mail-2.8.1.rc2 lib/mail/parsers/mime_version_parser.rl
mail-2.8.0.1 lib/mail/parsers/mime_version_parser.rl
mail-2.8.0.1.rc1 lib/mail/parsers/mime_version_parser.rl
mail-2.8.0 lib/mail/parsers/mime_version_parser.rl
mail-2.8.0.rc3 lib/mail/parsers/mime_version_parser.rl
mail-2.8.0.rc2 lib/mail/parsers/mime_version_parser.rl
mail-2.8.0.rc1 lib/mail/parsers/mime_version_parser.rl