<commit_before>module Gitlab
  module ReplyByEmail
    class << self
      def enabled?
        config.enabled && address_formatted_correctly?
      end

      def address_formatted_correctly?
        config.address &&
          config.address.include?("%{reply_key}")
      end

      def reply_key
        return nil unless enabled?

        SecureRandom.hex(16)
      end

      def reply_address(reply_key)
        config.address.gsub('%{reply_key}', reply_key)
      end

      def reply_key_from_address(address)
        return unless address_regex

        match = address.match(address_regex)
        return unless match

        match[1]
      end

      private

      def config
        Gitlab.config.reply_by_email<commit_msg>Memoize address_regex locally.<commit_after>module Gitlab
  module ReplyByEmail
    class << self
      def enabled?
        config.enabled && address_formatted_correctly?
      end

      def address_formatted_correctly?
        config.address &&
          config.address.include?("%{reply_key}")
      end

      def reply_key
        return nil unless enabled?

        SecureRandom.hex(16)
      end

      def reply_address(reply_key)
        config.address.gsub('%{reply_key}', reply_key)
      end

      def reply_key_from_address(address)
        regex = address_regex
        return unless regex

        match = address.match(regex)
        return unless match

        match[1]
      end

      private

      def config
        Gitlab.config.reply_by_email
{'fraction_non_alphanumeric': 0.0676841406768414, 'fraction_numerical': 0.003981420039814201, 'mean_word_length': 2.109278350515464, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 3, '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': '3193541', 'n_tokens_mistral': 436, 'n_tokens_neox': 417, 'n_words': 93}