<commit_before>require 'resolv'
require 'stringio'
require 'net/smtp'
module Net
  class SMTP
    def socket
      @socket
    end

    def bind_at(ip)
      @bind_at = ip
    end

    def tcp_socket(address, port)
      in_addr = Socket.pack_sockaddr_in(0, @bind_at) if @bind_at

      out_addr = Socket.pack_sockaddr_in(port, address)
      s = Socket.new(Socket::AF_INET, Socket::SOCK_STREAM, 0)
      s.bind(in_addr) if @bind_at
      s.connect(out_addr)
      s
    end
  end
end


module Rhcf
  module Utils
    module Email
      def self.get_mxs(domain) 
        Resolv::DNS.open do |dns|
          dns.getresources(domain, Resolv::DNS::Resource::IN::MX).collect{|x| x.exchange.to_s}
        end
      end
  
      def self.transmit(from, to, body, bind_interface, ehlo = 'localhost.localdomain')
        domain = to.split('@').last
      
        chat = StringIO.new 
        mx = get_mxs(domain).sample
        smtp = Net::SMTP.new(mx, 25)
        smtp.bind_at bind_interface 
        result = smtp.start(ehlo) do |smtp|
          smtp.socket.debug_output = chat
          smtp.send_message body, from, to
        end
   
        {status: result.status, string: result.string, chat: chat.string}
      end
    end
  end
end<commit_msg>Bind interface is now optional<commit_after>require 'resolv'
require 'stringio'
require 'net/smtp'
module Net
  class SMTP
    def socket
      @socket
    end

    def bind_at(ip)
      @bind_at = ip
    end

    def tcp_socket(address, port)
      in_addr = Socket.pack_sockaddr_in(0, @bind_at) if @bind_at

      out_addr = Socket.pack_sockaddr_in(port, address)
      s = Socket.new(Socket::AF_INET, Socket::SOCK_STREAM, 0)
      s.bind(in_addr) if @bind_at
      s.connect(out_addr)
      s
    end
  end
end


module Rhcf
  module Utils
    module Email
      def self.get_mxs(domain)
        Resolv::DNS.open do |dns|
          dns.getresources(domain, Resolv::DNS::Resource::IN::MX).collect{|x| x.exchange.to_s}
        end
      end

      def self.transmit(from, to, body, bind_interface=nil, ehlo = 'localhost.localdomain')
        domain = to.split('@').last

        chat = StringIO.new
        mx = get_mxs(domain).sample
        smtp = Net::SMTP.new(mx, 25)
        smtp.bind_at bind_interface if bind_interface
        result = smtp.start(ehlo) do |smtp|
          smtp.socket.debug_output = chat
          smtp.send_message body, from, to
        end

        {status: result.status, string: result.string, chat: chat.string}
      end
    end
  end
end
{'fraction_non_alphanumeric': 0.10298210735586481, 'fraction_numerical': 0.0031809145129224653, 'mean_word_length': 2.3591455273698263, 'pattern_counts': {'":': 0, '<': 3, '<?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': '5967390', 'n_tokens_mistral': 905, 'n_tokens_neox': 878, 'n_words': 199}