<commit_before>module Bouncefetch
  class Application
    module Helper
      def imap_search_headers
        [].tap do |r|
          if idh = cfg("identification_header")
            r << ["HEADER", idh, ""]
          end
          cfg("imap_search.headers").each do |a, b, c|
            r << [a, b, c || ""]
          end
        end
      end

      def handle_throttle
        if @opts[:throttle_detect] && connection.instance_variable_get(:@parser).instance_variable_get(:@str)["THROTTLED"]
          @throttled ||= 1
          warn "The IMAP server (probably gmail) is throttling your account! (sleep #{@throttled * 5} seconds)"
          sleep @throttled * 5
          @throttled += 1
        else
          @throttled = nil
        end
      rescue NoMethodError
      end

      def mid_expunge
        return if @opts[:simulate] || cfg("imap.expunge_rate") == 0
        @mid_expunge ||= 0
        @mid_expunge += 1

        if @mid_expunge > cfg("imap.expunge_rate") && connected?
          log(c("E", :yellow))
          connection.expunge
          logger.raw "\b \b#{c("E", :magenta)}"
          @mid_expunge = nil
        end
      end

      def log_perform_failsafe what, &block
        logger.log_with_print do
          log "#{what} "
          begin
            block.call
            logger.raw c("DONE", :green)
          rescue
            logger.raw c("FAILED (#{$!.message.strip})", :red)
          end
        end
      end

      def inspect_mail mail<commit_msg>Fix helper to return block<commit_after>module Bouncefetch
  class Application
    module Helper
      def imap_search_headers
        [].tap do |r|
          if idh = cfg("identification_header")
            r << ["HEADER", idh, ""]
          end
          cfg("imap_search.headers").each do |a, b, c|
            r << [a, b, c || ""]
          end
        end
      end

      def handle_throttle
        if @opts[:throttle_detect] && connection.instance_variable_get(:@parser).instance_variable_get(:@str)["THROTTLED"]
          @throttled ||= 1
          warn "The IMAP server (probably gmail) is throttling your account! (sleep #{@throttled * 5} seconds)"
          sleep @throttled * 5
          @throttled += 1
        else
          @throttled = nil
        end
      rescue NoMethodError
      end

      def mid_expunge
        return if @opts[:simulate] || cfg("imap.expunge_rate") == 0
        @mid_expunge ||= 0
        @mid_expunge += 1

        if @mid_expunge > cfg("imap.expunge_rate") && connected?
          log(c("E", :yellow))
          connection.expunge
          logger.raw "\b \b#{c("E", :magenta)}"
          @mid_expunge = nil
        end
      end

      def log_perform_failsafe what, &block
        ret = nil
        logger.log_with_print do
          log "#{what} "
          begin
            ret = block.call
            logger.raw c("DONE", :green)
          rescue
            logger.raw c("FAILED (#{$!.message.strip})", :red)
          end
        end
        ret
      end

      def inspect_mail mail
{'fraction_non_alphanumeric': 0.11488940244305051, 'fraction_numerical': 0.00462198745460548, 'mean_word_length': 1.707774798927614, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 5, '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': '4424492', 'n_tokens_mistral': 951, 'n_tokens_neox': 924, 'n_words': 233}