<commit_before>module Animoto
  module ManyMailers
    def self.included(base)
      base.extend(ClassMethods)      
      base.class_eval do
        @@mail_servers = { }        
        cattr_accessor :mail_servers
        load_settings!
      end
    end
    
    module ClassMethods
      def with_settings(name, options={}, &block)
        self.class_inheritable_accessor :smtp_settings
        self.smtp_settings = mail_servers[name]
        rescue_servers = [options[:retry]].flatten
        begin
          yield self
        rescue => e
          raise e if rescue_servers.empty?
          retry_server = rescue_servers.shift
          with_settings(retry_server, :retry => rescue_servers, &block)          
        end
        self.smtp_settings = mail_servers[:default]
      end
           
      def load_settings!(file_path = "#{RAILS_ROOT}/config/mail_servers.yml")
        YAML.load_file(file_path).each do |key, value|
          mail_servers[key.to_sym] = value.to_options!
          self.smtp_settings = mail_servers[:default]
        end
        rescue
          puts "=> \"#{file_path}\" not found! Using default SMTP settings (if any)."
      end
    end
  end
end

ActionMailer::Base.send :include, Animoto::ManyMailers<commit_msg>fixed a bug in many-mailers. It would give ambiguous error messages if no retry server was specified and the primary server didn't work.<commit_after>module Animoto
  module ManyMailers
    def self.included(base)
      base.extend(ClassMethods)      
      base.class_eval do
        @@mail_servers = { }        
        cattr_accessor :mail_servers
        load_settings!
      end
    end
    
    module ClassMethods
      def with_settings(name, options={}, &block)
        self.class_inheritable_accessor :smtp_settings
        self.smtp_settings = mail_servers[name]
        rescue_servers = [options[:retry]].flatten.compact
        begin
          yield self
        rescue => e
          raise e if rescue_servers.empty?
          retry_server = rescue_servers.shift
          with_settings(retry_server, :retry => rescue_servers, &block)          
        end
        self.smtp_settings = mail_servers[:default]
      end
           
      def load_settings!(file_path = "#{RAILS_ROOT}/config/mail_servers.yml")
        YAML.load_file(file_path).each do |key, value|
          mail_servers[key.to_sym] = value.to_options!
          self.smtp_settings = mail_servers[:default]
        end
        rescue
          puts "=> \"#{file_path}\" not found! Using default SMTP settings (if any)."
      end
    end
  end
end

ActionMailer::Base.send :include, Animoto::ManyMailers
{'fraction_non_alphanumeric': 0.08462998102466793, 'fraction_numerical': 0.0, 'mean_word_length': 2.2908863920099876, 'pattern_counts': {'":': 0, '<': 3, '<?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': '5244248', 'n_tokens_mistral': 775, 'n_tokens_neox': 793, 'n_words': 173}