<commit_before>#coding: utf-8
require "log4r/outputter/outputter"
require "mail"

module Log4r
  class MailOutputter < Log4r::Outputter
    VERSION = "0.0.2"
    attr_accessor :host, :port, :from, :to, :subject, :body, :encoding
    def initialize(_name, hash={})
      super(_name, hash)
      @host = hash[:host] || hash["host"] || "localhost"
      @port = hash[:port] || hash["port"] || 25
      @from = hash[:from] || hash["from"] || ""
      @to = hash[:to] || hash["to"] || ""
      @subject = hash[:subject] || hash["subject"] || ""
      @body = hash[:body] || hash["body"] || ""
      @encoding = hash[:encoding] || hash["encoding"] || "UTF-8"
    end
    
    def write(data)
      send_mail(data.is_a?(Hash) ? data : {body: data})
    end
    
    def send_mail(params)
      mail = make_mail(params)
      add_files(mail, params)
      mail.delivery_method :smtp, {
          :enable_starttls_auto => false,
          :address => params[:host] || params["host"] || @host,
          :port => params[:port] || params["port"] || @port.to_i,
        }
      mail.deliver
    end
    
    def make_mail(params)
      encoding = params[:encoding] || params["encoding"] || @encoding
      from = params[:from] || params["from"] || @from
      to = params[:to] || params["to"] || @to
      subject = apply_encoding(encoding, params[:subject] || params["subject"] || @subject)
      body = apply_encoding(encoding, params[:body] || params["body"] || @body)
      
      mail = ::Mail.new do
        from from
        to to
        subject subject
        body body
      end
      mail.charset = encoding
      mail
    end
    
    def add_files(mail, params)
      files = params[:files] || params["files"]
      return if !files
      files.each do |file|
        mail.add_file(file)
      end
    end
    
    def apply_encoding(encoding, content)
      if encoding == "ISO-2022-JP"
        NKF.nkf("-j", content).force_encoding("binary")
      else
        content
      end
    end
  end
end<commit_msg>add reqire nkf<commit_after>#coding: utf-8
require "log4r/outputter/outputter"
require "mail"
require "nkf"

module Log4r
  class MailOutputter < Log4r::Outputter
    VERSION = "0.0.3"
    attr_accessor :host, :port, :from, :to, :subject, :body, :encoding
    def initialize(_name, hash={})
      super(_name, hash)
      @host = hash[:host] || hash["host"] || "localhost"
      @port = hash[:port] || hash["port"] || 25
      @from = hash[:from] || hash["from"] || ""
      @to = hash[:to] || hash["to"] || ""
      @subject = hash[:subject] || hash["subject"] || ""
      @body = hash[:body] || hash["body"] || ""
      @encoding = hash[:encoding] || hash["encoding"] || "UTF-8"
    end
    
    def write(data)
      send_mail(data.is_a?(Hash) ? data : {body: data})
    end
    
    def send_mail(params)
      mail = make_mail(params)
      add_files(mail, params)
      mail.delivery_method :smtp, {
          :enable_starttls_auto => false,
          :address => params[:host] || params["host"] || @host,
          :port => params[:port] || params["port"] || @port.to_i,
        }
      mail.deliver
    end
    
    def make_mail(params)
      encoding = params[:encoding] || params["encoding"] || @encoding
      from = params[:from] || params["from"] || @from
      to = params[:to] || params["to"] || @to
      subject = apply_encoding(encoding, params[:subject] || params["subject"] || @subject)
      body = apply_encoding(encoding, params[:body] || params["body"] || @body)
      
      mail = ::Mail.new do
        from from
        to to
        subject subject
        body body
      end
      mail.charset = encoding
      mail
    end
    
    def add_files(mail, params)
      files = params[:files] || params["files"]
      return if !files
      files.each do |file|
        mail.add_file(file)
      end
    end
    
    def apply_encoding(encoding, content)
      if encoding == "ISO-2022-JP"
        ::NKF.nkf("-j", content).force_encoding("binary")
      else
        content
      end
    end
  end
end
{'fraction_non_alphanumeric': 0.16423447934701954, 'fraction_numerical': 0.006925550333910463, 'mean_word_length': 2.4417021276595743, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 9, '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': '4198437', 'n_tokens_mistral': 1306, 'n_tokens_neox': 1286, 'n_words': 297}