<commit_before>require 'net/smtp'

module CMail
  class SendMailError < Exception; end
  
  class Transport
    class Config
      attr_accessor :host, :port
      attr_accessor :auth_type, :auth_user, :auth_pass
      attr_accessor :method, :sendmail_binary

      def initialize
        @method = :smtp # :sendmail
        @host = 'localhost'
        @port = 25
        @auth_type = nil # :plain, :login, :cram_md5
        @auth_user = nil
        @auth_pass = nil
        @sendmail_binary = 'sendmail'
      end
    end
    
    DefaultConfig = Config.new

    def self.mail(message, config = nil)
      new(config).mail(message)
    end
    
    attr_accessor :config
    
    def initialize(config = nil)
      @config = config || DefaultConfig
    end
    
    def mail(message)
      unless Message === message
        raise ArgumentError, "expected CMail::Message, got #{message.class}"
      end
      
      send("mail_#{config.method}", message)
    end
    
    def mail_smtp(message)
      Net::SMTP.start(config.host, config.port, 'localhost.localdomain', 
          config.auth_user, config.auth_pass, config.auth_type) do |smtp|
        smtp.send_message(message.to_s, message.from, message.recipients_list)
      end
    end
    
    def mail_sendmail(message)
      bin, err = config.sendmail_binary, ''
      result = IO.popen("#{bin} -t 2>&1", "w+") do |io|
        io.write(message.to_s)
        io.write(".\n")
        io.close_write
        err = io.read.chomp
      end
      
      raise SendMailError, err if $? != 0
    end
  end

  class Message
    def initialize(opts = {})
      defaults = {<commit_msg>Don't need to write . to the stream<commit_after>require 'net/smtp'

module CMail
  class SendMailError < Exception; end
  
  class Transport
    class Config
      attr_accessor :host, :port
      attr_accessor :auth_type, :auth_user, :auth_pass
      attr_accessor :method, :sendmail_binary

      def initialize
        @method = :smtp # :sendmail
        @host = 'localhost'
        @port = 25
        @auth_type = nil # :plain, :login, :cram_md5
        @auth_user = nil
        @auth_pass = <PASSWORD>
        @sendmail_binary = 'sendmail'
      end
    end
    
    DefaultConfig = Config.new

    def self.mail(message, config = nil)
      new(config).mail(message)
    end
    
    attr_accessor :config
    
    def initialize(config = nil)
      @config = config || DefaultConfig
    end
    
    def mail(message)
      unless Message === message
        raise ArgumentError, "expected CMail::Message, got #{message.class}"
      end
      
      send("mail_#{config.method}", message)
    end
    
    def mail_smtp(message)
      Net::SMTP.start(config.host, config.port, 'localhost.localdomain', 
          config.auth_user, config.auth_pass, config.auth_type) do |smtp|
        smtp.send_message(message.to_s, message.from, message.recipients_list)
      end
    end
    
    def mail_sendmail(message)
      bin, err = config.sendmail_binary, ''
      result = IO.popen("#{bin} -t 2>&1", "w+") do |io|
        io.write(message.to_s)
        io.close_write
        err = io.read.chomp
      end
      
      raise SendMailError, err if $? != 0
    end
  end

  class Message
    def initialize(opts = {})
      defaults = {
{'fraction_non_alphanumeric': 0.10479682248701497, 'fraction_numerical': 0.0036663611365719525, 'mean_word_length': 2.2192723697148478, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 6, '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': '2591618', 'n_tokens_mistral': 1064, 'n_tokens_neox': 1040, 'n_words': 247}