Sha256: 5784266efabdff2bbf63d44f9fc22866cb7cf1b94d30abc3e4abe56cd5b4c57d

Contents?: true

Size: 1.87 KB

Versions: 14

Compression:

Stored size: 1.87 KB

Contents

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

begin
  original_verbose, $VERBOSE = $VERBOSE, nil

%%{
  # RFC 2557 Content-Location
  # https://tools.ietf.org/html/rfc2557#section-4.1
  machine content_location;
  alphtype int;

  # Quoted String
  action qstr_s { qstr_s = p }
  action qstr_e { content_location.location = chars(data, qstr_s, p-1) }

  # Token String
  action token_string_s { token_string_s = p }
  action token_string_e { content_location.location = chars(data, token_string_s, p-1) }

  # No-op actions
  action comment_e { }
  action comment_s { }
  action phrase_e { }
  action phrase_s { }
  action main_type_e { }
  action main_type_s { }
  action sub_type_e { }
  action sub_type_s { }
  action param_attr_e { }
  action param_attr_s { }
  action param_val_e { }
  action param_val_s { }

  include rfc2045_content_type "rfc2045_content_type.rl";

  location = quoted_string | ((token | 0x3d)+ >token_string_s %token_string_e);
  main := CFWS? location CFWS?;
}%%

module Mail::Parsers
  module ContentLocationParser
    extend Mail::ParserTools

    ContentLocationStruct = Struct.new(:location, :error)

    %%write data noprefix;

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

      content_location = ContentLocationStruct.new(nil)
      return content_location if Mail::Utilities.blank?(data)

      # Parser state
      disp_type_s = param_attr_s = param_attr = qstr_s = qstr = param_val_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::ContentLocationElement, data, p)
      end

      content_location
    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/content_location_parser.rl
blacklight-spotlight-3.6.0.beta8 vendor/bundle/ruby/3.2.0/gems/mail-2.8.1/lib/mail/parsers/content_location_parser.rl
cm-admin-1.5.22 vendor/bundle/ruby/3.3.0/gems/mail-2.8.1/lib/mail/parsers/content_location_parser.rl
cm-admin-1.5.21 vendor/bundle/ruby/3.3.0/gems/mail-2.8.1/lib/mail/parsers/content_location_parser.rl
cm-admin-1.5.20 vendor/bundle/ruby/3.3.0/gems/mail-2.8.1/lib/mail/parsers/content_location_parser.rl
tinymce-rails-7.1.2 vendor/bundle/ruby/3.3.0/gems/mail-2.8.1/lib/mail/parsers/content_location_parser.rl
mail-2.8.1 lib/mail/parsers/content_location_parser.rl
mail-2.8.1.rc2 lib/mail/parsers/content_location_parser.rl
mail-2.8.0.1 lib/mail/parsers/content_location_parser.rl
mail-2.8.0.1.rc1 lib/mail/parsers/content_location_parser.rl
mail-2.8.0 lib/mail/parsers/content_location_parser.rl
mail-2.8.0.rc3 lib/mail/parsers/content_location_parser.rl
mail-2.8.0.rc2 lib/mail/parsers/content_location_parser.rl
mail-2.8.0.rc1 lib/mail/parsers/content_location_parser.rl