<commit_before>#Copyright (c) 2008-12 <NAME> of 9thBit LLC
#Released under the MIT license

module SanitizeEmail
  require 'sanitize_email/version'
  require 'sanitize_email/deprecation'
  require 'sanitize_email/config'
  require 'sanitize_email/bleach'

  # Allow non-rails implementations to use this gem
  # TODO: Prepare this for Rails 4
  if defined?(Rails) && ::Rails::VERSION::MAJOR >= 3
    if ::Rails::VERSION::MINOR >= 1
      require 'sanitize_email/engine'
    elsif ::Rails::VERSION::MINOR == 0
      require 'sanitize_email/railtie'
    end
  elsif defined?(Rails)
    raise "Please use the 0.X.X versions of sanitize_email for Rails 2.X and below."
  elsif defined?(Mailer) && Mailer.respond_to?(:register_interceptor)
    Mailer.register_interceptor(SanitizeEmail::Bleach.new)
  end

  def self.[](key)
    return nil unless key.respond_to?(:to_sym)
    SanitizeEmail::Config.config[key.to_sym]
  end

  def self.method_missing(name, *args)
    SanitizeEmail[name]
  end

  # NOTE: Deprecated method
  # We have to actually define because we can't deprecate methods that are hooked up via method_missing
  def self.sanitized_recipients
    SanitizeEmail[:sanitized_recipients]
  end

  # NOTE: Deprecated method
  # We have to actually define because we can't deprecate methods that are hooked up via method_missing
  def self.local_environments
    SanitizeEmail[:local_environments]
  end

  mattr_reader :force_sanitize
  mattr_writer :force_sanitize
  self.force_sanitize = nil

  # Regardless of the Config settings of SanitizeEmail you can do a local override to send sanitary email in any environment.
  # You have access to all the same configuration options in the parameter hash as you can set in the actual
  # SanitizeEmail.configure block.
  #
  # SanitizeEmail.sanitary({:sanitized_to => '<EMAIL>'}) do # these config options are merged with the globals
  #   Mail.deliver do
  #     from      '<EMAIL>'
  #     to        '<EMAIL>' # Will actually be sent to the override addresses, in this case: <EMAIL>
  #     reply_to  '<EMAIL>'
  #     subject   'subject'
  #   end
  # end
  #
  def self.sanitary(config_options = {}, &block)
    janitor({:forcing => true}) do
      original = SanitizeEmail::Config.config.dup
      SanitizeEmail::Config.config.merge!(config_options)
      yield
      SanitizeEmail::Config.config = original
    end
  end

  # Regardless of the Config settings of SanitizeEmail you can do a local override to force unsanitary email in any environment.
  #
  # SanitizeEmail.unsanitary do
  #   Mail.deliver do
  #     from      '<EMAIL>'
  #     to        '<EMAIL>'
  #     reply_to  '<EMAIL>'
  #     subject   'subject'
  #   end
  # end
  #
  def self.unsanitary &block
    janitor({:forcing => false}) do
      yield
    end
  end

  def self.janitor(options, &block)
    return false unless block_given?
    original = SanitizeEmail.force_sanitize
    SanitizeEmail.force_sanitize = options[:forcing]
    yield
    SanitizeEmail.force_sanitize = original
  end

  # Setup Deprecations!
  class << self
    extend SanitizeEmail::Deprecation
    deprecated_alias :sanitized_recipients, :sanitized_to
    deprecated :local_environments, :activation_proc
  end

end
<commit_msg>Improve handling of mal-formed calls to (un)sanitary<commit_after>#Copyright (c) 2008-12 <NAME> of 9thBit LLC
#Released under the MIT license

module SanitizeEmail
  require 'sanitize_email/version'
  require 'sanitize_email/deprecation'
  require 'sanitize_email/config'
  require 'sanitize_email/bleach'

  # Allow non-rails implementations to use this gem
  # TODO: Prepare this for Rails 4
  if defined?(Rails) && ::Rails::VERSION::MAJOR >= 3
    if ::Rails::VERSION::MINOR >= 1
      require 'sanitize_email/engine'
    elsif ::Rails::VERSION::MINOR == 0
      require 'sanitize_email/railtie'
    end
  elsif defined?(Rails)
    raise "Please use the 0.X.X versions of sanitize_email for Rails 2.X and below."
  elsif defined?(Mailer) && Mailer.respond_to?(:register_interceptor)
    Mailer.register_interceptor(SanitizeEmail::Bleach.new)
  end

  def self.[](key)
    return nil unless key.respond_to?(:to_sym)
    SanitizeEmail::Config.config[key.to_sym]
  end

  def self.method_missing(name, *args)
    SanitizeEmail[name]
  end

  # NOTE: Deprecated method
  # We have to actually define because we can't deprecate methods that are hooked up via method_missing
  def self.sanitized_recipients
    SanitizeEmail[:sanitized_recipients]
  end

  # NOTE: Deprecated method
  # We have to actually define because we can't deprecate methods that are hooked up via method_missing
  def self.local_environments
    SanitizeEmail[:local_environments]
  end

  mattr_reader :force_sanitize
  mattr_writer :force_sanitize
  self.force_sanitize = nil

  # Regardless of the Config settings of SanitizeEmail you can do a local override to send sanitary email in any environment.
  # You have access to all the same configuration options in the parameter hash as you can set in the actual
  # SanitizeEmail.configure block.
  #
  # SanitizeEmail.sanitary({:sanitized_to => '<EMAIL>'}) do # these config options are merged with the globals
  #   Mail.deliver do
  #     from      '<EMAIL>'
  #     to        '<EMAIL>' # Will actually be sent to the override addresses, in this case: <EMAIL>
  #     reply_to  '<EMAIL>'
  #     subject   'subject'
  #   end
  # end
  #
  def self.sanitary(config_options = {}, &block)
    raise "SanitizeEmail.sanitary must be called with a block" unless block_given?
    janitor({:forcing => true}) do
      original = SanitizeEmail::Config.config.dup
      SanitizeEmail::Config.config.merge!(config_options)
      yield
      SanitizeEmail::Config.config = original
    end
  end

  # Regardless of the Config settings of SanitizeEmail you can do a local override to force unsanitary email in any environment.
  #
  # SanitizeEmail.unsanitary do
  #   Mail.deliver do
  #     from      '<EMAIL>'
  #     to        '<EMAIL>'
  #     reply_to  '<EMAIL>'
  #     subject   'subject'
  #   end
  # end
  #
  def self.unsanitary &block
    raise "SanitizeEmail.unsanitary must be called with a block" unless block_given?
    janitor({:forcing => false}) do
      yield
    end
  end

  def self.janitor(options, &block)
    original = SanitizeEmail.force_sanitize
    SanitizeEmail.force_sanitize = options[:forcing]
    yield
    SanitizeEmail.force_sanitize = original
  end

  # Setup Deprecations!
  class << self
    extend SanitizeEmail::Deprecation
    deprecated_alias :sanitized_recipients, :sanitized_to
    deprecated :local_environments, :activation_proc
  end

end

{'fraction_non_alphanumeric': 0.08373493975903615, 'fraction_numerical': 0.00391566265060241, 'mean_word_length': 3.530013642564802, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 31, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6052893', 'n_tokens_mistral': 2122, 'n_tokens_neox': 2117, 'n_words': 618}