<commit_before>require 'date'
require 'json'
require 'sonar_connector'
require 'rews'

module Sonar
  module Connector
    class EwsPullConnector < Sonar::Connector::Base

      DEFAULT_BATCH_SIZE = 100

      attr_reader :url
      attr_reader :auth
      attr_reader :user
      attr_reader :password
      attr_reader :distinguished_folders
      attr_reader :batch_size
      attr_reader :delete

      def parse(settings)
        ["name", "repeat_delay", "url", "auth", "user", "password", "distinguished_folders", "batch_size", "delete"].each do |param|
          raise Sonar::Connector::InvalidConfig.new("#{self.class}: param '#{param}' is blank") if settings[param].blank?
        end
        
        @url = settings["url"]
        @auth = settings["auth"]
        @user = settings["user"]
        @password = settings["password"]
        @mailbox_email = settings["mailbox_email"]
        @distinguished_folders = settings["distinguished_folders"]
        @batch_size = settings["batch_size"] || DEFAULT_BATCH_SIZE
        @delete = settings["delete"]
      end
      
      def inspect
        "#<#{self.class} @url=#{url}, @auth=#{auth}, @user=#{user}, @password=#{password}, @distinguished_folders=#{distinguished_folders}, @batch_size=#{batch_size}>"
      end

      def distinguished_folder_ids
        return @distinguished_folder_ids if @distinguished_folder_ids
        client ||= Rews::Client.new(url, auth, user, password)

        @distinguished_folder_ids = @distinguished_folders.inject([]) do |ids, (name, mailbox_email)|
          ids << client.distinguished_folder_id(name, mailbox_email)
        end
      end

      def action
        distinguished_folder_ids.each do |fid|<commit_msg>drop requirement for "delete" parameter...<commit_after>require 'date'
require 'json'
require 'sonar_connector'
require 'rews'

module Sonar
  module Connector
    class EwsPullConnector < Sonar::Connector::Base

      DEFAULT_BATCH_SIZE = 100

      attr_reader :url
      attr_reader :auth
      attr_reader :user
      attr_reader :password
      attr_reader :distinguished_folders
      attr_reader :batch_size
      attr_reader :delete

      def parse(settings)
        ["name", "repeat_delay", "url", "auth", "user", "password", "distinguished_folders", "batch_size"].each do |param|
          raise Sonar::Connector::InvalidConfig.new("#{self.class}: param '#{param}' is blank") if settings[param].blank?
        end
        
        @url = settings["url"]
        @auth = settings["auth"]
        @user = settings["user"]
        @password = settings["password"]
        @mailbox_email = settings["mailbox_email"]
        @distinguished_folders = settings["distinguished_folders"]
        @batch_size = settings["batch_size"] || DEFAULT_BATCH_SIZE
        @delete = settings["delete"]
      end
      
      def inspect
        "#<#{self.class} @url=#{url}, @auth=#{auth}, @user=#{user}, @password=#{password}, @distinguished_folders=#{distinguished_folders}, @batch_size=#{batch_size}>"
      end

      def distinguished_folder_ids
        return @distinguished_folder_ids if @distinguished_folder_ids
        client ||= Rews::Client.new(url, auth, user, password)

        @distinguished_folder_ids = @distinguished_folders.inject([]) do |ids, (name, mailbox_email)|
          ids << client.distinguished_folder_id(name, mailbox_email)
        end
      end

      def action
        distinguished_folder_ids.each do |fid|
{'fraction_non_alphanumeric': 0.12235430559582487, 'fraction_numerical': 0.0017396346767178893, 'mean_word_length': 3.3071161048689137, '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': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7239468', 'n_tokens_mistral': 1041, 'n_tokens_neox': 1007, 'n_words': 218}